hashicorp / hashicorp/terraform-plugin-sdk

nested Set does not detect updates to elements, only recreation

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

Description

### SDK version

```
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0
```

### Relevant provider source code

```go
Schema: map[string]*schema.Schema{
"user": {
Type: schema.TypeSet,
Elem: resourceDoorUser(),
Set: func(i interface{}) int {
m := i.(map[string]interface{})
token := m["token"].(string)
return schema.HashString(token)
},
Required: true,
},
},
// resourceDoorUser() schema
Schema: map[string]*schema.Schema{
"token": {
Type: schema.TypeString,
Computed: true,
},
"first_name": {
Type: schema.TypeString,
Required: true,
},
"last_name": {
Type: schema.TypeString,
Required: true,
},
"credential": {
Type: schema.TypeSet,
Elem: resourceDoorCredential(),
Optional: true,
},
},
// resourceDoorCredential() schema
Schema: map[string]*schema.Schema{
"token": {
Type: schema.TypeString,
Computed: true,
},
"profile_token": { // TODO this should support a set of profiles, not just a single one
Type: schema.TypeString,
Required: true,
},
"pin": {
Type: schema.TypeString,
Required: true,
},
}
```

### Terraform Configuration Files

```hcl
resource "axis_door_users" "test" {
user {
first_name = "Test"
last_name = "User"
credential {
profile_token = data.axis_door_profile.test.id //defined elsewhere
pin = "1234"
}
}

}
```

### Debug Output
https://gist.github.com/khumps/20e7510f20089c677aa64c248f6c0dd8

### Expected Behavior
If I change something about a user such as first/last name or profile_token or pin from credential it should show up in the plan as a change to the sub-block

### Actual Behavior
A full deletion of the sub-block followed by a creation of an identical one with the changes

### Steps to Reproduce
terraform apply followed by another terraform apply with a small change

Contributor guide

Open the contributing guide

Research direction

Start with the resource schema's nested TypeSet definitions and reproduce the issue by applying the shown configuration, changing a user or credential field, and running plan again. Trace the SDK's nested set hashing and diff behavior; done means the plan reports an update to the sub-block rather than deleting and recreating an identical block.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, terraform
Domain
infrastructure, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.