diff --git a/command/apply_test.go b/command/apply_test.go index 820b510b4..163ac9121 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -48,6 +48,24 @@ func TestApply(t *testing.T) { } } +func TestApply_configInvalid(t *testing.T) { + p := testProvider() + ui := new(cli.MockUi) + c := &ApplyCommand{ + TFConfig: testTFConfig(p), + Ui: ui, + } + + args := []string{ + "-init", + testTempFile(t), + testFixturePath("apply-config-invalid"), + } + if code := c.Run(args); code != 1 { + t.Fatalf("bad: \n%s", ui.OutputWriter.String()) + } +} + func TestApply_plan(t *testing.T) { planPath := testPlanFile(t, new(terraform.Plan)) statePath := testTempFile(t) diff --git a/command/command.go b/command/command.go index d42584d23..0805202b2 100644 --- a/command/command.go +++ b/command/command.go @@ -55,6 +55,9 @@ func PlanArg( if err != nil { return nil, fmt.Errorf("Error loading config: %s", err) } + if err := config.Validate(); err != nil { + return nil, fmt.Errorf("Error validating config: %s", err) + } plan, err := tf.Plan(&terraform.PlanOpts{ Config: config, diff --git a/command/test-fixtures/apply-config-invalid/main.tf b/command/test-fixtures/apply-config-invalid/main.tf new file mode 100644 index 000000000..ea4d9df6e --- /dev/null +++ b/command/test-fixtures/apply-config-invalid/main.tf @@ -0,0 +1,3 @@ +resource "test_instance" "foo" { + ami = "${var.nope}" +}