From ed1860de612c7fabb59dd4c9ec45920d4676c0f4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 4 Jul 2014 10:57:09 -0700 Subject: [PATCH] config: validate output only has "value" field --- config/config.go | 13 +++++++++++++ config/config_test.go | 7 +++++++ .../test-fixtures/validate-output-bad-field/main.tf | 7 +++++++ 3 files changed, 27 insertions(+) create mode 100644 config/test-fixtures/validate-output-bad-field/main.tf diff --git a/config/config.go b/config/config.go index dba3c0012..849508cef 100644 --- a/config/config.go +++ b/config/config.go @@ -146,6 +146,19 @@ func (c *Config) Validate() error { } // Check that all outputs are valid + for _, o := range c.Outputs { + invalid := false + for k, _ := range o.RawConfig.Raw { + if k != "value" { + invalid = true + break + } + } + if invalid { + errs = append(errs, fmt.Errorf( + "%s: output should only have 'value' field", o.Name)) + } + } if len(errs) > 0 { return &multierror.Error{Errors: errs} diff --git a/config/config_test.go b/config/config_test.go index f784d0df5..2afc89236 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -15,6 +15,13 @@ func TestConfigValidate(t *testing.T) { } } +func TestConfigValidate_outputBadField(t *testing.T) { + c := testConfig(t, "validate-output-bad-field") + if err := c.Validate(); err == nil { + t.Fatal("should not be valid") + } +} + func TestConfigValidate_unknownResourceVar(t *testing.T) { c := testConfig(t, "validate-unknown-resource-var") if err := c.Validate(); err == nil { diff --git a/config/test-fixtures/validate-output-bad-field/main.tf b/config/test-fixtures/validate-output-bad-field/main.tf new file mode 100644 index 000000000..dae3781a4 --- /dev/null +++ b/config/test-fixtures/validate-output-bad-field/main.tf @@ -0,0 +1,7 @@ +resource "aws_instance" "web" { +} + +output "ip" { + value = "foo" + another = "nope" +}