diff --git a/terraform/context_test.go b/terraform/context_test.go index c591390d1..3b1310b47 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -132,6 +132,54 @@ func TestContextValidate_requiredVar(t *testing.T) { } } +func TestContextValidate_provisionerConfig_bad(t *testing.T) { + config := testConfig(t, "validate-bad-prov-conf") + p := testProvider("aws") + pr := testProvisioner() + c := testContext(t, &ContextOpts{ + Config: config, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + Provisioners: map[string]ResourceProvisionerFactory{ + "shell": testProvisionerFuncFixed(pr), + }, + }) + + pr.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_provisionerConfig_good(t *testing.T) { + config := testConfig(t, "validate-bad-prov-conf") + p := testProvider("aws") + pr := testProvisioner() + c := testContext(t, &ContextOpts{ + Config: config, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + Provisioners: map[string]ResourceProvisionerFactory{ + "shell": testProvisionerFuncFixed(pr), + }, + }) + + w, e := c.Validate() + if len(w) > 0 { + t.Fatalf("bad: %#v", w) + } + if len(e) > 0 { + t.Fatalf("bad: %#v", e) + } +} + func TestContextApply(t *testing.T) { c := testConfig(t, "apply-good") p := testProvider("aws") @@ -1406,3 +1454,8 @@ func testProvider(prefix string) *MockResourceProvider { return p } + +func testProvisioner() *MockResourceProvisioner { + p := new(MockResourceProvisioner) + return p +} diff --git a/terraform/test-fixtures/validate-bad-prov-conf/main.tf b/terraform/test-fixtures/validate-bad-prov-conf/main.tf new file mode 100644 index 000000000..bb239fad7 --- /dev/null +++ b/terraform/test-fixtures/validate-bad-prov-conf/main.tf @@ -0,0 +1,7 @@ +provider "aws" { + foo = "bar" +} + +resource "aws_instance" "test" { + provisioner "shell" {} +}