Skip to content

Commit

Permalink
FLPROD-1439: Make terraform config consistent with the API on declari…
Browse files Browse the repository at this point in the history
…ng optional fields for snippet rules
  • Loading branch information
Denis Davydov committed Dec 17, 2024
1 parent 739e49c commit 382c70f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/4787.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/snippets-rules: make terraform consistent with the API and do not require "enabled" and "description" fields
```
4 changes: 1 addition & 3 deletions internal/framework/service/snippet_rules/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestAccCloudflareSnippetRules(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "rules.0.%", "4"),
resource.TestCheckResourceAttr(resourceName, "rules.0.enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.0.expression", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.0.description", "some description 1"),
resource.TestCheckResourceAttr(resourceName, "rules.0.description", ""),
resource.TestCheckResourceAttr(resourceName, "rules.0.snippet_name", "test_snippet_0"),

resource.TestCheckResourceAttr(resourceName, "rules.1.%", "4"),
Expand Down Expand Up @@ -100,9 +100,7 @@ func testAccCheckCloudflareSnippetRules(rnd, zoneID string) string {
resource "cloudflare_snippet_rules" "%[1]s" {
zone_id = "%[2]s"
rules {
enabled = true
expression = "true"
description = "some description 1"
snippet_name = "test_snippet_0"
}
Expand Down
11 changes: 9 additions & 2 deletions internal/framework/service/snippet_rules/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/MakeNowJust/heredoc/v2"
"github.com/cloudflare/terraform-provider-cloudflare/internal/consts"
"github.com/cloudflare/terraform-provider-cloudflare/internal/framework/modifiers/defaults"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand Down Expand Up @@ -39,7 +40,10 @@ func (r *SnippetRulesResource) Schema(ctx context.Context, req resource.SchemaRe
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"enabled": schema.BoolAttribute{
Optional: true,
Optional: true,
PlanModifiers: []planmodifier.Bool{
defaults.DefaultBool(true),
},
MarkdownDescription: "Whether the headers rule is active.",
},
"expression": schema.StringAttribute{
Expand All @@ -51,7 +55,10 @@ func (r *SnippetRulesResource) Schema(ctx context.Context, req resource.SchemaRe
MarkdownDescription: "Name of the snippet invoked by this rule.",
},
"description": schema.StringAttribute{
Optional: true,
Optional: true,
PlanModifiers: []planmodifier.String{
defaults.DefaultString(""),
},
MarkdownDescription: "Brief summary of the snippet rule and its intended use.",
},
},
Expand Down

0 comments on commit 382c70f

Please sign in to comment.