From b64c0c2139f66949ab75917c410db25b0e982a79 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Wed, 11 Dec 2019 01:37:33 -0800 Subject: [PATCH] zone_settings_overrid: Remap 0rtt attribute name to zero_rtt `0rtt` is not a valid HCL attribute name (the scanner begins to process this as a digit, not a string). Fixes: #555 --- CHANGELOG.md | 2 +- .../resource_cloudflare_zone_settings_override.go | 11 ++++++++++- ...resource_cloudflare_zone_settings_override_test.go | 3 +++ website/docs/r/zone_settings_override.html.markdown | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8083c9d9e..3a2e6dd88d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ **Improvements:** * `resource/cloudflare_zone_settings_override`: Add `non_identity` to allowed `decision` schema ([#541](https://github.com/terraform-providers/terraform-provider-cloudflare/issues/541)) -* `resource/cloudflare_zone_settings_override`: Add support for `0rtt` and `http3` settings ([#542](https://github.com/terraform-providers/terraform-provider-cloudflare/issues/542)) +* `resource/cloudflare_zone_settings_override`: Add support for `zero_rtt` and `http3` settings ([#542](https://github.com/terraform-providers/terraform-provider-cloudflare/issues/542)) * `resource/cloudflare_load_balancer_monitor`: Allow empty string for `expected_body` ([#539](https://github.com/terraform-providers/terraform-provider-cloudflare/issues/539)) * `resource/cloudflare_worker_script`: Add support for Worker KV Namespace Bindings ([#544](https://github.com/terraform-providers/terraform-provider-cloudflare/issues/544)) * `data_source/waf_rules`, `resource/cloudflare_waf_rule`, Support allowed modes for WAF Rules ([#550](https://github.com/terraform-providers/terraform-provider-cloudflare/issues/550)) diff --git a/cloudflare/resource_cloudflare_zone_settings_override.go b/cloudflare/resource_cloudflare_zone_settings_override.go index 47e0c3f8eb..2749ad3578 100644 --- a/cloudflare/resource_cloudflare_zone_settings_override.go +++ b/cloudflare/resource_cloudflare_zone_settings_override.go @@ -476,7 +476,7 @@ var resourceCloudflareZoneSettingsSchema = map[string]*schema.Schema{ Computed: true, }, - "0rtt": { + "zero_rtt": { Type: schema.TypeString, ValidateFunc: validation.StringInSlice([]string{"on", "off"}, false), Optional: true, @@ -585,6 +585,10 @@ func resourceCloudflareZoneSettingsOverrideRead(d *schema.ResourceData, meta int func flattenZoneSettings(d *schema.ResourceData, settings []cloudflare.ZoneSetting, flattenAll bool) []map[string]interface{} { cfg := map[string]interface{}{} for _, s := range settings { + if s.ID == "0rtt" { // NOTE: 0rtt is an invalid attribute in HCLs grammar. Remap to `zero_rtt` + s.ID = "zero_rtt" + } + if !settingInSchema(s.ID) { log.Printf("[WARN] Value not in schema returned from API zone settings (is it new?) - %q : %#v", s.ID, s.Value) continue @@ -690,6 +694,11 @@ func expandOverriddenZoneSettings(d *schema.ResourceData, settingsKey string, re return zoneSettings, err } + // Remap zero_rtt key back to Cloudflare's setting name, 0rtt + if k == "zero_rtt" { + k = "0rtt" + } + if zoneSettingValue != nil { newZoneSetting := cloudflare.ZoneSetting{ ID: k, diff --git a/cloudflare/resource_cloudflare_zone_settings_override_test.go b/cloudflare/resource_cloudflare_zone_settings_override_test.go index 690801d4d3..f42440038a 100644 --- a/cloudflare/resource_cloudflare_zone_settings_override_test.go +++ b/cloudflare/resource_cloudflare_zone_settings_override_test.go @@ -58,6 +58,8 @@ func TestAccCloudflareZoneSettingsOverride_Full(t *testing.T) { name, "settings.0.security_level", "high"), resource.TestCheckResourceAttr( name, "settings.0.h2_prioritization", "on"), + resource.TestCheckResourceAttr( + name, "settings.0.zero_rtt", "off"), ), }, }, @@ -230,6 +232,7 @@ resource "cloudflare_zone_settings_override" "test" { security_header { enabled = true } + zero_rtt = "off" } }`, zoneID) } diff --git a/website/docs/r/zone_settings_override.html.markdown b/website/docs/r/zone_settings_override.html.markdown index c84c7da4cb..57d180d4cd 100644 --- a/website/docs/r/zone_settings_override.html.markdown +++ b/website/docs/r/zone_settings_override.html.markdown @@ -76,7 +76,7 @@ These can be specified as "on" or "off" string. Similar to boolean values, but h * `waf` (default: `off`) * `webp` (default: `off`). Note that the value specified will be ignored unless `polish` is turned on (i.e. is "lossless" or "lossy") * `websockets` (default: `off`) -* `0rtt` (default: `off`) +* `zero_rtt` (default: `off`) ### String Values