Merge pull request #10643 from hashicorp/jbardin/GH-10640

Disaply interpolation strings for computed fields
This commit is contained in:
James Bardin 2016-12-09 15:31:42 -05:00 committed by GitHub
commit 626ad57546
2 changed files with 45 additions and 1 deletions

View File

@ -152,7 +152,7 @@ func formatPlanModuleExpand(
attrDiff := rdiff.Attributes[attrK] attrDiff := rdiff.Attributes[attrK]
v := attrDiff.New v := attrDiff.New
if attrDiff.NewComputed { if v == "" && attrDiff.NewComputed {
v = "<computed>" v = "<computed>"
} }

View File

@ -43,6 +43,50 @@ func TestFormatPlan_destroyDeposed(t *testing.T) {
} }
} }
// Test that computed fields with an interpolation string get displayed
func TestFormatPlan_displayInterpolations(t *testing.T) {
plan := &terraform.Plan{
Diff: &terraform.Diff{
Modules: []*terraform.ModuleDiff{
&terraform.ModuleDiff{
Path: []string{"root"},
Resources: map[string]*terraform.InstanceDiff{
"aws_instance.foo": &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"computed_field": &terraform.ResourceAttrDiff{
New: "${aws_instance.other.id}",
NewComputed: true,
},
},
},
},
},
},
},
}
opts := &FormatPlanOpts{
Plan: plan,
Color: &colorstring.Colorize{
Colors: colorstring.DefaultColors,
Disable: true,
},
ModuleDepth: 1,
}
out := FormatPlan(opts)
lines := strings.Split(out, "\n")
if len(lines) != 2 {
t.Fatal("expected 2 lines of output, got:\n", out)
}
actual := strings.TrimSpace(lines[1])
expected := `computed_field: "" => "${aws_instance.other.id}"`
if actual != expected {
t.Fatalf("expected:\n\n%s\n\ngot:\n\n%s", expected, actual)
}
}
// Test that a root level data source gets a special plan output on create // Test that a root level data source gets a special plan output on create
func TestFormatPlan_rootDataSource(t *testing.T) { func TestFormatPlan_rootDataSource(t *testing.T) {
plan := &terraform.Plan{ plan := &terraform.Plan{