Skip to content

Commit ffa8cbe

Browse files
committed
feat: v4 to v5 migration for regional_hostname
1 parent 1565a0c commit ffa8cbe

File tree

9 files changed

+1411
-0
lines changed

9 files changed

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

0 commit comments

Comments
 (0)