Skip to content

Commit

Permalink
Do not use TypeMap for non-primitive types, use TypeList
Browse files Browse the repository at this point in the history
Currently, TypeMap doesn't support non-primitive type values.
ref : hashicorp/terraform-plugin-sdk#62

When using non-primitive values with TypeMap, terraform crashes at
runtime with a following error message.

```
panic: Unknown validation type: 6
```

This error is originated at
https://github.com/hashicorp/terraform-plugin-sdk/blob/v2.11.0/helper/schema/schema.go#L2017
Only TypeBool, TypeInt, TypeFloat and TypeString are supported.

So, in this change, use TypeList with new custom resource to store
non-primitive values.
  • Loading branch information
0gajun committed Mar 18, 2022
1 parent ed246a3 commit 9bf1bf9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/1520.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_notification_policy: Fix unexpected crashes when using cloudflare_notification_policy with a filters attribute
```
2 changes: 1 addition & 1 deletion cloudflare/resource_cloudflare_notification_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func buildNotificationPolicy(d *schema.ResourceData) cloudflare.NotificationPoli
}

if filters, ok := d.GetOk("filters"); ok {
notificationPolicy.Filters = filters.(map[string][]string)
notificationPolicy.Filters = filters.([]interface{})[0].(map[string][]string)
}

if conditions, ok := d.GetOk("conditions"); ok {
Expand Down
23 changes: 19 additions & 4 deletions cloudflare/schema_cloudflare_notification_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,26 @@ func resourceCloudflareNotificationPolicySchema() map[string]*schema.Schema {
Required: true,
},
"filters": {
Type: schema.TypeMap,
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeList,
Elem: schema.TypeString,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"zones": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
},
"services": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
},
},
},
},
"created": {
Expand Down

0 comments on commit 9bf1bf9

Please sign in to comment.