hashicorp / hashicorp/terraform-plugin-sdk

Add support for maps with non-primitive types (rich / object map support)

Open
#62 9 comments 21 reactions 1 assignee Claimed by @appilon View on GitHub
enhancement subsystem/types terraform-plugin-framework
Dominant language
Go
Stars
485
Forks
244
Avg merge
19h 57m
Merged PRs (30d)
4

Description

### Terraform Version

`Terraform v0.6.14`
### Terraform Configuration Files

``` hcl
resource "aws_api_gateway_stage" "boo" {
rest_api_id = "${aws_api_gateway_rest_api.demo.id}"
name = "test"

method_setting "yada" {
metrics_enabled = true
logging_level = "DEBUG"
}

method_setting "bada" {
metrics_enabled = false
logging_level = "ERROR"
}
}
```
### Expected Behavior

```
+ aws_api_gateway_stage.boo
rest_api_id: "" => "${aws_api_gateway_rest_api.demo.id}"
name: "" => "test"
method_setting.#: "" => "2"
method_setting.yada.metrics_enabled: "" => "1"
method_setting.yada.logging_level: "" => "DEBUG"
method_setting.bada.metrics_enabled: "" => "0"
method_setting.bada.logging_level: "" => "ERROR"
```
### Actual Behavior

```
Error running plan: 1 error(s) occurred:

* method_setting: 2 error(s) decoding:

* '[bada]' expected type 'string', got unconvertible type '[]map[string]interface {}'
* '[yada]' expected type 'string', got unconvertible type '[]map[string]interface {}'
```
### Steps to Reproduce

``` go

"method_setting": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"metrics_enabled": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},
"logging_level": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"data_trace_enabled": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},
},
},
},
```

```
$ terraform plan
```

The current schema does support `TypeMap` which translates into `map[string]interface{}`. The interface is then decoded via `mapstructure`:
https://github.com/mitchellh/mapstructure/blob/master/mapstructure.go#L70

which seems to support slice of maps, but somehow expects string.

---

I'm creating this issue as I'm working around this by putting the key inside `TypeSet` as another field and I plan to link here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.