Skip to content

Commit

Permalink
Merge pull request #4787 from WowVeryLogin/denis/FLPROD-1439
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz authored Jan 29, 2025
2 parents 4aa2e65 + a4a4a4a commit 96f73b4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changelog/4787.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```release-note:enhancement
resource/snippets-rules: make terraform consistent with the API and do not require "enabled" and "description" fields
resource/snippets: use list instead of set
resource/cloud_connector_rules: use list instead of set
```
10 changes: 5 additions & 5 deletions internal/framework/service/cloud_connector_rules/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/MakeNowJust/heredoc/v2"
"github.com/cloudflare/terraform-provider-cloudflare/internal/consts"
"github.com/cloudflare/terraform-provider-cloudflare/internal/utils"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand All @@ -33,11 +33,11 @@ func (r *CloudConnectorRulesResource) Schema(ctx context.Context, req resource.S
},
},
Blocks: map[string]schema.Block{
"rules": schema.SetNestedBlock{
"rules": schema.ListNestedBlock{
MarkdownDescription: "List of Cloud Connector Rules",
Validators: []validator.Set{
setvalidator.SizeAtLeast(1),
setvalidator.IsRequired(),
Validators: []validator.List{
listvalidator.SizeAtLeast(1),
listvalidator.IsRequired(),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
Expand Down
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
23 changes: 16 additions & 7 deletions internal/framework/service/snippet_rules/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (

"github.com/MakeNowJust/heredoc/v2"
"github.com/cloudflare/terraform-provider-cloudflare/internal/consts"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/cloudflare/terraform-provider-cloudflare/internal/framework/modifiers/defaults"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand All @@ -30,16 +31,20 @@ func (r *SnippetRulesResource) Schema(ctx context.Context, req resource.SchemaRe
},
},
Blocks: map[string]schema.Block{
"rules": schema.SetNestedBlock{
"rules": schema.ListNestedBlock{
MarkdownDescription: "List of Snippet Rules",
Validators: []validator.Set{
setvalidator.SizeAtLeast(1),
setvalidator.IsRequired(),
Validators: []validator.List{
listvalidator.SizeAtLeast(1),
listvalidator.IsRequired(),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"enabled": schema.BoolAttribute{
Optional: true,
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Bool{
defaults.DefaultBool(true),
},
MarkdownDescription: "Whether the headers rule is active.",
},
"expression": schema.StringAttribute{
Expand All @@ -51,7 +56,11 @@ 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,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
MarkdownDescription: "Brief summary of the snippet rule and its intended use.",
},
},
Expand Down
10 changes: 5 additions & 5 deletions internal/framework/service/snippets/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/MakeNowJust/heredoc/v2"
"github.com/cloudflare/terraform-provider-cloudflare/internal/consts"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand Down Expand Up @@ -41,11 +41,11 @@ func (r *SnippetResource) Schema(ctx context.Context, req resource.SchemaRequest
},
},
Blocks: map[string]schema.Block{
"files": schema.SetNestedBlock{
"files": schema.ListNestedBlock{
MarkdownDescription: "List of Snippet Files",
Validators: []validator.Set{
setvalidator.SizeAtLeast(1),
setvalidator.IsRequired(),
Validators: []validator.List{
listvalidator.SizeAtLeast(1),
listvalidator.IsRequired(),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
Expand Down

0 comments on commit 96f73b4

Please sign in to comment.