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

ComputedIf deletes diff key with same prefix #715

Closed
rick-masters opened this issue Feb 26, 2021 · 2 comments · Fixed by #716
Closed

ComputedIf deletes diff key with same prefix #715

rick-masters opened this issue Feb 26, 2021 · 2 comments · Fixed by #716
Labels
bug Something isn't working
Milestone

Comments

@rick-masters
Copy link
Contributor

SDK version

2.4.4

Relevant Provider Source Code

        CustomizeDiff: customdiff.Sequence(
            customdiff.ComputedIf("private_ips", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
                return diff.HasChange("private_ips_count")
            }),
        ),

Applied to this resource: https://github.com/hashicorp/terraform-provider-aws/blob/main/aws/resource_aws_network_interface.go

This functionality helps resolve issue hashicorp/terraform-provider-aws#9277 in the AWS provider as suggested here hashicorp/terraform-provider-aws#9277 (comment)

Terraform Configuration Files

resource "aws_network_interface" "test_iface" {
    subnet_id        = "subnet-redacted"
    private_ips_count = 4
    security_groups = ["sg-redacted"]
}

Debug Output

N/A

Expected Behavior

If private_ips_count is changed, private_ips should be computed.

Actual Behavior

If private_ips_count is changed, private_ips is computed but private_ips_count has its pending change deleted.

Steps

terraform init
terraform apply
# Change private_ips_count
terraform apply

Reference

The root cause of this problem is that clear(key string) in helper/schema/resource_diff.go is using strings.HasPrefix to delete nested keys but incorrectly finds overlapping plain keys. There is another function in resource_diff.go matching the same way.

@dd-willgan
Copy link

@rick-masters Thanks so much for detailing this, had the same issue!

@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

Successfully merging a pull request may close this issue.

3 participants