diff --git a/config/config.go b/config/config.go index 439f9d227..cd11c027d 100644 --- a/config/config.go +++ b/config/config.go @@ -160,10 +160,11 @@ type Variable struct { // output marked Sensitive will be output in a masked form following // application, but will still be available in state. type Output struct { - Name string - Sensitive bool - DependsOn []string - RawConfig *RawConfig + Name string + DependsOn []string + Description string + Sensitive bool + RawConfig *RawConfig } // VariableType is the type of value a variable is holding, and returned @@ -663,6 +664,17 @@ func (c *Config) Validate() error { o.Name)) continue } + if k == "description" { + if desc, ok := o.RawConfig.config[k].(string); ok { + o.Description = desc + continue + } + + errs = append(errs, fmt.Errorf( + "%s: value for 'description' must be string", + o.Name)) + continue + } invalidKeys = append(invalidKeys, k) } if len(invalidKeys) > 0 { diff --git a/config/config_test.go b/config/config_test.go index e89172ff8..f6303e8e7 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -394,6 +394,19 @@ func TestConfigValidate_outputBadField(t *testing.T) { } } +func TestConfigValidate_outputDescription(t *testing.T) { + c := testConfig(t, "validate-output-description") + if err := c.Validate(); err != nil { + t.Fatalf("err: %s", err) + } + if len(c.Outputs) != 1 { + t.Fatalf("got %d outputs; want 1", len(c.Outputs)) + } + if got, want := "Number 5", c.Outputs[0].Description; got != want { + t.Fatalf("got description %q; want %q", got, want) + } +} + func TestConfigValidate_outputDuplicate(t *testing.T) { c := testConfig(t, "validate-output-dup") if err := c.Validate(); err == nil { diff --git a/config/test-fixtures/validate-output-description/main.tf b/config/test-fixtures/validate-output-description/main.tf new file mode 100644 index 000000000..3f1db8f27 --- /dev/null +++ b/config/test-fixtures/validate-output-description/main.tf @@ -0,0 +1,4 @@ +output "foo" { + value = "5" + description = "Number 5" +}