Skip to content

Commit bcf25d7

Browse files
authored
Merge pull request #507 from cloudflare/status-code-range-being-omitted
once we find an "id" use that as the ParentID for the rest of the rule
2 parents c441f6a + 329d4d6 commit bcf25d7

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

internal/app/cf-terraforming/cmd/util.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strings"
1212

1313
cloudflare "github.com/cloudflare/cloudflare-go"
14-
"github.com/google/uuid"
1514
tfjson "github.com/hashicorp/terraform-json"
1615
"github.com/sirupsen/logrus"
1716
"github.com/spf13/cobra"
@@ -221,21 +220,23 @@ func nestBlocks(schemaBlock *tfjson.SchemaBlock, structData map[string]interface
221220
case []interface{}:
222221
var previousNextedBlockOutput string
223222
for _, nestedItem := range s.([]interface{}) {
224-
parentID, exists := nestedItem.(map[string]interface{})["id"]
223+
_, exists := nestedItem.(map[string]interface{})["id"]
224+
if exists {
225+
parentID = nestedItem.(map[string]interface{})["id"].(string)
226+
}
225227
if !exists {
226228
// if we fail to find an ID, we tag the current element with a uuid
227229
log.Debugf("id not found for nestedItem %#v using uuid terraform_internal_id", nestedItem)
228-
parentID = uuid.New().String()
229230
nestedItem.(map[string]interface{})["terraform_internal_id"] = parentID
230231
}
231232

232-
nestedBlockOutput += nestBlocks(schemaBlock.NestedBlocks[block].Block, nestedItem.(map[string]interface{}), parentID.(string), indexedNestedBlocks)
233+
nestedBlockOutput += nestBlocks(schemaBlock.NestedBlocks[block].Block, nestedItem.(map[string]interface{}), parentID, indexedNestedBlocks)
233234

234235
if previousNextedBlockOutput != nestedBlockOutput {
235236
previousNextedBlockOutput = nestedBlockOutput
236237
// The indexedNestedBlocks maps helps us know which parent we're rendering the nested block for
237238
// So we append the current child's output to it, for when we render it out later
238-
indexedNestedBlocks[parentID.(string)] = append(indexedNestedBlocks[parentID.(string)], nestedBlockOutput)
239+
indexedNestedBlocks[parentID] = append(indexedNestedBlocks[parentID], nestedBlockOutput)
239240
}
240241
}
241242

testdata/cloudflare/cloudflare_ruleset_http_request_cache_settings.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,31 @@ interactions:
114114
"default": 60
115115
}
116116
}
117+
},
118+
{
119+
"id": "cd89ae000de64730bd61651c1b1f7f8c",
120+
"version": "1",
121+
"action": "set_cache_settings",
122+
"expression": "(http.host eq \"example.com\")",
123+
"description": "test cache rule 2",
124+
"last_updated": "2023-01-12T15:11:57.591876Z",
125+
"ref": "cd89ae000de64730bd61651c1b1f7f8c",
126+
"enabled": true,
127+
"action_parameters": {
128+
"cache": true,
129+
"edge_ttl": {
130+
"mode": "respect_origin",
131+
"status_code_ttl": [
132+
{
133+
"status_code_range": {
134+
"from": 100,
135+
"to": 200
136+
},
137+
"value": 300
138+
}
139+
]
140+
}
141+
}
117142
}
118143
],
119144
"last_updated": "2022-09-28T17:21:21.510301Z",

testdata/terraform/cloudflare_ruleset_http_request_cache_settings/test.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,23 @@ resource "cloudflare_ruleset" "terraform_managed_resource" {
5454
cache = false
5555
}
5656
}
57+
rules {
58+
action = "set_cache_settings"
59+
description = "test cache rule 2"
60+
enabled = true
61+
expression = "(http.host eq \"example.com\")"
62+
action_parameters {
63+
edge_ttl {
64+
status_code_ttl {
65+
value = 300
66+
status_code_range {
67+
from = 100
68+
to = 200
69+
}
70+
}
71+
mode = "respect_origin"
72+
}
73+
cache = true
74+
}
75+
}
5776
}

0 commit comments

Comments
 (0)