Skip to content

Commit

Permalink
Merge pull request hashicorp#15940 from hashicorp/b-output-desc
Browse files Browse the repository at this point in the history
config: parse description field for outputs
  • Loading branch information
mitchellh authored Aug 28, 2017
2 parents 648acf7 + adcf41f commit b6047dc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions config/config_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ func outputsStr(os []*Output) string {
result += fmt.Sprintf(" %s: %s\n", kind, str)
}
}

if o.Description != "" {
result += fmt.Sprintf(" description\n %s\n", o.Description)
}
}

return strings.TrimSpace(result)
Expand Down
20 changes: 17 additions & 3 deletions config/loader_hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ func loadOutputsHcl(list *ast.ObjectList) ([]*Output, error) {

// Delete special keys
delete(config, "depends_on")
delete(config, "description")

rawConfig, err := NewRawConfig(config)
if err != nil {
Expand All @@ -520,10 +521,23 @@ func loadOutputsHcl(list *ast.ObjectList) ([]*Output, error) {
}
}

// If we have a description field, then filter that
var description string
if o := listVal.Filter("description"); len(o.Items) > 0 {
err := hcl.DecodeObject(&description, o.Items[0].Val)
if err != nil {
return nil, fmt.Errorf(
"Error reading description for output %q: %s",
n,
err)
}
}

result = append(result, &Output{
Name: n,
RawConfig: rawConfig,
DependsOn: dependsOn,
Name: n,
RawConfig: rawConfig,
DependsOn: dependsOn,
Description: description,
})
}

Expand Down
5 changes: 5 additions & 0 deletions config/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,11 @@ aws_instance.test (x1)
`

const basicOutputsStr = `
web_id
vars
resource: aws_instance.web.id
description
The ID
web_ip
vars
resource: aws_instance.web.private_ip
Expand Down
5 changes: 5 additions & 0 deletions config/test-fixtures/basic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ output "web_ip" {
value = "${aws_instance.web.private_ip}"
}

output "web_id" {
description = "The ID"
value = "${aws_instance.web.id}"
}

atlas {
name = "mitchellh/foo"
}
4 changes: 4 additions & 0 deletions config/test-fixtures/basic.tf.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
},

"output": {
"web_id": {
"description": "The ID",
"value": "${aws_instance.web.id}"
},
"web_ip": {
"value": "${aws_instance.web.private_ip}"
}
Expand Down

0 comments on commit b6047dc

Please sign in to comment.