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

add edge_cache_ttl page rule and fix EdgeCacheTTLNotClobbered test #4745

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions internal/services/page_rule/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type PageRuleActionsModel struct {
DisablePerformance types.Bool `tfsdk:"disable_performance" json:"disable_performance,optional"`
DisableSecurity types.Bool `tfsdk:"disable_security" json:"disable_security,optional"`
DisableZaraz types.Bool `tfsdk:"disable_zaraz" json:"disable_zaraz,optional"`
EdgeCacheTTL types.Int64 `tfsdk:"edge_cache_ttl" json:"edge_cache_ttl,optional"`
EmailObfuscation types.String `tfsdk:"email_obfuscation" json:"email_obfuscation,optional"`
ExplicitCacheControl types.String `tfsdk:"explicit_cache_control" json:"explicit_cache_control,optional"`
ForwardingURL customfield.NestedObject[PageRuleActionsForwardingURLModel] `tfsdk:"forwarding_url" json:"forwarding_url,optional"`
Expand Down Expand Up @@ -142,6 +143,9 @@ func (m *PageRuleActionsModel) Encode() (encoded []map[string]any, err error) {
if m.DisableZaraz.ValueBool() {
encoded = append(encoded, map[string]any{"id": pagerules.PageRuleActionsIDDisableZaraz})
}
if !m.EdgeCacheTTL.IsNull() {
encoded = append(encoded, map[string]any{"id": pagerules.PageRuleActionsIDEdgeCacheTTL, "value": m.EdgeCacheTTL.ValueInt64()})
}
if !m.EmailObfuscation.IsNull() {
encoded = append(encoded, map[string]any{"id": pagerules.PageRuleActionsIDEmailObfuscation, "value": m.EmailObfuscation.ValueString()})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/services/page_rule/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,14 +1531,14 @@ func TestAccCloudflarePageRule_EdgeCacheTTLNotClobbered(t *testing.T) {
Config: testAccCheckCloudflarePageRuleConfigWithEdgeCacheTtl(zoneID, target, rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflarePageRuleExists(resourceName, &before),
resource.TestCheckResourceAttr(resourceName, "actions.0.edge_cache_ttl", "10"),
resource.TestCheckResourceAttr(resourceName, "actions.edge_cache_ttl", "7200"),
),
},
{
Config: testAccCheckCloudflarePageRuleConfigWithEdgeCacheTtlAndAlwaysOnline(zoneID, target, rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflarePageRuleExists(resourceName, &after),
resource.TestCheckResourceAttr(resourceName, "actions.0.edge_cache_ttl", "10"),
resource.TestCheckResourceAttr(resourceName, "actions.edge_cache_ttl", "7200"),
),
},
},
Expand Down
8 changes: 8 additions & 0 deletions internal/services/page_rule/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cloudflare/terraform-provider-cloudflare/internal/customfield"
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand Down Expand Up @@ -114,6 +115,13 @@ func ResourceSchema(ctx context.Context) schema.Schema {
"disable_zaraz": schema.BoolAttribute{
Optional: true,
},
"edge_cache_ttl": schema.Int64Attribute{
Optional: true,
Validators: []validator.Int64{
int64validator.AtLeast(7200),
Copy link
Member

Choose a reason for hiding this comment

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

this seems like alot for edge cache. is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

according to our open api schema this is correct. give me some time to fact check the actual code though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

according to the code, edge cache ttl can be as little as 0. I updated this PR. @mgirouard we're going to want to update the schemas sometime this week.

int64validator.AtMost(2419200),
},
},
"email_obfuscation": schema.StringAttribute{
Optional: true,
Validators: []validator.String{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

resource "cloudflare_page_rule" "%[3]s" {
zone_id = "%[1]s"
target = "%[2]s"
actions =[ {
ssl = "flexible"
edge_cache_ttl = 10
}]
}
resource "cloudflare_page_rule" "%[3]s"{
zone_id = "%[1]s"
target = "%[2]s"
actions = {
ssl = "flexible"
edge_cache_ttl = 7200
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

resource "cloudflare_page_rule" "%[3]s" {
zone_id = "%[1]s"
target = "%[2]s"
actions =[ {
edge_cache_ttl = 10
}]
}
zone_id = "%[1]s"
target = "%[2]s"
actions = {
edge_cache_ttl = 7200
}
}
Loading