generated from oracle-quickstart/oci-quickstart-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdns.tf
357 lines (316 loc) · 15.8 KB
/
dns.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# ####################################################################################################### #
# Copyright (c) 2023 Oracle and/or its affiliates, All rights reserved. #
# Licensed under the Universal Permissive License v 1.0 as shown at https: //oss.oracle.com/licenses/upl. #
# Author: Flavius Sana #
# Author email: [email protected] #
# Last Modified: Sat Dec 9 2023 #
# Modified by: Flavius Sana, email: [email protected] #
# ####################################################################################################### #
locals {
one_dimension_dns_tsig_keys = local.one_dimension_processed_vcns != null ? {
for flat_tsig_keys in flatten([
for vcn_key, vcn_value in local.one_dimension_processed_vcns :
vcn_value.dns_resolver != null ? vcn_value.dns_resolver.tsig_keys != null ? [
for tsig_key_key, tsig_key_value in vcn_value.dns_resolver.tsig_keys : {
vcn_key = vcn_key
tsig_key_key = tsig_key_key
algorithm = tsig_key_value.algorithm
compartment_id = tsig_key_value.compartment_id != null ? tsig_key_value.compartment_id : vcn_value.category_compartment_id != null ? vcn_value.category_compartment_id : vcn_value.default_compartment_id != null ? vcn_value.default_compartment_id : null
name = tsig_key_value.name
secret = tsig_key_value.secret
defined_tags = tsig_key_value.defined_tags
freeform_tags = tsig_key_value.freeform_tags
}
] : [] : []
]) : flat_tsig_keys.tsig_key_key => flat_tsig_keys
} : {}
one_dimension_resolver_endpoints = local.one_dimension_processed_vcns != null ? {
for flat_resolver_endpoint in flatten([
for vcn_key, vcn_value in local.one_dimension_processed_vcns :
vcn_value.dns_resolver != null ? vcn_value.dns_resolver.resolver_endpoints != null ? [
for resolver_endpoint_key, resolver_endpoint_value in vcn_value.dns_resolver.resolver_endpoints : {
name = resolver_endpoint_value.name
vcn_key = vcn_key
resolver_endpoint_key = resolver_endpoint_key
is_forwarding = resolver_endpoint_value.is_forwarding
is_listening = resolver_endpoint_value.is_listening
subnet = resolver_endpoint_value.subnet != null ? oci_core_subnet.these[resolver_endpoint_value.subnet].id : null
endpoint_type = resolver_endpoint_value.endpoint_type
forwarding_address = resolver_endpoint_value.forwarding_address
listening_address = resolver_endpoint_value.listening_address
nsgs = resolver_endpoint_value.nsg != null ? [
for key in resolver_endpoint_value.nsg :
oci_core_network_security_group.these[key].id
] : []
}
] : [] : []
]) : flat_resolver_endpoint.resolver_endpoint_key => flat_resolver_endpoint
} : {}
one_dimension_resolver = local.one_dimension_processed_vcns != null ? {
for flat_resolver in flatten([
for vcn_key, vcn_value in local.one_dimension_processed_vcns :
vcn_value.dns_resolver != null ? [{
vcn_key = vcn_key
display_name = vcn_value.dns_resolver.display_name
rules = vcn_value.dns_resolver.rules != null ? vcn_value.dns_resolver.rules : []
attached_views = vcn_value.dns_resolver.attached_views
defined_tags = vcn_value.dns_resolver.defined_tags
freeform_tags = vcn_value.dns_resolver.freeform_tags
}] : []
]) : flat_resolver.vcn_key => flat_resolver
} : {}
one_dimension_dns_views = local.one_dimension_processed_vcns != null ? {
for flat_attached_views in flatten([
for vcn_key, vcn_value in local.one_dimension_processed_vcns :
vcn_value.dns_resolver != null ? vcn_value.dns_resolver.attached_views != null ? [
for view_key, view_value in vcn_value.dns_resolver.attached_views : {
vcn_key = vcn_key
view_key = view_key
compartment_id = view_value.compartment_id != null ? view_value.compartment_id : vcn_value.category_compartment_id != null ? vcn_value.category_compartment_id : vcn_value.default_compartment_id != null ? vcn_value.default_compartment_id : null
display_name = view_value.display_name
defined_tags = view_value.defined_tags
freeform_tags = view_value.freeform_tags
} if view_value.existing_view_id == null
] : [] : []
]) : flat_attached_views.view_key => flat_attached_views
} : {}
one_dimension_dns_zones = local.one_dimension_processed_vcns != null ? {
for flat_dns_zones in flatten([
for vcn_key, vcn_value in local.one_dimension_processed_vcns :
vcn_value.dns_resolver != null ? vcn_value.dns_resolver.attached_views != null ? [
for view_key, view_value in vcn_value.dns_resolver.attached_views :
view_value.dns_zones != null ? [
for zone_key, zone_value in view_value.dns_zones : {
zone_key = zone_key
view_key = zone_value.scope != "GLOBAL" ? view_key : null
compartment_id = zone_value.compartment_id != null ? zone_value.compartment_id : vcn_value.category_compartment_id != null ? vcn_value.category_compartment_id : vcn_value.default_compartment_id != null ? vcn_value.default_compartment_id : null
name = zone_value.name
defined_tags = zone_value.defined_tags
freeform_tags = zone_value.freeform_tags
scope = zone_value.scope
external_downstreams = zone_value.external_downstreams != null ? zone_value.external_downstreams : []
external_masters = zone_value.external_masters != null ? zone_value.external_masters : []
zone_type = zone_value.zone_type
view_id = view_value.existing_view_id
}
] : []
] : [] : []
]) : flat_dns_zones.zone_key => flat_dns_zones
} : {}
one_dimension_dns_steering_policies = local.one_dimension_processed_vcns != null ? {
for flat_dns_steering_policies in flatten([
for vcn_key, vcn_value in local.one_dimension_processed_vcns :
vcn_value.dns_resolver != null ? vcn_value.dns_resolver.attached_views != null ? [
for view_key, view_value in vcn_value.dns_resolver.attached_views :
view_value.dns_zones != null ? [
for zone_key, zone_value in view_value.dns_zones : [
for steering_policy_key, steering_policy_value in coalesce(zone_value.dns_steering_policies,{}) : {
zone_key = zone_key
steering_policy_key = steering_policy_key
domain_name = steering_policy_value.domain_name
compartment_id = steering_policy_value.compartment_id != null ? steering_policy_value.compartment_id : vcn_value.category_compartment_id != null ? vcn_value.category_compartment_id : vcn_value.default_compartment_id != null ? vcn_value.default_compartment_id : null
template = steering_policy_value.template
answers = steering_policy_value.answers
defined_tags = steering_policy_value.defined_tags
freeform_tags = steering_policy_value.freeform_tags
health_check_monitor_id = steering_policy_value.health_check_monitor_id
rules = steering_policy_value.rules
ttl = steering_policy_value.ttl
}
]
] : []
] : [] : []
]) : flat_dns_steering_policies.zone_key => flat_dns_steering_policies
} : {}
one_dimension_dns_rrset = local.one_dimension_processed_vcns != null ? {
for flat_dns_rrset in flatten([
for vcn_key, vcn_value in local.one_dimension_processed_vcns :
vcn_value.dns_resolver != null ? vcn_value.dns_resolver.attached_views != null ? [
for view_key, view_value in vcn_value.dns_resolver.attached_views :
view_value.dns_zones != null ? [
for zone_key, zone_value in view_value.dns_zones : [
zone_value.dns_rrset != null ? [
for rrset_key, rrset_value in zone_value.dns_rrset : {
rrset_key = rrset_key
zone_key = zone_key
view_key = view_key
compartment_id = rrset_value.compartment_id != null ? rrset_value.compartment_id : vcn_value.category_compartment_id != null ? vcn_value.category_compartment_id : vcn_value.default_compartment_id != null ? vcn_value.default_compartment_id : null
rtype = rrset_value.rtype
domain = rrset_value.domain
scope = rrset_value.scope
items = rrset_value.items
}] : []
]
] : []
] : [] : []
]) : flat_dns_rrset.rrset_key => flat_dns_rrset
} : {}
}
data "oci_core_vcn_dns_resolver_association" "dns_resolvers" {
for_each = local.one_dimension_processed_vcns
vcn_id = oci_core_vcn.these[each.key].id
depends_on = [time_sleep.wait_for_dns_resolver]
}
resource "oci_dns_view" "these" {
for_each = local.one_dimension_dns_views
compartment_id = each.value.compartment_id
display_name = each.value.display_name
scope = "PRIVATE"
defined_tags = each.value.defined_tags
freeform_tags = each.value.freeform_tags
}
resource "oci_dns_zone" "these" {
for_each = local.one_dimension_dns_zones
compartment_id = each.value.compartment_id
name = each.value.name
scope = each.value.scope
zone_type = each.value.zone_type
view_id = each.value.view_key != null ? (contains(keys(oci_dns_view.these),each.value.view_key) ? oci_dns_view.these[each.value.view_key].id : (length(regexall("^ocid1.*$", each.value.view_id)) > 0 ? each.value.view_id : var.network_dependency["dns_private_views"][each.value.view_id].id)) : null
dynamic "external_downstreams" {
for_each = each.value.external_downstreams
iterator = downstream
content {
address = downstream.value.address
port = downstream.value.port
tsig_key_id = oci_dns_tsig_key.these[downstream.tsig_key].id
}
}
dynamic "external_masters" {
for_each = each.value.external_masters
iterator = master
content {
address = master.value.address
port = master.value.port
tsig_key_id = oci_dns_tsig_key.these[master.tsig_key].id
}
}
defined_tags = each.value.defined_tags
freeform_tags = each.value.freeform_tags
}
resource "oci_dns_rrset" "these" {
for_each = local.one_dimension_dns_rrset
compartment_id = each.value.compartment_id
domain = each.value.domain
rtype = each.value.rtype
zone_name_or_id = oci_dns_zone.these[each.value.zone_key].id
view_id = oci_dns_view.these[each.value.view_key].id
scope = each.value.scope
dynamic "items" {
for_each = each.value.items
iterator = item
content {
domain = item.value.domain
rdata = item.value.rdata
rtype = item.value.rtype
ttl = item.value.ttl
}
}
}
resource "oci_dns_tsig_key" "these" {
for_each = local.one_dimension_dns_tsig_keys
compartment_id = each.value.compartment_id
name = each.value.name
secret = each.value.secret
algorithm = each.value.algorithm
defined_tags = each.value.defined_tags
freeform_tags = each.value.freeform_tags
}
resource "oci_dns_resolver_endpoint" "these" {
for_each = local.one_dimension_resolver_endpoints
is_forwarding = each.value.is_forwarding
is_listening = each.value.is_listening
name = each.value.name
resolver_id = data.oci_core_vcn_dns_resolver_association.dns_resolvers[each.value.vcn_key].dns_resolver_id
subnet_id = each.value.subnet
scope = "PRIVATE"
endpoint_type = each.value.endpoint_type
forwarding_address = each.value.forwarding_address
listening_address = each.value.listening_address
nsg_ids = each.value.nsgs
}
resource "time_sleep" "wait_for_dns_resolver" {
create_duration = "60s"
depends_on = [oci_core_vcn.these]
}
resource "oci_dns_resolver" "these" {
for_each = local.one_dimension_resolver
resolver_id = data.oci_core_vcn_dns_resolver_association.dns_resolvers[each.value.vcn_key].dns_resolver_id
scope = "PRIVATE"
display_name = each.value.display_name
dynamic "attached_views" {
for_each = each.value.attached_views
iterator = views
content {
view_id = views.key != null ? (contains(keys(oci_dns_view.these),views.key) ? oci_dns_view.these[views.key].id : (length(regexall("^ocid1.*$", views.value.existing_view_id)) > 0 ? views.value.existing_view_id : var.network_dependency["dns_private_views"][views.value.existing_view_id].id)) : null
}
}
defined_tags = each.value.defined_tags
freeform_tags = each.value.freeform_tags
dynamic "rules" {
for_each = each.value.rules
iterator = rule
content {
action = rule.value.action
destination_addresses = rule.value.destination_address
source_endpoint_name = oci_dns_resolver_endpoint.these[rule.value.source_endpoint_name].name
client_address_conditions = rule.value.client_address_conditions != null ? rule.value.client_address_conditions : []
qname_cover_conditions = rule.value.qname_cover_conditions != null ? rule.value.qname_cover_conditions : []
}
}
depends_on = [data.oci_core_vcn_dns_resolver_association.dns_resolvers]
}
resource "oci_dns_steering_policy" "these" {
for_each = local.one_dimension_dns_steering_policies
compartment_id = each.value.compartment_id
display_name = each.value.display_name
template = each.value.template
dynamic "answers" {
for_each = each.value.answers
iterator = answer
content {
name = answer.value.name
rdata = answer.value.rdata
rtype = answer.value.rtype
is_disabled = answer.value.is_disabled
pool = [answer.value.pool]
}
}
defined_tags = each.value.defined_tags
freeform_tags = each.value.freeform_tags
health_check_monitor_id = each.value.health_check_monitor_id
dynamic "rules" {
for_each = each.value.rules
iterator = rule
content {
rule_type = rule.value.rule_type
dynamic "cases" {
for_each = rule.value.cases
iterator = case
content {
answer_data {
answer_condition = case.value.answer_data.answer_condition
should_keep = case.value.answer_data.should_keep
value = case.value.answer_data.value
}
case_condition = case.value.case_condition
count = case.value.count
}
}
default_answer_data {
answer_condition = rule.value.default_answer_data.answer_condition
should_keep = rule.value.default_answer_data.should_keep
value = rule.value.default_answer_data.value
}
default_count = rule.value.default_count
description = rule.value.description
}
}
ttl = each.value.ttl
}
resource "oci_dns_steering_policy_attachment" "these" {
for_each = local.one_dimension_dns_steering_policies
domain_name = each.value.domain_name
steering_policy_id = oci_dns_steering_policy.these[each.value.steering_policy_key].id
zone_id = oci_dns_zone.these[each.value.zone_key].id
display_name = each.value.display_name
}