config: validate output only has "value" field

This commit is contained in:
Mitchell Hashimoto 2014-07-04 10:57:09 -07:00
parent a4f38a3933
commit ed1860de61
3 changed files with 27 additions and 0 deletions

View File

@ -146,6 +146,19 @@ func (c *Config) Validate() error {
} }
// Check that all outputs are valid // 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 { if len(errs) > 0 {
return &multierror.Error{Errors: errs} return &multierror.Error{Errors: errs}

View File

@ -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) { func TestConfigValidate_unknownResourceVar(t *testing.T) {
c := testConfig(t, "validate-unknown-resource-var") c := testConfig(t, "validate-unknown-resource-var")
if err := c.Validate(); err == nil { if err := c.Validate(); err == nil {

View File

@ -0,0 +1,7 @@
resource "aws_instance" "web" {
}
output "ip" {
value = "foo"
another = "nope"
}