I have a Terraform resource called test_resource with a nested TypeSet attribute called input_interface. Here’s an example configuration:
resource "test_resource" "example" {
name = "example-resource"
input_interface {
name = "interface-1"
corr_id = "corr-12345"
legacy_ports = [80, 443]
enable_feature = true
domains {
name = "test"
auto_delete = true
}
}
input_interface {
name = "interface-2"
corr_id = "corr-67890"
legacy_ports = [22]
enable_feature = false
}
}
input_interfaceis aTypeSetattribute.- Each
input_interfacehas optional fields likelegacy_portsandenable_feature. - The
domainsblock is a nested structure with fields likenameandauto_delete.
When Terraform processes this resource, it uses a hash function to uniquely identify each input_interface in the set. However, if the hash function doesn’t handle optional or computed fields correctly, it leads to inconsistent behavior in the GetChange function. call, often returning dummy and incomplete values.
When you update this resource, Terraform uses the GetChange function to compare the old and new states of the input_interface set. However, you might notice that the GetChange output contains incomplete or dummy values, such as:
- Empty
corr_idornamefields. - Missing or incomplete
domainsblocks. - Incorrect or partial
legacy_portsvalues.
For example, the newList in GetChange might look like this
*Set(map[string]interface{}{
"entry-1": map[string]interface{}{
"name": "interface-1",
"corr_id": "", // Empty or dummy value
"legacy_ports": []interface{}{}, // Empty or dummy value
"enable_feature": false, // Incorrect value
"domains": []interface{}{}, // Missing or incomplete
},
"entry-2": map[string]interface{}{
"name": "interface-2",
"corr_id": "corr-67890",
"legacy_ports": []interface{}{22},
"enable_feature": false,
"domains": []interface{}{}, // Missing or incomplete
},
})