command/validate: read terraform.tfvars file for variable values

This is now consistent with the handling of this file for other commands.
This commit is contained in:
Sunny 2017-08-29 00:31:11 +05:30 committed by Martin Atkins
parent aefcc5403e
commit 3a1582c1b9
4 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,4 @@
variable "var_without_default" {
type = "string"
}

View File

@ -0,0 +1 @@
var_without_default = "foo"

View File

@ -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
}

View File

@ -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())