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

Set ends up with additional empty elements #652

Open
eddycharly opened this issue Dec 7, 2020 · 4 comments · May be fixed by #1042
Open

Set ends up with additional empty elements #652

eddycharly opened this issue Dec 7, 2020 · 4 comments · May be fixed by #1042
Labels
bug Something isn't working subsystem/types Issues and feature requests related to the type system of Terraform and our shims around it.

Comments

@eddycharly
Copy link

When using a schema.Set, i end up with additional elements in the set (on update) with all fields initialized with default values.

Let's say i have a configuration like this (instance_group is the set here):

resource "cluster" "cluster" {
  instance_group {
    name = "compute-0"
    // ...
  }
  instance_group {
    name = "compute-1"
    // ...
  }
}

And i want to change it to something like this:

resource "cluster" "cluster" {
  instance_group {
    name = "node-0"
    // ...
  }
  instance_group {
    name = "node-1"
    // ...
  }
}

When i apply this change, the set contains node-0 and node-1 instance groups plus one empty element. I would expect the set to contain only node-0 and node-1.

SDK version

	github.com/hashicorp/terraform-plugin-sdk/v2 v2.3.0

Expected Behavior

Given the example above i would have expected to receive only node-0 and node-1 in the set elements when update function is invoked.

Actual Behavior

Update function receives node-0, node-1 and an additional empty element in the set elements.

Not sure it this behavior is expected, it looks a bit unnatural to me but maybe i'm missing something.
Correct me if i'm wrong, there's nothing bad returning a set when terraform calls the read function to refresh the state ?

@eddycharly eddycharly added the bug Something isn't working label Dec 7, 2020
@eddycharly eddycharly changed the title Sets ends up with additional empty elements Set ends up with additional empty elements Dec 7, 2020
@bflad
Copy link
Member

bflad commented Dec 9, 2020

Potentially related: #588

@eddycharly
Copy link
Author

Thanks, it looks the same indeed.
Is there a known workaround ? So many plugins rely on sets, i can't believe this issue went unnoticed.

@paddycarver paddycarver added the subsystem/types Issues and feature requests related to the type system of Terraform and our shims around it. label Jan 6, 2021
@bflad bflad added this to the v2.12.0 milestone Mar 15, 2022
@bflad bflad self-assigned this Mar 15, 2022
@bflad bflad modified the milestones: v2.12.0, v2.13.0 Mar 17, 2022
@prashantv
Copy link

In case anyone is looking for a workaround, copying a mitigation (that I originally posted in #895) -- use a list instead of a set.

@prashantv
Copy link

After this hitting this issue again in a scenario where we couldn't use a list, I spent some time investigating and think I have a fix: #1042. I'm not very familiar with this codebase, so it may not be the right fix, but it would be great to get some eyes on the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working subsystem/types Issues and feature requests related to the type system of Terraform and our shims around it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants