Skip to content

Commit 4a3853e

Browse files
committed
feat: v4 to v5 migration for regional_hostname
1 parent 2be746e commit 4a3853e

File tree

7 files changed

+1089
-0
lines changed

7 files changed

+1089
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
variable "cloudflare_account_id" {
2+
description = "Cloudflare account ID"
3+
type = string
4+
}
5+
6+
variable "cloudflare_zone_id" {
7+
description = "Cloudflare zone ID"
8+
type = string
9+
}
10+
11+
# Pattern 1: Basic resource with required fields only
12+
resource "cloudflare_regional_hostname" "basic" {
13+
zone_id = var.cloudflare_zone_id
14+
hostname = "regional-basic.example.com"
15+
region_key = "eu"
16+
}
17+
18+
# Pattern 2: Resource with timeouts (should be removed)
19+
resource "cloudflare_regional_hostname" "with_timeouts" {
20+
zone_id = var.cloudflare_zone_id
21+
hostname = "regional-timeouts.example.com"
22+
region_key = "us"
23+
24+
}
25+
26+
# Pattern 3: Wildcard hostname
27+
resource "cloudflare_regional_hostname" "wildcard" {
28+
zone_id = var.cloudflare_zone_id
29+
hostname = "*.regional.example.com"
30+
region_key = "ca"
31+
}
32+
33+
# Pattern 4: for_each with map
34+
locals {
35+
regional_hosts_map = {
36+
eu = {
37+
hostname = "eu-regional.example.com"
38+
region_key = "eu"
39+
}
40+
us = {
41+
hostname = "us-regional.example.com"
42+
region_key = "us"
43+
}
44+
au = {
45+
hostname = "au-regional.example.com"
46+
region_key = "au"
47+
}
48+
}
49+
}
50+
51+
resource "cloudflare_regional_hostname" "by_region_map" {
52+
for_each = local.regional_hosts_map
53+
54+
zone_id = var.cloudflare_zone_id
55+
hostname = each.value.hostname
56+
region_key = each.value.region_key
57+
}
58+
59+
# Pattern 5: for_each with set
60+
locals {
61+
regional_hostnames_set = toset([
62+
"api-regional.example.com",
63+
"web-regional.example.com",
64+
"app-regional.example.com"
65+
])
66+
}
67+
68+
resource "cloudflare_regional_hostname" "from_set" {
69+
for_each = local.regional_hostnames_set
70+
71+
zone_id = var.cloudflare_zone_id
72+
hostname = each.value
73+
region_key = "eu"
74+
}
75+
76+
# Pattern 6: count-based resources
77+
resource "cloudflare_regional_hostname" "counted" {
78+
count = 3
79+
80+
zone_id = var.cloudflare_zone_id
81+
hostname = "regional-${count.index}.example.com"
82+
region_key = "us"
83+
}
84+
85+
# Pattern 7: Conditional resource creation
86+
variable "enable_regional" {
87+
type = bool
88+
default = true
89+
}
90+
91+
resource "cloudflare_regional_hostname" "conditional" {
92+
count = var.enable_regional ? 1 : 0
93+
94+
zone_id = var.cloudflare_zone_id
95+
hostname = "conditional-regional.example.com"
96+
region_key = "in"
97+
}
98+
99+
# Pattern 8: Using Terraform functions
100+
resource "cloudflare_regional_hostname" "with_functions" {
101+
zone_id = var.cloudflare_zone_id
102+
hostname = lower("UPPERCASE-REGIONAL.example.com")
103+
region_key = "ca"
104+
}
105+
106+
# Total: 1 + 1 + 1 + 3 (map) + 3 (set) + 3 (count) + 1 + 1 = 14 resources
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
{
2+
"lineage": "test-lineage-regional-hostname",
3+
"outputs": {},
4+
"resources": [
5+
{
6+
"instances": [
7+
{
8+
"attributes": {
9+
"created_on": "2023-01-15T10:30:00Z",
10+
"hostname": "regional-basic.example.com",
11+
"id": "regional-basic.example.com",
12+
"region_key": "eu",
13+
"routing": "dns",
14+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
15+
},
16+
"schema_version": 0
17+
}
18+
],
19+
"mode": "managed",
20+
"name": "basic",
21+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
22+
"type": "cloudflare_regional_hostname"
23+
},
24+
{
25+
"instances": [
26+
{
27+
"attributes": {
28+
"created_on": "2023-02-20T14:45:00Z",
29+
"hostname": "regional-timeouts.example.com",
30+
"id": "regional-timeouts.example.com",
31+
"region_key": "us",
32+
"routing": "dns",
33+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
34+
},
35+
"schema_version": 0
36+
}
37+
],
38+
"mode": "managed",
39+
"name": "with_timeouts",
40+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
41+
"type": "cloudflare_regional_hostname"
42+
},
43+
{
44+
"instances": [
45+
{
46+
"attributes": {
47+
"created_on": "2023-03-10T08:15:00Z",
48+
"hostname": "*.regional.example.com",
49+
"id": "*.regional.example.com",
50+
"region_key": "ca",
51+
"routing": "dns",
52+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
53+
},
54+
"schema_version": 0
55+
}
56+
],
57+
"mode": "managed",
58+
"name": "wildcard",
59+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
60+
"type": "cloudflare_regional_hostname"
61+
},
62+
{
63+
"instances": [
64+
{
65+
"attributes": {
66+
"created_on": "2023-04-05T12:00:00Z",
67+
"hostname": "au-regional.example.com",
68+
"id": "au-regional.example.com",
69+
"region_key": "au",
70+
"routing": "dns",
71+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
72+
},
73+
"index_key": "au",
74+
"schema_version": 0
75+
},
76+
{
77+
"attributes": {
78+
"created_on": "2023-04-05T12:00:00Z",
79+
"hostname": "eu-regional.example.com",
80+
"id": "eu-regional.example.com",
81+
"region_key": "eu",
82+
"routing": "dns",
83+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
84+
},
85+
"index_key": "eu",
86+
"schema_version": 0
87+
},
88+
{
89+
"attributes": {
90+
"created_on": "2023-04-05T12:00:00Z",
91+
"hostname": "us-regional.example.com",
92+
"id": "us-regional.example.com",
93+
"region_key": "us",
94+
"routing": "dns",
95+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
96+
},
97+
"index_key": "us",
98+
"schema_version": 0
99+
}
100+
],
101+
"mode": "managed",
102+
"name": "by_region_map",
103+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
104+
"type": "cloudflare_regional_hostname"
105+
},
106+
{
107+
"instances": [
108+
{
109+
"attributes": {
110+
"created_on": "2023-05-12T09:30:00Z",
111+
"hostname": "api-regional.example.com",
112+
"id": "api-regional.example.com",
113+
"region_key": "eu",
114+
"routing": "dns",
115+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
116+
},
117+
"index_key": "api-regional.example.com",
118+
"schema_version": 0
119+
},
120+
{
121+
"attributes": {
122+
"created_on": "2023-05-12T09:30:00Z",
123+
"hostname": "app-regional.example.com",
124+
"id": "app-regional.example.com",
125+
"region_key": "eu",
126+
"routing": "dns",
127+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
128+
},
129+
"index_key": "app-regional.example.com",
130+
"schema_version": 0
131+
},
132+
{
133+
"attributes": {
134+
"created_on": "2023-05-12T09:30:00Z",
135+
"hostname": "web-regional.example.com",
136+
"id": "web-regional.example.com",
137+
"region_key": "eu",
138+
"routing": "dns",
139+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
140+
},
141+
"index_key": "web-regional.example.com",
142+
"schema_version": 0
143+
}
144+
],
145+
"mode": "managed",
146+
"name": "from_set",
147+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
148+
"type": "cloudflare_regional_hostname"
149+
},
150+
{
151+
"instances": [
152+
{
153+
"attributes": {
154+
"created_on": "2023-06-01T14:00:00Z",
155+
"hostname": "regional-0.example.com",
156+
"id": "regional-0.example.com",
157+
"region_key": "us",
158+
"routing": "dns",
159+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
160+
},
161+
"index_key": 0,
162+
"schema_version": 0
163+
},
164+
{
165+
"attributes": {
166+
"created_on": "2023-06-01T14:00:00Z",
167+
"hostname": "regional-1.example.com",
168+
"id": "regional-1.example.com",
169+
"region_key": "us",
170+
"routing": "dns",
171+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
172+
},
173+
"index_key": 1,
174+
"schema_version": 0
175+
},
176+
{
177+
"attributes": {
178+
"created_on": "2023-06-01T14:00:00Z",
179+
"hostname": "regional-2.example.com",
180+
"id": "regional-2.example.com",
181+
"region_key": "us",
182+
"routing": "dns",
183+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
184+
},
185+
"index_key": 2,
186+
"schema_version": 0
187+
}
188+
],
189+
"mode": "managed",
190+
"name": "counted",
191+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
192+
"type": "cloudflare_regional_hostname"
193+
},
194+
{
195+
"instances": [
196+
{
197+
"attributes": {
198+
"created_on": "2023-07-15T11:20:00Z",
199+
"hostname": "conditional-regional.example.com",
200+
"id": "conditional-regional.example.com",
201+
"region_key": "in",
202+
"routing": "dns",
203+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
204+
},
205+
"index_key": 0,
206+
"schema_version": 0
207+
}
208+
],
209+
"mode": "managed",
210+
"name": "conditional",
211+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
212+
"type": "cloudflare_regional_hostname"
213+
},
214+
{
215+
"instances": [
216+
{
217+
"attributes": {
218+
"created_on": "2023-08-22T16:45:00Z",
219+
"hostname": "uppercase-regional.example.com",
220+
"id": "uppercase-regional.example.com",
221+
"region_key": "ca",
222+
"routing": "dns",
223+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711"
224+
},
225+
"schema_version": 0
226+
}
227+
],
228+
"mode": "managed",
229+
"name": "with_functions",
230+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
231+
"type": "cloudflare_regional_hostname"
232+
}
233+
],
234+
"serial": 1,
235+
"terraform_version": "1.5.0",
236+
"version": 4
237+
}

0 commit comments

Comments
 (0)