A use-case:
The cloudflare/cloudflare_page_rule resource takes an actions
block. Page Rules collectively form a priority list of rules, but only the highest-priority match is applied. Thus, if you want to extend the default behavior, the only way is to duplicate its actions
.
I’d love to be able to do this:
cloudflare_page_rule "special" {
target = "https://example.com/special"
actions = merge(cloudflare_page_rule.default.actions, {
cache_level = "bypass"
})
}
cloudflare_page_rule "default" {
target = "https://example.com/*"
actions {
cache_level = "cache_everything"
ip_geolocation = "on"
sort_query_string_for_cache = "on"
ssl = "strict"
true_client_ip_header = "on"
waf = "on"
}
}
Instead, I have to do this:
cloudflare_page_rule "special" {
target = "https://example.com/special"
actions {
cache_level = "bypass"
ip_geolocation = "on"
sort_query_string_for_cache = "on"
ssl = "strict"
true_client_ip_header = "on"
waf = "on"
}
}
cloudflare_page_rule "default" {
target = "https://example.com/*"
actions {
cache_level = "cache_everything"
ip_geolocation = "on"
sort_query_string_for_cache = "on"
ssl = "strict"
true_client_ip_header = "on"
waf = "on"
}
}
Not only is the duplication annoying, it presents a risk that someone changes the default
, not knowing that the other rules won’t inherit the setting.
(See also How to use locals in terraform to repeat and merge blocks?)