diff --git a/command/test-fixtures/validate-valid/with-tfvars-file/main.tf b/command/test-fixtures/validate-valid/with-tfvars-file/main.tf new file mode 100644 index 000000000..86a19b8fb --- /dev/null +++ b/command/test-fixtures/validate-valid/with-tfvars-file/main.tf @@ -0,0 +1,4 @@ +variable "var_without_default" { + type = "string" +} + diff --git a/command/test-fixtures/validate-valid/with-tfvars-file/terraform.tfvars b/command/test-fixtures/validate-valid/with-tfvars-file/terraform.tfvars new file mode 100644 index 000000000..5b6bd874a --- /dev/null +++ b/command/test-fixtures/validate-valid/with-tfvars-file/terraform.tfvars @@ -0,0 +1 @@ +var_without_default = "foo" diff --git a/command/validate.go b/command/validate.go index 04ae2dddb..d5ec580fe 100644 --- a/command/validate.go +++ b/command/validate.go @@ -17,7 +17,7 @@ type ValidateCommand struct { const defaultPath = "." func (c *ValidateCommand) Run(args []string) int { - args, err := c.Meta.process(args, false) + args, err := c.Meta.process(args, true) if err != nil { return 1 } diff --git a/command/validate_test.go b/command/validate_test.go index 77bdfed97..a52b956ff 100644 --- a/command/validate_test.go +++ b/command/validate_test.go @@ -1,9 +1,11 @@ package command import ( + "os" "strings" "testing" + "github.com/hashicorp/terraform/helper/copy" "github.com/mitchellh/cli" ) @@ -28,6 +30,28 @@ func TestValidateCommand(t *testing.T) { } } +func TestValidateCommandWithTfvarsFile(t *testing.T) { + // Create a temporary working directory that is empty because this test + // requires scanning the current working directory by validate command. + td := tempDir(t) + copy.CopyDir(testFixturePath("validate-valid/with-tfvars-file"), td) + defer os.RemoveAll(td) + defer testChdir(t, td)() + + ui := new(cli.MockUi) + c := &ValidateCommand{ + Meta: Meta{ + testingOverrides: metaOverridesForProvider(testProvider()), + Ui: ui, + }, + } + + args := []string{} + if code := c.Run(args); code != 0 { + t.Fatalf("bad %d\n\n%s", code, ui.ErrorWriter.String()) + } +} + func TestValidateFailingCommand(t *testing.T) { if ui, code := setupTest("validate-invalid"); code != 1 { t.Fatalf("Should have failed: %d\n\n%s", code, ui.ErrorWriter.String())