hashicorp / hashicorp/terraform-plugin-sdk

Optional+Computed attribute of type string can't be force zeroed

Open
#282 5 comments 1 reaction 0 assignees View on GitHub
enhancement subsystem/types
Dominant language
Go
Stars
485
Forks
244
Avg merge
19h 57m
Merged PRs (30d)
4

Description

### SDK version

```
v1.4.0
```

### Relevant provider source code

I just write a dummy provider to better illustrate my question.

Below code is the schema definition, there defined 3 different attributes:

- name: primitive type of string
- age: primitive type of int
- aliases: aggregate type of list

```go
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"age": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"aliases": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
```

### Terraform Configuration Files

```hcl
resource "example_server" "my-server" {
name = "foo"
age = 10
aliases = ["a", "b"]
}

```
### Steps to Reproduce

1. `terraform apply` with the config i attached above
2. modify the config to be as below (force zero each attribute):

```
resource "example_server" "my-server" {
name = ""
age = 0
aliases = []
}
```

3. `terraform plan`

### Expected Behavior

```
~ resource "example_server" "my-server" {
~ age = 10 -> 0
~ aliases = [
- "a",
- "b",
]
id = "1.2.3.5"
~ name = ""
}

```

### Actual Behavior

```
~ resource "example_server" "my-server" {
~ age = 10 -> 0
~ aliases = [
- "a",
- "b",
]
id = "1.2.3.5"
name = "foo"
}

```

The `name` attribute doesn't honour the force zero operartion.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the provided Optional+Computed schema and configuration, then trace how the SDK handles an empty string for the name attribute during planning. Done means a regression test demonstrates that changing name from a nonempty value to "" is preserved in the plan, consistently with age and aliases.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
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.