Skip to content

Commit

Permalink
SPEED-836: Deprecate Auto Minify settings
Browse files Browse the repository at this point in the history
This commit deprecates the settings for the Auto Minify feature whose
sunset date is set to August 8th, 2024.

After this date, it will not be able for the users of the Cloudflare
dashboard, Terraform provider to change that setting.
  • Loading branch information
aseure committed Jul 30, 2024
1 parent 24fb14c commit 7024045
Show file tree
Hide file tree
Showing 6 changed files with 591 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/3521.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:note
resource/zone_settings_override: deprecate `minify` setting and include state migration to remove from local state. You should immediately remove the configuration from the resource to prevent permadiffs.
```
2 changes: 1 addition & 1 deletion docs/resources/zone_settings_override.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Optional:
- `log_to_cloudflare` (String)
- `max_upload` (Number)
- `min_tls_version` (String)
- `minify` (Block List, Max: 1) (see [below for nested schema](#nestedblock--settings--minify))
- `minify` (Block List, Max: 1, Deprecated) (see [below for nested schema](#nestedblock--settings--minify))
- `mirage` (String)
- `mobile_redirect` (Block List, Max: 1, Deprecated) (see [below for nested schema](#nestedblock--settings--mobile_redirect))
- `nel` (Block List, Max: 1) (see [below for nested schema](#nestedblock--settings--nel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

func resourceCloudflareZoneSettingsOverride() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
SchemaVersion: 2,
Schema: resourceCloudflareZoneSettingsOverrideSchema(),
CreateContext: resourceCloudflareZoneSettingsOverrideCreate,
ReadContext: resourceCloudflareZoneSettingsOverrideRead,
Expand All @@ -32,6 +32,11 @@ func resourceCloudflareZoneSettingsOverride() *schema.Resource {
Type: resourceCloudflareZoneSettingsOverrideV0().CoreConfigSchema().ImpliedType(),
Upgrade: resourceCloudflareZoneSettingsOverrideStateUpgradeV1,
},
{
Version: 1,
Type: resourceCloudflareZoneSettingsOverrideV1().CoreConfigSchema().ImpliedType(),
Upgrade: resourceCloudflareZoneSettingsOverrideStateUpgradeV2,
},
},
}
}
Expand Down Expand Up @@ -195,7 +200,7 @@ func flattenZoneSettings(ctx context.Context, d *schema.ResourceData, settings [
continue
}

if s.ID == "minify" || s.ID == "nel" {
if s.ID == "nel" {
cfg[s.ID] = []interface{}{s.Value.(map[string]interface{})}
} else if s.ID == "security_header" {
cfg[s.ID] = []interface{}{s.Value.(map[string]interface{})["strict_transport_security"]}
Expand Down Expand Up @@ -363,7 +368,7 @@ func expandZoneSetting(d *schema.ResourceData, keyFormatString, k string, settin
zoneSettingValue = settingValue
}
}
case "minify", "nel":
case "nel":
{
listValue := settingValue.([]interface{})
if len(listValue) > 0 && listValue != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,49 @@ func resourceCloudflareZoneSettingsOverrideStateUpgradeV1(

return state, nil
}

func resourceCloudflareZoneSettingsOverrideV1() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"settings": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: resourceCloudflareZoneSettingsSchemaV1,
},
},

"initial_settings": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: resourceCloudflareZoneSettingsSchemaV1,
},
},
},
}
}

func resourceCloudflareZoneSettingsOverrideStateUpgradeV2(
_ context.Context,
rawState map[string]interface{},
_ interface{},
) (map[string]interface{}, error) {
errMsg := "could not upgrade cloudflare_zone_settings_override from v1 to v2"

if rawState == nil {
return nil, fmt.Errorf("%s: state is nil", errMsg)
}

upgrade := func(state map[string]interface{}, name string) map[string]interface{} {
delete(state[name].([]interface{})[0].(map[string]interface{}), "minify")
return state
}

state := upgrade(rawState, "settings")
state = upgrade(state, "initial_settings")

return state, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,38 @@ func TestCloudflareZoneSettingsOverrideStateUpgradeV0(t *testing.T) {

require.Equal(t, expectedV1, actualV1)
}

func TestCloudflareZoneSettingsOverrideStateUpgradeV1(t *testing.T) {
v1 := map[string]interface{}{
"settings": []interface{}{map[string]interface{}{
"minify": map[string]interface{}{
"css": "on",
"js": "on",
"html": "off",
},
"other_thing": "foo",
}},
"initial_settings": []interface{}{map[string]interface{}{
"minify": map[string]interface{}{
"css": "on",
"js": "on",
"html": "off",
},
"other_thing": "foo",
}},
}

expectedV2 := map[string]interface{}{
"settings": []interface{}{map[string]interface{}{
"other_thing": "foo",
}},
"initial_settings": []interface{}{map[string]interface{}{
"other_thing": "foo",
}},
}

actualV2, err := resourceCloudflareZoneSettingsOverrideStateUpgradeV2(context.Background(), v1, nil)
require.NoError(t, err)

require.Equal(t, expectedV2, actualV2)
}
Loading

0 comments on commit 7024045

Please sign in to comment.