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:
parent
aefcc5403e
commit
3a1582c1b9
|
@ -0,0 +1,4 @@
|
|||
variable "var_without_default" {
|
||||
type = "string"
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
var_without_default = "foo"
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue