Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FLPROD-1439: Make terraform config consistent with the API on declaring optional fields for snippet rules #4787

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(""),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need an empty string here? or can it be totally optional?

},
MarkdownDescription: "Brief summary of the snippet rule and its intended use.",
},
},
Expand Down
Loading