command: validate configuration, test for it

This commit is contained in:
Mitchell Hashimoto 2014-07-02 21:16:36 -07:00
parent 78e056770c
commit d23733263f
3 changed files with 24 additions and 0 deletions

View File

@ -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) { func TestApply_plan(t *testing.T) {
planPath := testPlanFile(t, new(terraform.Plan)) planPath := testPlanFile(t, new(terraform.Plan))
statePath := testTempFile(t) statePath := testTempFile(t)

View File

@ -55,6 +55,9 @@ func PlanArg(
if err != nil { if err != nil {
return nil, fmt.Errorf("Error loading config: %s", err) 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{ plan, err := tf.Plan(&terraform.PlanOpts{
Config: config, Config: config,

View File

@ -0,0 +1,3 @@
resource "test_instance" "foo" {
ami = "${var.nope}"
}