Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudflare_tiered_cache: add cf-tf support for new resource #557

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/app/cf-terraforming/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,22 @@ 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{})["cache_type"] = tieredCache.Type.String()
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved
default:
fmt.Fprintf(cmd.OutOrStdout(), "%q is not yet supported for automatic generation", resourceType)
return
Expand Down
1 change: 1 addition & 0 deletions internal/app/cf-terraforming/cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
61 changes: 61 additions & 0 deletions testdata/cloudflare/cloudflare_tiered_cache.yaml
Original file line number Diff line number Diff line change
@@ -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: ""
7 changes: 7 additions & 0 deletions testdata/terraform/cloudflare_tiered_cache/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
}
}
}
4 changes: 4 additions & 0 deletions testdata/terraform/cloudflare_tiered_cache/test.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "cloudflare_tiered_cache" "terraform_managed_resource" {
cache_type = "smart"
zone_id = "0da42c8d2132a9ddaf714f9e7c920711"
}