Skip to content

Commit

Permalink
command/validate: read terraform.tfvars file for variable values
Browse files Browse the repository at this point in the history
This is now consistent with the handling of this file for other commands.
  • Loading branch information
darkowlzz authored and apparentlymart committed Aug 28, 2017
1 parent aefcc54 commit 3a1582c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions command/test-fixtures/validate-valid/with-tfvars-file/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "var_without_default" {
type = "string"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var_without_default = "foo"
2 changes: 1 addition & 1 deletion command/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 24 additions & 0 deletions command/validate_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package command

import (
"os"
"strings"
"testing"

"github.com/hashicorp/terraform/helper/copy"
"github.com/mitchellh/cli"
)

Expand All @@ -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())
Expand Down

0 comments on commit 3a1582c

Please sign in to comment.