Skip to content

Commit b6047dc

Browse files
authored
Merge pull request hashicorp#15940 from hashicorp/b-output-desc
config: parse description field for outputs
2 parents 648acf7 + adcf41f commit b6047dc

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎config/config_string.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ func outputsStr(os []*Output) string {
143143
result += fmt.Sprintf(" %s: %s\n", kind, str)
144144
}
145145
}
146+
147+
if o.Description != "" {
148+
result += fmt.Sprintf(" description\n %s\n", o.Description)
149+
}
146150
}
147151

148152
return strings.TrimSpace(result)

‎config/loader_hcl.go‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ func loadOutputsHcl(list *ast.ObjectList) ([]*Output, error) {
499499

500500
// Delete special keys
501501
delete(config, "depends_on")
502+
delete(config, "description")
502503

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

524+
// If we have a description field, then filter that
525+
var description string
526+
if o := listVal.Filter("description"); len(o.Items) > 0 {
527+
err := hcl.DecodeObject(&description, o.Items[0].Val)
528+
if err != nil {
529+
return nil, fmt.Errorf(
530+
"Error reading description for output %q: %s",
531+
n,
532+
err)
533+
}
534+
}
535+
523536
result = append(result, &Output{
524-
Name: n,
525-
RawConfig: rawConfig,
526-
DependsOn: dependsOn,
537+
Name: n,
538+
RawConfig: rawConfig,
539+
DependsOn: dependsOn,
540+
Description: description,
527541
})
528542
}
529543

‎config/loader_test.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,11 @@ aws_instance.test (x1)
10581058
`
10591059

10601060
const basicOutputsStr = `
1061+
web_id
1062+
vars
1063+
resource: aws_instance.web.id
1064+
description
1065+
The ID
10611066
web_ip
10621067
vars
10631068
resource: aws_instance.web.private_ip

‎config/test-fixtures/basic.tf‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ output "web_ip" {
8585
value = "${aws_instance.web.private_ip}"
8686
}
8787

88+
output "web_id" {
89+
description = "The ID"
90+
value = "${aws_instance.web.id}"
91+
}
92+
8893
atlas {
8994
name = "mitchellh/foo"
9095
}

‎config/test-fixtures/basic.tf.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
},
8989

9090
"output": {
91+
"web_id": {
92+
"description": "The ID",
93+
"value": "${aws_instance.web.id}"
94+
},
9195
"web_ip": {
9296
"value": "${aws_instance.web.private_ip}"
9397
}

0 commit comments

Comments
 (0)