hashicorp / hashicorp/terraform-plugin-sdk

Set ends up with additional empty elements

Open
#652 4 comments 4 reactions 0 assignees View on GitHub
bug subsystem/types
Dominant language
Go
Stars
485
Forks
244
Avg merge
19h 57m
Merged PRs (30d)
4

Description

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):

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

And i want to change it to something like this:

```hcl
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 ?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.