Skip to content

Commit f191df8

Browse files
authored
Merge pull request #702 from cloudflare/handle-nested-maps-as-non-strings
2 parents 77fb02b + 8902e2f commit f191df8

File tree

4 files changed

+81
-112
lines changed

4 files changed

+81
-112
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestResourceGeneration(t *testing.T) {
112112
"cloudflare health check": {identiferType: "zone", resourceType: "cloudflare_healthcheck", testdataFilename: "cloudflare_healthcheck"},
113113
"cloudflare load balancer monitor": {identiferType: "account", resourceType: "cloudflare_load_balancer_monitor", testdataFilename: "cloudflare_load_balancer_monitor"},
114114
"cloudflare load balancer pool": {identiferType: "account", resourceType: "cloudflare_load_balancer_pool", testdataFilename: "cloudflare_load_balancer_pool"},
115-
// "cloudflare load balancer": {identiferType: "zone", resourceType: "cloudflare_load_balancer", testdataFilename: "cloudflare_load_balancer"},
115+
"cloudflare load balancer": {identiferType: "zone", resourceType: "cloudflare_load_balancer", testdataFilename: "cloudflare_load_balancer"},
116116
"cloudflare logpush jobs with filter": {identiferType: "zone", resourceType: "cloudflare_logpush_job", testdataFilename: "cloudflare_logpush_job_with_filter"},
117117
"cloudflare logpush jobs": {identiferType: "zone", resourceType: "cloudflare_logpush_job", testdataFilename: "cloudflare_logpush_job"},
118118
"cloudflare managed headers": {identiferType: "zone", resourceType: "cloudflare_managed_headers", testdataFilename: "cloudflare_managed_headers"},

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,11 @@ func writeAttrLine(key string, value interface{}, parentName string, body *hclwr
240240

241241
ctyMap := make(map[string]cty.Value)
242242
for _, v := range sortedKeys {
243-
if hasNumber(v) {
244-
ctyMap[fmt.Sprintf("%s", v)] = cty.StringVal(values[v].(string))
245-
} else {
246-
switch val := values[v].(type) {
247-
case string:
248-
ctyMap[v] = cty.StringVal(val)
249-
case float64:
250-
ctyMap[v] = cty.NumberFloatVal(val)
251-
}
243+
switch val := values[v].(type) {
244+
case string:
245+
ctyMap[v] = cty.StringVal(val)
246+
case float64:
247+
ctyMap[v] = cty.NumberFloatVal(val)
252248
}
253249
}
254250
body.SetAttributeValue(key, cty.ObjectVal(ctyMap))
Lines changed: 69 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,74 @@
11
---
22
version: 1
33
interactions:
4-
- request:
5-
body: ""
6-
form: {}
7-
headers:
8-
Content-Type:
9-
- application/json
10-
url: https://api.cloudflare.com/client/v4/zones/0da42c8d2132a9ddaf714f9e7c920711/load_balancers
11-
method: GET
12-
response:
13-
body: |
14-
{
15-
"success": true,
16-
"errors": [],
17-
"messages": [],
18-
"result": [
19-
{
20-
"id": "699d98642c564d2e855e9661899b7252",
21-
"created_on": "2014-01-01T05:20:00.12345Z",
22-
"modified_on": "2014-01-01T05:20:00.12345Z",
23-
"description": "Load Balancer for www.example.com",
24-
"name": "www.example.com",
25-
"enabled": true,
26-
"ttl": 30,
27-
"proxied": false,
28-
"fallback_pool": "17b5962d775c646f3f9725cbc7a53df4",
29-
"default_pools": [
30-
"17b5962d775c646f3f9725cbc7a53df4",
31-
"9290f38c5d07c2e2f4df57b1f61d4196",
32-
"00920f38ce07c2e2f4df50b1f61d4194"
33-
],
34-
"region_pools": {
35-
"ENAM": [
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
Content-Type:
9+
- application/json
10+
url: https://api.cloudflare.com/client/v4/zones/0da42c8d2132a9ddaf714f9e7c920711/load_balancers
11+
method: GET
12+
response:
13+
body: |
14+
{
15+
"success": true,
16+
"errors": [],
17+
"messages": [],
18+
"result": [
19+
{
20+
"id": "699d98642c564d2e855e9661899b7252",
21+
"created_on": "2014-01-01T05:20:00.12345Z",
22+
"modified_on": "2014-01-01T05:20:00.12345Z",
23+
"description": "Load Balancer for www.example.com",
24+
"name": "www.example.com",
25+
"enabled": true,
26+
"ttl": 30,
27+
"proxied": false,
28+
"fallback_pool": "17b5962d775c646f3f9725cbc7a53df4",
29+
"default_pools": [
30+
"17b5962d775c646f3f9725cbc7a53df4",
31+
"9290f38c5d07c2e2f4df57b1f61d4196",
3632
"00920f38ce07c2e2f4df50b1f61d4194"
3733
],
38-
"WNAM": [
39-
"de90f38ced07c2e2f4df50b1f61d4194",
40-
"9290f38c5d07c2e2f4df57b1f61d4196"
41-
]
42-
},
43-
"pop_pools": {
44-
"LAX": [
45-
"de90f38ced07c2e2f4df50b1f61d4194",
46-
"9290f38c5d07c2e2f4df57b1f61d4196"
47-
],
48-
"LHR": [
49-
"abd90f38ced07c2e2f4df50b1f61d4194",
50-
"f9138c5d07c2e2f4df57b1f61d4196"
51-
],
52-
"SJC": [
53-
"00920f38ce07c2e2f4df50b1f61d4194"
54-
]
55-
},
56-
"country_pools": {
57-
"AU": [
58-
"de90f38ced07c2e2f4df50b1f61d4194",
59-
"9290f38c5d07c2e2f4df57b1f61d4196"
60-
],
61-
"ME": [
62-
"00920f38ce07c2e2f4df50b1f61d4194"
63-
],
64-
"US": [
65-
"abd90f38ced07c2e2f4df50b1f61d4194",
66-
"f9138c5d07c2e2f4df57b1f61d4196"
67-
]
68-
},
69-
"steering_policy": "dynamic_latency",
70-
"session_affinity": "cookie",
71-
"session_affinity_attributes": {
72-
"samesite": "Auto",
73-
"secure": "Auto",
74-
"drain_duration": 100
75-
},
76-
"session_affinity_ttl": 5000
77-
}
78-
]
79-
}
80-
headers:
81-
Content-Type:
82-
- application/json
83-
Vary:
84-
- Accept-Encoding
85-
status: 200 OK
86-
code: 200
87-
duration: ""
34+
"region_pools": {
35+
"ENAM": [
36+
"00920f38ce07c2e2f4df50b1f61d4194"
37+
]
38+
},
39+
"pop_pools": {
40+
"SJC": [
41+
"00920f38ce07c2e2f4df50b1f61d4194"
42+
]
43+
},
44+
"country_pools": {
45+
"AU": [
46+
"de90f38ced07c2e2f4df50b1f61d4194",
47+
"9290f38c5d07c2e2f4df57b1f61d4196"
48+
]
49+
},
50+
"steering_policy": "dynamic_latency",
51+
"session_affinity": "cookie",
52+
"session_affinity_attributes": {
53+
"samesite": "Auto",
54+
"secure": "Auto",
55+
"drain_duration": 100
56+
},
57+
"session_affinity_ttl": 5000,
58+
"random_steering": {
59+
"default_weight": 1,
60+
"pool_weights": {
61+
"2c3f886957b4112bfaca8b12d87ce8c1": 0
62+
}
63+
}
64+
}
65+
]
66+
}
67+
headers:
68+
Content-Type:
69+
- application/json
70+
Vary:
71+
- Accept-Encoding
72+
status: 200 OK
73+
code: 200
74+
duration: ""

testdata/terraform/cloudflare_load_balancer/test.tf

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,20 @@ resource "cloudflare_load_balancer" "terraform_managed_resource" {
1414
country = "AU"
1515
pool_ids = ["de90f38ced07c2e2f4df50b1f61d4194", "9290f38c5d07c2e2f4df57b1f61d4196"]
1616
}
17-
country_pools {
18-
country = "ME"
19-
pool_ids = ["00920f38ce07c2e2f4df50b1f61d4194"]
20-
}
21-
country_pools {
22-
country = "US"
23-
pool_ids = ["abd90f38ced07c2e2f4df50b1f61d4194", "f9138c5d07c2e2f4df57b1f61d4196"]
24-
}
25-
pop_pools {
26-
pool_ids = ["de90f38ced07c2e2f4df50b1f61d4194", "9290f38c5d07c2e2f4df57b1f61d4196"]
27-
pop = "LAX"
28-
}
29-
pop_pools {
30-
pool_ids = ["abd90f38ced07c2e2f4df50b1f61d4194", "f9138c5d07c2e2f4df57b1f61d4196"]
31-
pop = "LHR"
32-
}
3317
pop_pools {
3418
pool_ids = ["00920f38ce07c2e2f4df50b1f61d4194"]
3519
pop = "SJC"
3620
}
21+
random_steering {
22+
default_weight = 1
23+
pool_weights = {
24+
"2c3f886957b4112bfaca8b12d87ce8c1" = 0
25+
}
26+
}
3727
region_pools {
3828
pool_ids = ["00920f38ce07c2e2f4df50b1f61d4194"]
3929
region = "ENAM"
4030
}
41-
region_pools {
42-
pool_ids = ["de90f38ced07c2e2f4df50b1f61d4194", "9290f38c5d07c2e2f4df57b1f61d4196"]
43-
region = "WNAM"
44-
}
4531
session_affinity_attributes {
4632
drain_duration = 100
4733
samesite = "Auto"

0 commit comments

Comments
 (0)