Skip to content

Commit

Permalink
Merge pull request #2753 from iveelsm/mikey/origin-cache-control
Browse files Browse the repository at this point in the history
Add Origin Cache Control option to Rulesets API schema
  • Loading branch information
jacobbednarz authored Sep 15, 2023
2 parents 2b4b443 + 0b2f154 commit 48354d0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
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
Expand Up @@ -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"`
Expand Down
5 changes: 5 additions & 0 deletions internal/framework/service/rulesets/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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())
}
Expand Down
2 changes: 2 additions & 0 deletions internal/framework/service/rulesets/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
Expand Down Expand Up @@ -3962,6 +3963,7 @@ func testAccCloudflareRulesetCacheSettingsAllEnabled(rnd, accountID, zoneID stri
}
}
}
origin_cache_control = true
origin_error_page_passthru = false
}
expression = "true"
Expand Down
4 changes: 4 additions & 0 deletions internal/framework/service/rulesets/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions internal/sdkv2provider/data_source_rulesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 48354d0

Please sign in to comment.