Skip to content
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

Attribute with nested Set is marked as changed even if values was not touched #710

Closed
oliver-schoenherr opened this issue Feb 20, 2021 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@oliver-schoenherr
Copy link
Contributor

SDK version

latest Plugin SDK version in master

Relevant SDK source code

resource_data.go takes not in consideration that the special case of comparing Set can happen not only on the first level but even deeper in the resource attribute tree.

func (d *ResourceData) HasChange(key string) bool {
	o, n := d.GetChange(key)
        
        // If the type implements the Equal interface, then call that
	// instead of just doing a reflect.DeepEqual. An example where this is
	// needed is *Set
	if eq, ok := o.(Equal); ok {
		return !eq.Equal(n)
	}

	return !reflect.DeepEqual(o, n)
}

Terraform Configuration Files

AWS ECS Service resource use such kind of schema:

resource "aws_ecs_service" "default" {
  ....
  network_configuration {
    security_groups = [
    aws_security_group.default.id]
    subnets          = var.subnet_ids
    assign_public_ip = false
  }
}

Expected Behavior

If network_configuration has no change, Terraform should not try to update the AWS ECS service.

Actual Behavior

Terraform tries to update the AWS ECS service always, even without any change in the network_configuration.

Steps to Reproduce

PR which enhance the resource_data_test.go test cases to reproduce the behaviour: https://github.com/oliver-schoenherr/terraform-plugin-sdk/pull/1/files

References

hashicorp/terraform-provider-aws#14711
hashicorp/terraform-provider-aws#13658

@oliver-schoenherr oliver-schoenherr added the bug Something isn't working label Feb 20, 2021
oliver-schoenherr added a commit to oliver-schoenherr/terraform-plugin-sdk that referenced this issue Feb 20, 2021
Compare resource attribute values more reliable. Use Equal method from Set even if Set is not on the top of the tree.
@bflad bflad closed this as completed in 46c610d Oct 12, 2021
@bflad bflad modified the milestones: v2.8.1, v2.9.0 Oct 12, 2021
@github-actions
Copy link

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.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants