[Custom Providers] Use of TypeSet vs TypeList vs TypeMap

505 views
Skip to first unread message

Chamila de Alwis

unread,
Apr 3, 2019, 10:37:34 PM4/3/19
to terrafo...@googlegroups.com
Hi,

I'm writing a custom Terraform provider with AWS provider as a reference code. One aspect I still can't grasp properly is the exact use of the TypeSet, TypeList, and TypeMap. AWS provider seems to interchangeably use TypeList and TypeSet wherever an array of strings is needed.

```
"vpc_zone_identifier": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
```

Also, just as I thought I understood TypeMap as something to be used for a "object" option like the following,

```
 13   event_selector {
 14     read_write_type           = "All"
 15     include_management_events = true
 16      
 17     data_resource {
 18       type = "AWS::S3::Object"
 19          
 20       values = [
 21         "arn:aws:s3:::",  
 22       ]
 23     }
 24   } 
```

AWS provider uses TypeList for that option.

```
"event_selector": {
Type: schema.TypeList,
Optional: true,
MaxItems: 5,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"read_write_type": {
Type: schema.TypeString,
Optional: true,
...
...
...
```

From [1] I understand that because of a known limitation, the above behavior uses TypeList for the outer structure instead of TypeMap. However, the documentation (that I could manage to find) on this topic is inadequate IMHO.

Greatly appreciate if the above use cases (and how to idiomatically read each type) can be explained or any resources that explain them can be provided.



Regards,
Chamila de Alwis
Committer and PMC Member - Apache Stratos

Chamila de Alwis

unread,
Apr 24, 2019, 2:30:27 PM4/24/19
to terrafo...@googlegroups.com
Hi team,

Greatly appreciate if the above could be clarified.

Regards,
Chamila de Alwis
Committer and PMC Member - Apache Stratos


Reply all
Reply to author
Forward
0 new messages