Merge pull request #4762 from hashicorp/phinze/validate-output-missing-value

config: validation error when output is missing value field
This commit is contained in:
Paul Hinze 2016-01-20 17:11:38 -06:00
commit 944e6eec02
4 changed files with 25 additions and 8 deletions

View File

@ -500,16 +500,23 @@ func (c *Config) Validate() error {
// Check that all outputs are valid // Check that all outputs are valid
for _, o := range c.Outputs { for _, o := range c.Outputs {
invalid := false var invalidKeys []string
for k, _ := range o.RawConfig.Raw { valueKeyFound := false
if k != "value" { for k := range o.RawConfig.Raw {
invalid = true if k == "value" {
break valueKeyFound = true
} else {
invalidKeys = append(invalidKeys, k)
} }
} }
if invalid { if len(invalidKeys) > 0 {
errs = append(errs, fmt.Errorf( errs = append(errs, fmt.Errorf(
"%s: output should only have 'value' field", o.Name)) "%s: output has invalid keys: %s",
o.Name, strings.Join(invalidKeys, ", ")))
}
if !valueKeyFound {
errs = append(errs, fmt.Errorf(
"%s: output is missing required 'value' key", o.Name))
} }
for _, v := range o.RawConfig.Variables { for _, v := range o.RawConfig.Variables {

View File

@ -196,6 +196,13 @@ func TestConfigValidate_outputBadField(t *testing.T) {
} }
} }
func TestConfigValidate_outputMissingEquals(t *testing.T) {
c := testConfig(t, "validate-output-missing-equals")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_pathVar(t *testing.T) { func TestConfigValidate_pathVar(t *testing.T) {
c := testConfig(t, "validate-path-var") c := testConfig(t, "validate-path-var")
if err := c.Validate(); err != nil { if err := c.Validate(); err != nil {

View File

@ -1,3 +1,3 @@
variable "memory" {} variable "memory" {}
output "result" {} output "result" { value = "foo" }

View File

@ -0,0 +1,3 @@
output "whoops" {
value "wheresmyequals"
}