hashicorp / hashicorp/terraform-plugin-sdk
Unable to clear value for key in resource attribute's computed map
- Dominant language
- Go
- Stars
- 485
- Forks
- 244
- Avg merge
- 19h 57m
- Merged PRs (30d)
- 4
Description
### Terraform version
```
$ terraform version
Terraform v0.12.19
```
### SDK version
```json
{
"Path": "github.com/hashicorp/terraform-plugin-sdk",
"Version": "v1.5.0"
}
```
### Relevant provider source code
To demonstrate this with an isolated resource, I created a fake, dummy provider here: https://github.com/camlow325/terraform-provider-fake/tree/computed-params. The provider has a simple `foo` resource with the following schema definition:
```go
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"parameters": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Computed: true,
},
},
```
### Terraform Configuration Files
For testing this resource, I used the following config file:
```hcl
variable "param" {
default = ""
}
resource "fake_foo" "test" {
name = "tester"
parameters = {
TheParam = var.param
}
}
```
### Debug Output
### Crash Output
### Expected Behavior
The apply should report a change for the resource and the value for the map parameter should be cleared from state:
```hcl
resource "fake_foo" "test" {
id = "tester"
name = "tester"
parameters = {
"TheParam" = ""
}
}
```
### Actual Behavior
The apply reported no changes and the value for the map parameter remained unchanged in state:
```hcl
resource "fake_foo" "test" {
id = "tester"
name = "tester"
parameters = {
"TheParam" = "nonempty"
}
}
```
### Steps to Reproduce
1. `terraform init`
2. `terraform apply --var="param=nonempty"`
3. `terraform apply`
4. `terraform state show fake_foo.test`
### Additional Context
If I remove the `Computed: true` element reference from the `parameters` attribute in the schema definition, I'm unable to reproduce the issue. In this case, the parameter value is cleared during the second apply.
### References
- https://github.com/terraform-providers/terraform-provider-aws/issues/11312 - Issue filed for the `aws_cloudformation_stack` resource, which shows this same behavior.
Contributor guide
Research direction
Reproduce the behavior with the linked fake provider's computed-params branch using the configuration and four Terraform commands listed in the issue. Start from the resource schema's Optional and Computed parameters map, then trace the second apply and state output; done means changing the variable to an empty value produces a plan and clears TheParam from state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, terraform
- Domain
- backend-api-design, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100