helper/schema: don't include zero count in state
This commit is contained in:
parent
5a5ef67d87
commit
ba819d1f37
|
@ -532,7 +532,9 @@ func (d *ResourceData) stateList(
|
|||
count := countRaw.(int)
|
||||
|
||||
result := make(map[string]string)
|
||||
result[prefix+".#"] = strconv.FormatInt(int64(count), 10)
|
||||
if count > 0 {
|
||||
result[prefix+".#"] = strconv.FormatInt(int64(count), 10)
|
||||
}
|
||||
for i := 0; i < count; i++ {
|
||||
key := fmt.Sprintf("%s.%d", prefix, i)
|
||||
|
||||
|
|
|
@ -406,6 +406,44 @@ func TestResourceDataGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
|
||||
// List of maps with removal in diff
|
||||
{
|
||||
Schema: map[string]*Schema{
|
||||
"config_vars": &Schema{
|
||||
Type: TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &Schema{
|
||||
Type: TypeMap,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
Attributes: map[string]string{
|
||||
"config_vars.#": "1",
|
||||
"config_vars.0.FOO": "bar",
|
||||
},
|
||||
},
|
||||
|
||||
Diff: &terraform.ResourceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||
"config_vars.#": &terraform.ResourceAttrDiff{
|
||||
Old: "1",
|
||||
New: "0",
|
||||
},
|
||||
"config_vars.0.FOO": &terraform.ResourceAttrDiff{
|
||||
Old: "bar",
|
||||
NewRemoved: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Key: "config_vars",
|
||||
|
||||
Value: []interface{}{},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
@ -1171,6 +1209,44 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
|
||||
// List of maps with removal in diff
|
||||
{
|
||||
Schema: map[string]*Schema{
|
||||
"config_vars": &Schema{
|
||||
Type: TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &Schema{
|
||||
Type: TypeMap,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
Attributes: map[string]string{
|
||||
"config_vars.#": "1",
|
||||
"config_vars.0.FOO": "bar",
|
||||
},
|
||||
},
|
||||
|
||||
Diff: &terraform.ResourceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||
"config_vars.#": &terraform.ResourceAttrDiff{
|
||||
Old: "1",
|
||||
New: "0",
|
||||
},
|
||||
"config_vars.0.FOO": &terraform.ResourceAttrDiff{
|
||||
Old: "bar",
|
||||
NewRemoved: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Attributes: map[string]string{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
|
Loading…
Reference in New Issue