Skip to content

Add Origin Cache Control option to Rulesets API schema #2753

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

Merged
merged 2 commits into from
Sep 15, 2023
Merged
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/2753.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_ruleset: Add support for the use of Origin Cache Control in the Rulesets API
```
1 change: 1 addition & 0 deletions internal/framework/service/rulesets/model.go
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ type ActionParametersModel struct {
Mirage types.Bool `tfsdk:"mirage"`
OpportunisticEncryption types.Bool `tfsdk:"opportunistic_encryption"`
Origin []*ActionParameterOriginModel `tfsdk:"origin"`
OriginCacheControl types.Bool `tfsdk:"origin_cache_control"`
OriginErrorPagePassthru types.Bool `tfsdk:"origin_error_page_passthru"`
Overrides []*ActionParameterOverridesModel `tfsdk:"overrides"`
Phases types.Set `tfsdk:"phases"`
5 changes: 5 additions & 0 deletions internal/framework/service/rulesets/resource.go
Original file line number Diff line number Diff line change
@@ -352,6 +352,7 @@ func toRulesetResourceModel(ctx context.Context, zoneID, accountID basetypes.Str
ServerSideExcludes: flatteners.Bool(ruleResponse.ActionParameters.ServerSideExcludes),
StatusCode: flatteners.Int64(int64(ruleResponse.ActionParameters.StatusCode)),
SXG: flatteners.Bool(ruleResponse.ActionParameters.SXG),
OriginCacheControl: flatteners.Bool(ruleResponse.ActionParameters.OriginCacheControl),
OriginErrorPagePassthru: flatteners.Bool(ruleResponse.ActionParameters.OriginErrorPagePassthru),
RespectStrongEtags: flatteners.Bool(ruleResponse.ActionParameters.RespectStrongETags),
Version: flatteners.String(cloudflare.String(ruleResponse.ActionParameters.Version)),
@@ -919,6 +920,10 @@ func (r *RulesModel) toRulesetRule(ctx context.Context) cloudflare.RulesetRule {
rr.ActionParameters.OriginErrorPagePassthru = cloudflare.BoolPtr(ap.OriginErrorPagePassthru.ValueBool())
}

if !ap.OriginCacheControl.IsNull() {
rr.ActionParameters.OriginCacheControl = cloudflare.BoolPtr(ap.OriginCacheControl.ValueBool())
}

if !ap.RespectStrongEtags.IsNull() {
rr.ActionParameters.RespectStrongETags = cloudflare.BoolPtr(ap.RespectStrongEtags.ValueBool())
}
2 changes: 2 additions & 0 deletions internal/framework/service/rulesets/resource_test.go
Original file line number Diff line number Diff line change
@@ -1836,6 +1836,7 @@ func TestAccCloudflareRuleset_CacheSettingsAllEnabled(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.cache_key.0.custom_key.0.user.0.device_type", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.cache_key.0.custom_key.0.user.0.geo", "false"),
resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.cache_key.0.custom_key.0.host.0.resolved", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.origin_cache_control", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.origin_error_page_passthru", "false"),
),
},
@@ -3962,6 +3963,7 @@ func testAccCloudflareRulesetCacheSettingsAllEnabled(rnd, accountID, zoneID stri
}
}
}
origin_cache_control = true
origin_error_page_passthru = false
}
expression = "true"
4 changes: 4 additions & 0 deletions internal/framework/service/rulesets/schema.go
Original file line number Diff line number Diff line change
@@ -219,6 +219,10 @@ func (r *RulesetResource) Schema(ctx context.Context, req resource.SchemaRequest
Optional: true,
MarkdownDescription: "Turn on or off the Cloudflare Opportunistic Encryption feature of the Edge Certificates tab in the Cloudflare SSL/TLS app.",
},
"origin_cache_control": schema.BoolAttribute{
Optional: true,
MarkdownDescription: "Enable or disable the use of a more compliant Cache Control parsing mechanism, enabled by default for most zones.",
},
"phases": schema.SetAttribute{
ElementType: types.StringType,
Optional: true,
5 changes: 5 additions & 0 deletions internal/sdkv2provider/data_source_rulesets.go
Original file line number Diff line number Diff line change
@@ -828,6 +828,11 @@ func resourceCloudflareRulesetSchema() map[string]*schema.Schema {
},
},
},
"origin_cache_control": {
Type: schema.TypeBool,
Optional: true,
Description: "Sets a more compliant mode for parsing Cache Control headers",
},
"origin_error_page_passthru": {
Type: schema.TypeBool,
Optional: true,