From 394b48a55a13b58ba3c8ec68bb03a981707275b4 Mon Sep 17 00:00:00 2001 From: Chenxi Zhang Date: Thu, 4 May 2023 16:55:18 -0700 Subject: [PATCH 1/3] cloudflare_tiered_cache: add cf-tf support for new resource --- internal/app/cf-terraforming/cmd/generate.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/app/cf-terraforming/cmd/generate.go b/internal/app/cf-terraforming/cmd/generate.go index 943e82ad3..8284f8072 100644 --- a/internal/app/cf-terraforming/cmd/generate.go +++ b/internal/app/cf-terraforming/cmd/generate.go @@ -1068,6 +1068,23 @@ func generateResources() func(cmd *cobra.Command, args []string) { // tls_1_2_only is deprecated in favour of min_tls jsonStructData[i].(map[string]interface{})["settings"].(map[string]interface{})["tls_1_2_only"] = nil } + case "cloudflare_tiered_cache": + tieredCache, err := api.GetTieredCache(context.Background(), &cloudflare.ResourceContainer{Identifier: zoneID}) + if err != nil { + log.Fatal(err) + } + var jsonPayload []cloudflare.TieredCache + jsonPayload = append(jsonPayload, tieredCache) + + resourceCount = 1 + m, _ := json.Marshal(jsonPayload) + err = json.Unmarshal(m, &jsonStructData) + if err != nil { + log.Fatal(err) + } + + jsonStructData[0].(map[string]interface{})["id"] = zoneID + jsonStructData[0].(map[string]interface{})["cache_type"] = tieredCache.Type.String() default: fmt.Fprintf(cmd.OutOrStdout(), "%q is not yet supported for automatic generation", resourceType) return From 131df3489a0548bd7f4526b71a9eccd89d84c993 Mon Sep 17 00:00:00 2001 From: Chenxi Zhang Date: Fri, 5 May 2023 13:48:52 -0700 Subject: [PATCH 2/3] Add tests for cloudflare_tiered_cache generation --- .../app/cf-terraforming/cmd/generate_test.go | 1 + .../cloudflare/cloudflare_tiered_cache.yaml | 61 +++++++++++++++++++ .../cloudflare_tiered_cache/provider.tf | 7 +++ .../terraform/cloudflare_tiered_cache/test.tf | 4 ++ 4 files changed, 73 insertions(+) create mode 100644 testdata/cloudflare/cloudflare_tiered_cache.yaml create mode 100644 testdata/terraform/cloudflare_tiered_cache/provider.tf create mode 100644 testdata/terraform/cloudflare_tiered_cache/test.tf diff --git a/internal/app/cf-terraforming/cmd/generate_test.go b/internal/app/cf-terraforming/cmd/generate_test.go index 1048d878e..e399ca8a3 100644 --- a/internal/app/cf-terraforming/cmd/generate_test.go +++ b/internal/app/cf-terraforming/cmd/generate_test.go @@ -147,6 +147,7 @@ func TestResourceGeneration(t *testing.T) { "cloudflare workers kv namespace": {identiferType: "account", resourceType: "cloudflare_workers_kv_namespace", testdataFilename: "cloudflare_workers_kv_namespace"}, "cloudflare zone lockdown": {identiferType: "zone", resourceType: "cloudflare_zone_lockdown", testdataFilename: "cloudflare_zone_lockdown"}, "cloudflare zone settings override": {identiferType: "zone", resourceType: "cloudflare_zone_settings_override", testdataFilename: "cloudflare_zone_settings_override"}, + "cloudflare tiered cache": {identiferType: "zone", resourceType: "cloudflare_tiered_cache", testdataFilename: "cloudflare_tiered_cache"}, // "cloudflare access group (account)": {identiferType: "account", resourceType: "cloudflare_access_group", testdataFilename: "cloudflare_access_group_account"}, // "cloudflare access group (zone)": {identiferType: "zone", resourceType: "cloudflare_access_group", testdataFilename: "cloudflare_access_group_zone"}, diff --git a/testdata/cloudflare/cloudflare_tiered_cache.yaml b/testdata/cloudflare/cloudflare_tiered_cache.yaml new file mode 100644 index 000000000..6fe2652a0 --- /dev/null +++ b/testdata/cloudflare/cloudflare_tiered_cache.yaml @@ -0,0 +1,61 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://api.cloudflare.com/client/v4/zones/0da42c8d2132a9ddaf714f9e7c920711/argo/tiered_caching + method: GET + response: + body: | + { + "result":{ + "id":"tiered_caching", + "value":"on", + "modified_on":"2023-05-04T22:40:43.188743Z", + "editable":false + }, + "success":true, + "errors":[], + "messages":[] + } + headers: + Content-Type: + - application/json + Vary: + - Accept-Encoding + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://api.cloudflare.com/client/v4/zones/0da42c8d2132a9ddaf714f9e7c920711/cache/tiered_cache_smart_topology_enable + method: GET + response: + body: | + { + "result": { + "editable": true, + "id": "tiered_cache_smart_topology_enable", + "modified_on": "2023-05-04T22:43:20.834177Z", + "value": "on" + }, + "success": true, + "errors": [], + "messages": [] + } + headers: + Content-Type: + - application/json + Vary: + - Accept-Encoding + status: 200 OK + code: 200 + duration: "" diff --git a/testdata/terraform/cloudflare_tiered_cache/provider.tf b/testdata/terraform/cloudflare_tiered_cache/provider.tf new file mode 100644 index 000000000..6d4066837 --- /dev/null +++ b/testdata/terraform/cloudflare_tiered_cache/provider.tf @@ -0,0 +1,7 @@ +terraform { + required_providers { + cloudflare = { + source = "cloudflare/cloudflare" + } + } +} diff --git a/testdata/terraform/cloudflare_tiered_cache/test.tf b/testdata/terraform/cloudflare_tiered_cache/test.tf new file mode 100644 index 000000000..69c20683b --- /dev/null +++ b/testdata/terraform/cloudflare_tiered_cache/test.tf @@ -0,0 +1,4 @@ +resource "cloudflare_tiered_cache" "terraform_managed_resource" { + cache_type = "smart" + zone_id = "0da42c8d2132a9ddaf714f9e7c920711" +} From cbdf286c6af87a9442dce2fe33f75140be047d67 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Fri, 19 May 2023 10:11:07 +1000 Subject: [PATCH 3/3] remove unnecessary id mapping --- internal/app/cf-terraforming/cmd/generate.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/app/cf-terraforming/cmd/generate.go b/internal/app/cf-terraforming/cmd/generate.go index 8284f8072..428964617 100644 --- a/internal/app/cf-terraforming/cmd/generate.go +++ b/internal/app/cf-terraforming/cmd/generate.go @@ -1083,7 +1083,6 @@ func generateResources() func(cmd *cobra.Command, args []string) { log.Fatal(err) } - jsonStructData[0].(map[string]interface{})["id"] = zoneID jsonStructData[0].(map[string]interface{})["cache_type"] = tieredCache.Type.String() default: fmt.Fprintf(cmd.OutOrStdout(), "%q is not yet supported for automatic generation", resourceType)