From a53faa2fff659e4e51f0081e9dfcce8a57e66265 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 9 Sep 2014 17:38:30 -0700 Subject: [PATCH] terraform: validate providers even without config block [GH-284] --- CHANGELOG.md | 2 ++ terraform/context.go | 7 ++++--- terraform/context_test.go | 21 +++++++++++++++++++ .../validate-bad-pc-empty/main.tf | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 terraform/test-fixtures/validate-bad-pc-empty/main.tf diff --git a/CHANGELOG.md b/CHANGELOG.md index cf50195a1..7018a13d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 0.2.3 (unreleased) +BUG FIXES: + * core: Providers are validated even without a `provider` block. [GH-284] ## 0.2.2 (September 9, 2014) diff --git a/terraform/context.go b/terraform/context.go index 9f462a8dc..61d6ad509 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -933,11 +933,12 @@ func (c *Context) validateWalkFn(rws *[]string, res *[]error) depgraph.WalkFunc } case *GraphNodeResourceProvider: - if rn.Config == nil { - return nil + var raw *config.RawConfig + if rn.Config != nil { + raw = rn.Config.RawConfig } - rc := NewResourceConfig(rn.Config.RawConfig) + rc := NewResourceConfig(raw) for k, p := range rn.Providers { log.Printf("[INFO] Validating provider: %s", k) diff --git a/terraform/context_test.go b/terraform/context_test.go index 1b83e892f..8e8f54bfd 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -121,6 +121,27 @@ func TestContextValidate_providerConfig_bad(t *testing.T) { } } +func TestContextValidate_providerConfig_badEmpty(t *testing.T) { + config := testConfig(t, "validate-bad-pc-empty") + p := testProvider("aws") + c := testContext(t, &ContextOpts{ + Config: config, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + }) + + p.ValidateReturnErrors = []error{fmt.Errorf("bad")} + + w, e := c.Validate() + if len(w) > 0 { + t.Fatalf("bad: %#v", w) + } + if len(e) == 0 { + t.Fatalf("bad: %#v", e) + } +} + func TestContextValidate_providerConfig_good(t *testing.T) { config := testConfig(t, "validate-bad-pc") p := testProvider("aws") diff --git a/terraform/test-fixtures/validate-bad-pc-empty/main.tf b/terraform/test-fixtures/validate-bad-pc-empty/main.tf new file mode 100644 index 000000000..1ad9ade89 --- /dev/null +++ b/terraform/test-fixtures/validate-bad-pc-empty/main.tf @@ -0,0 +1 @@ +resource "aws_instance" "test" {}