Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: validation error when output is missing value field #4762

Merged
merged 1 commit into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
variable "memory" {}

output "result" {}
output "result" { value = "foo" }
3 changes: 3 additions & 0 deletions config/test-fixtures/validate-output-missing-equals/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "whoops" {
value "wheresmyequals"
}