hashicorp / hashicorp/terraform-plugin-sdk

TypeSet with nested TypeMap shows empty map in plan output when a map is removed from config

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

Description

### SDK version

```
"v2.0.1" (also tested against v1)
```

### Relevant provider source code
Excerpt from aws/resource_aws_autoscaling_group.go (`v3.7.0`):

```go
"tags": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeMap,
Elem: &schema.Schema{Type: schema.TypeString},
},
```

### Terraform Configuration Files

https://gist.github.com/anGie44/417856ad8231c96a89cf9e0d0356817f

### Debug Output

```
020/09/20 02:02:43 [WARN] Provider "registry.terraform.io/hashicorp/aws" produced an invalid plan for aws_autoscaling_group.bar, but we are tolerating it because it is using the legacy plugin SDK.
The following problems may be the cause of any confusing errors from downstream operations:
- .tags: planned value cty.SetVal([]cty.Value{cty.MapVal(map[string]cty.Value{"key":cty.StringVal("Name"), "propagate_at_launch":cty.StringVal("true"), "value":cty.StringVal("example")}), cty.MapValEmpty(cty.String)}) does not match config value cty.SetVal([]cty.Value{cty.MapVal(map[string]cty.Value{"key":cty.StringVal("Name"), "propagate_at_launch":cty.StringVal("true"), "value":cty.StringVal("example")})}) nor prior value cty.SetVal([]cty.Value{cty.MapVal(map[string]cty.Value{"key":cty.StringVal("Name"), "propagate_at_launch":cty.StringVal("true"), "value":cty.StringVal("example")}), cty.MapVal(map[string]cty.Value{"key":cty.StringVal("Owner"), "propagate_at_launch":cty.StringVal("true"), "value":cty.StringVal("bezos")})})
```
### Expected Behavior
```hcl
~ tags = [
{
"key" = "Name"
"propagate_at_launch" = "true"
"value" = "example"
},
- {
- "key" = "Owner"
- "propagate_at_launch" = "true"
- "value" = "bezos"
},
]
```

### Actual Behavior
```hcl
~ tags = [
{
"key" = "Name"
"propagate_at_launch" = "true"
"value" = "example"
},
- {
- "key" = "Owner"
- "propagate_at_launch" = "true"
- "value" = "bezos"
},
+ {},
]
```

### Steps to Reproduce
1. Using main.tf:
a. `terraform init`
b. `terraform apply`

2. Using update.tf (same as main.tf but with 2nd map in `tags` removed):
a. `terraform plan`

### References
* https://github.com/terraform-providers/terraform-provider-aws/issues/15227

Contributor guide

Open the contributing guide

Research direction

Start by checking go.mod for the SDK version and reproduce the issue with main.tf and update.tf using terraform plan. Trace how the SDK represents the nested TypeSet and TypeMap when the second map is removed. Done means the plan shows only the removed Owner map, without an additional empty map.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.