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:
commit
944e6eec02
|
@ -500,16 +500,23 @@ 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
|
||||
var invalidKeys []string
|
||||
valueKeyFound := false
|
||||
for k := range o.RawConfig.Raw {
|
||||
if k == "value" {
|
||||
valueKeyFound = true
|
||||
} else {
|
||||
invalidKeys = append(invalidKeys, k)
|
||||
}
|
||||
}
|
||||
if invalid {
|
||||
if len(invalidKeys) > 0 {
|
||||
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 {
|
||||
|
|
|
@ -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) {
|
||||
c := testConfig(t, "validate-path-var")
|
||||
if err := c.Validate(); err != nil {
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
variable "memory" {}
|
||||
|
||||
output "result" {}
|
||||
output "result" { value = "foo" }
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
output "whoops" {
|
||||
value "wheresmyequals"
|
||||
}
|
Loading…
Reference in New Issue