From d23733263f3c7e6be59a86651db35ccf084ab8b3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 2 Jul 2014 21:16:36 -0700 Subject: [PATCH] command: validate configuration, test for it --- command/apply_test.go | 18 ++++++++++++++++++ command/command.go | 3 +++ .../test-fixtures/apply-config-invalid/main.tf | 3 +++ 3 files changed, 24 insertions(+) create mode 100644 command/test-fixtures/apply-config-invalid/main.tf 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}" +}