hashicorp / hashicorp/terraform-plugin-sdk
Remove empty string value in schema.Schema
- Dominant language
- Go
- Stars
- 485
- Forks
- 244
- Avg merge
- 19h 57m
- Merged PRs (30d)
- 4
Description
### SDK version
```
github.com/hashicorp/terraform-plugin-sdk v1.14.0
```
### Relevant provider source code
#### case1
https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/autoscaling_tags.go#L17
```go
func autoscalingTagSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Required: true,
},
"value": {
Type: schema.TypeString,
Required: true,
},
"propagate_at_launch": {
Type: schema.TypeBool,
Required: true,
},
},
},
Set: autoscalingTagToHash,
}
}
```
#### case2
https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_autoscaling_group.go#L392
```hcl
"tags": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeMap,
Elem: &schema.Schema{Type: schema.TypeString},
},
ConflictsWith: []string{"tag"},
},
```
### Terraform Configuration Files
#### case1
```hcl
resource "aws_autoscaling_group" "this" {
tag {
key = "foo"
value = "foo"
propagate_at_launch = true
}
tag {
key = "bar"
value = ""
propagate_at_launch = true
}
}
```
#### case2
```hcl
resource "aws_autoscaling_group" "this" {
tags = [{
key = "foo"
value = "foo"
propagate_at_launch = true
},{
key = "bar"
value = ""
propagate_at_launch = true
}]
}
```
### Debug Output
#### terraform plan
`value` is dropped at the first element.
```hcl
+ tag {
+ key = "bar"
+ propagate_at_launch = true
}
+ tag {
+ key = "foo"
+ propagate_at_launch = true
+ value = "foo"
}
```
### Expected Behavior
`value` should be set even if it is empty string, `""`.
```hcl
+ tag {
+ key = "bar"
+ propagate_at_launch = true
+ value = ""
}
+ tag {
+ key = "foo"
+ propagate_at_launch = true
+ value = "foo"
}
```
### Actual Behavior
`value` key is removed if it is empty string.
### Steps to Reproduce
This issue can be reproduced using `aws_autoscaling_group` resource. Just write a code using it and `terraform plan`. And then you can see that the empty string value is removed in the output.
### References
- https://github.com/terraform-providers/terraform-provider-aws/issues/9049
Contributor guide
Assessment
This issue has not been assessed yet.