core: Tests for hasComputedSubKeys fix
This covers: * Complex sets with computed fields in a set * Complex lists with computed fields in a set Adding a test to test basic lists with computed fields seemed to fail, but possibly for an unrelated reason (the list returned as nil). The fix to this inparticular case may be out of the scope of this specific issue. Reference gist and details in hashicorp/terraform#9171.
This commit is contained in:
parent
4d8208d840
commit
f258056731
|
@ -3267,6 +3267,157 @@ func TestSchemaMap_DiffSuppress(t *testing.T) {
|
|||
|
||||
Err: false,
|
||||
},
|
||||
|
||||
"Complex structure with set of computed string should mark root set as computed": {
|
||||
Schema: map[string]*Schema{
|
||||
"outer": &Schema{
|
||||
Type: TypeSet,
|
||||
Optional: true,
|
||||
Elem: &Resource{
|
||||
Schema: map[string]*Schema{
|
||||
"outer_str": &Schema{
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"inner": &Schema{
|
||||
Type: TypeSet,
|
||||
Optional: true,
|
||||
Elem: &Resource{
|
||||
Schema: map[string]*Schema{
|
||||
"inner_str": &Schema{
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Set: func(v interface{}) int {
|
||||
return 2
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Set: func(v interface{}) int {
|
||||
return 1
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
State: nil,
|
||||
|
||||
Config: map[string]interface{}{
|
||||
"outer": []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"outer_str": "foo",
|
||||
"inner": []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"inner_str": "${var.bar}",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
ConfigVariables: map[string]ast.Variable{
|
||||
"var.bar": interfaceToVariableSwallowError(config.UnknownVariableValue),
|
||||
},
|
||||
|
||||
Diff: &terraform.InstanceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||
"outer.#": &terraform.ResourceAttrDiff{
|
||||
Old: "0",
|
||||
New: "1",
|
||||
},
|
||||
"outer.~1.outer_str": &terraform.ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "foo",
|
||||
},
|
||||
"outer.~1.inner.#": &terraform.ResourceAttrDiff{
|
||||
Old: "0",
|
||||
New: "1",
|
||||
},
|
||||
"outer.~1.inner.~2.inner_str": &terraform.ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "${var.bar}",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Err: false,
|
||||
},
|
||||
|
||||
"Complex structure with complex list of computed string should mark root set as computed": {
|
||||
Schema: map[string]*Schema{
|
||||
"outer": &Schema{
|
||||
Type: TypeSet,
|
||||
Optional: true,
|
||||
Elem: &Resource{
|
||||
Schema: map[string]*Schema{
|
||||
"outer_str": &Schema{
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"inner": &Schema{
|
||||
Type: TypeList,
|
||||
Optional: true,
|
||||
Elem: &Resource{
|
||||
Schema: map[string]*Schema{
|
||||
"inner_str": &Schema{
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Set: func(v interface{}) int {
|
||||
return 1
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
State: nil,
|
||||
|
||||
Config: map[string]interface{}{
|
||||
"outer": []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"outer_str": "foo",
|
||||
"inner": []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"inner_str": "${var.bar}",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
ConfigVariables: map[string]ast.Variable{
|
||||
"var.bar": interfaceToVariableSwallowError(config.UnknownVariableValue),
|
||||
},
|
||||
|
||||
Diff: &terraform.InstanceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||
"outer.#": &terraform.ResourceAttrDiff{
|
||||
Old: "0",
|
||||
New: "1",
|
||||
},
|
||||
"outer.~1.outer_str": &terraform.ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "foo",
|
||||
},
|
||||
"outer.~1.inner.#": &terraform.ResourceAttrDiff{
|
||||
Old: "0",
|
||||
New: "1",
|
||||
},
|
||||
"outer.~1.inner.0.inner_str": &terraform.ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "${var.bar}",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Err: false,
|
||||
},
|
||||
}
|
||||
|
||||
for tn, tc := range cases {
|
||||
|
|
Loading…
Reference in New Issue