helper/schema: show computed lists in diffs

This commit is contained in:
Mitchell Hashimoto 2014-08-18 21:22:27 -07:00
parent ba819d1f37
commit c4664a81e6
2 changed files with 42 additions and 7 deletions

View File

@ -248,15 +248,25 @@ func (m schemaMap) diffList(
newLen = len(vs) newLen = len(vs)
// If the counts are not the same, then record that diff // If the counts are not the same, then record that diff
if oldLen != newLen { changed := oldLen != newLen
computed := oldLen == 0 && newLen == 0 && schema.Computed
if changed || computed {
countSchema := &Schema{ countSchema := &Schema{
Type: TypeInt, Type: TypeInt,
Computed: schema.Computed,
ForceNew: schema.ForceNew, ForceNew: schema.ForceNew,
} }
oldStr := ""
newStr := ""
if !computed {
oldStr = strconv.FormatInt(int64(oldLen), 10)
newStr = strconv.FormatInt(int64(newLen), 10)
}
diff.Attributes[k+".#"] = countSchema.finalizeDiff(&terraform.ResourceAttrDiff{ diff.Attributes[k+".#"] = countSchema.finalizeDiff(&terraform.ResourceAttrDiff{
Old: strconv.FormatInt(int64(oldLen), 10), Old: oldStr,
New: strconv.FormatInt(int64(newLen), 10), New: newStr,
}) })
} }

View File

@ -181,7 +181,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Diff: &terraform.ResourceDiff{ Diff: &terraform.ResourceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{ Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{ "ports.#": &terraform.ResourceAttrDiff{
Old: "", Old: "0",
New: "3", New: "3",
}, },
"ports.0": &terraform.ResourceAttrDiff{ "ports.0": &terraform.ResourceAttrDiff{
@ -285,7 +285,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Diff: &terraform.ResourceDiff{ Diff: &terraform.ResourceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{ Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{ "ports.#": &terraform.ResourceAttrDiff{
Old: "", Old: "0",
New: "3", New: "3",
RequiresNew: true, RequiresNew: true,
}, },
@ -310,6 +310,32 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false, Err: false,
}, },
{
Schema: map[string]*Schema{
"ports": &Schema{
Type: TypeList,
Optional: true,
Computed: true,
Elem: &Schema{Type: TypeInt},
},
},
State: nil,
Config: map[string]interface{}{},
Diff: &terraform.ResourceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "",
NewComputed: true,
},
},
},
Err: false,
},
/* /*
* List of structure decode * List of structure decode
*/ */
@ -343,7 +369,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Diff: &terraform.ResourceDiff{ Diff: &terraform.ResourceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{ Attributes: map[string]*terraform.ResourceAttrDiff{
"ingress.#": &terraform.ResourceAttrDiff{ "ingress.#": &terraform.ResourceAttrDiff{
Old: "", Old: "0",
New: "1", New: "1",
}, },
"ingress.0.from": &terraform.ResourceAttrDiff{ "ingress.0.from": &terraform.ResourceAttrDiff{
@ -632,7 +658,6 @@ func TestSchemaMap_Diff(t *testing.T) {
} }
for i, tc := range cases { for i, tc := range cases {
if i != 1 { continue }
c, err := config.NewRawConfig(tc.Config) c, err := config.NewRawConfig(tc.Config)
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)