-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HasChange always return true for type map[string] Set #617
Comments
This is still occurring in v2.2.0. I will provide some test cases that demonstrate the error. |
Here are two test cases that can be added to This test case should not indicate that there is a change, but currently does: {
Schema: map[string]*Schema{
"vpc_config": {
Type: TypeList,
Optional: true,
Elem: &Resource{
Schema: map[string]*Schema{
"subnet_ids": {
Type: TypeSet,
Required: true,
Elem: &Schema{Type: TypeString},
Set: HashString,
},
},
},
},
},
State: &terraform.InstanceState{
Attributes: map[string]string{
"vpc_config.#": "1",
"vpc_config.0.subnet_ids.#": "1",
fmt.Sprintf("vpc_config.0.subnet_ids.%d", HashString("abc-123")): "abc-123",
},
},
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"tags.foo": {
Old: "",
New: "bar",
},
},
},
Key: "vpc_config",
Change: false,
}, This test case should indicate a change, and currently does: {
Schema: map[string]*Schema{
"vpc_config": {
Type: TypeList,
Optional: true,
Elem: &Resource{
Schema: map[string]*Schema{
"subnet_ids": {
Type: TypeSet,
Required: true,
Elem: &Schema{Type: TypeString},
Set: HashString,
},
},
},
},
},
State: &terraform.InstanceState{
Attributes: map[string]string{
"vpc_config.#": "1",
"vpc_config.0.subnet_ids.#": "1",
fmt.Sprintf("vpc_config.0.subnet_ids.%d", HashString("abc-123")): "abc-123",
},
},
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"vpc_config.0.subnet_ids.#": {
Old: "1",
New: "0",
},
},
},
Key: "vpc_config",
Change: true,
}, |
Hi, there is a PR related to this issue opened in November. Any chance that this PR can be looked at by the maintainers? |
As reported in #17385 a change i detected in vpc_config when there are no changes, this is caused by an issue in hashicorp/terraform-plugin-sdk#617 The PR to provide a fix is not getting any traction. On further debuging the issue is caused by the nested elements being of type set which needs the use of Equal rather than reflect.DeepEqual to test for differences. We can work around this bug by testing for changes in the two fields within vpc_config independantly as when the item passed to HasChanges is a Set it is tested correctly.
The fix for this (#711) has been merged and will release with the next Terraform Plugin SDK version. 👍 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
SDK version
Relevant provider source code
Terraform Configuration Files
Debug Output
I can see d.HasChange has used Set's Equal() before reflect.DeepEqual(o, n). But it works only for Set. It doesn't work for complicated struct including type Set.
Expected Behavior
If no update in "network_rules", d.HasChange("network_rules") should return false
Actual Behavior
d.HasChange("network_rules") always return true
Steps to Reproduce
Please list the full steps required to reproduce the issue, for example:
terraform init
terraform apply
terraform apply
References
The text was updated successfully, but these errors were encountered: