Skip to content

Commit

Permalink
Merge pull request #1947 from yan12125/issue1937
Browse files Browse the repository at this point in the history
resource/cloudflare_email_routing_catch_all: switch to a dedicated scheme
  • Loading branch information
jacobbednarz committed Oct 4, 2022
2 parents 1006158 + c96985a commit 821c1e1
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .changelog/1947.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_email_routing_catch_all: switch to a dedicated scheme to allow type = "drop"
```
12 changes: 3 additions & 9 deletions docs/resources/email_routing_catch_all.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ resource "cloudflare_email_routing_catch_all" "example" {
### Optional

- `enabled` (Boolean) Routing rule status.
- `priority` (Number) Priority of the routing rule.

### Read-Only

Expand All @@ -52,20 +51,15 @@ resource "cloudflare_email_routing_catch_all" "example" {

Required:

- `type` (String) Type of supported action.
- `value` (List of String) An array with items in the following form.
- `type` (String) Type of supported action. Available values: `drop`, `forward`, `worker`.
- `value` (List of String) A list with items in the following form.


<a id="nestedblock--matcher"></a>
### Nested Schema for `matcher`

Required:

- `type` (String) Type of matcher.

Optional:

- `field` (String) Field for type matcher.
- `value` (String) Value for matcher.
- `type` (String) Type of matcher. Available values: `all`.


Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func resourceCloudflareEmailRoutingCatchAll() *schema.Resource {
return &schema.Resource{
Schema: resourceCloudflareEmailRoutingRuleSchema(),
Schema: resourceCloudflareEmailRoutingCatchAllSchema(),
ReadContext: resourceCloudflareEmailRoutingCatchAllRead,
CreateContext: resourceCloudflareEmailRoutingCatchAllUpdate,
UpdateContext: resourceCloudflareEmailRoutingCatchAllUpdate,
Expand Down
13 changes: 9 additions & 4 deletions internal/provider/resource_cloudflare_email_routing_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ func buildMatchersAndActions(d *schema.ResourceData) (matchers []cloudflare.Emai
if items, ok := d.GetOk("matcher"); ok {
for _, item := range items.(*schema.Set).List() {
matcher := item.(map[string]interface{})
matchers = append(matchers, cloudflare.EmailRoutingRuleMatcher{
matcherStruct := cloudflare.EmailRoutingRuleMatcher{
Type: matcher["type"].(string),
Field: matcher["field"].(string),
Value: matcher["value"].(string),
})
}
if val, ok := matcher["field"]; ok {
matcherStruct.Field = val.(string)
}
if val, ok := matcher["value"]; ok {
matcherStruct.Value = val.(string)
}
matchers = append(matchers, matcherStruct)
}
}

Expand Down
71 changes: 71 additions & 0 deletions internal/provider/schema_cloudflare_email_routing_catch_all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package provider

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func resourceCloudflareEmailRoutingCatchAllSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"zone_id": {
Description: "The zone identifier to target for the resource.",
Type: schema.TypeString,
Required: true,
},
"tag": {
Description: "Routing rule identifier.",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Routing rule name.",
Type: schema.TypeString,
Required: true,
},
"enabled": {
Description: "Routing rule status.",
Type: schema.TypeBool,
Optional: true,
},
"matcher": {
Description: "Matching patterns to forward to your actions.",
Type: schema.TypeSet,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Description: fmt.Sprintf("Type of matcher. %s", renderAvailableDocumentationValuesStringSlice([]string{"all"})),
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"all"}, true),
},
},
},
},
"action": {
Description: "List actions patterns.",
Type: schema.TypeSet,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Description: fmt.Sprintf("Type of supported action. %s", renderAvailableDocumentationValuesStringSlice([]string{"drop", "forward", "worker"})),
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"drop", "forward", "worker"}, true),
},
"value": {
Description: "A list with items in the following form.",
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringLenBetween(0, 90),
},
},
},
},
},
}
}

0 comments on commit 821c1e1

Please sign in to comment.