-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from Binsabbar/v2.12.0-dev
V2.12.0 dev
- Loading branch information
Showing
13 changed files
with
433 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,131 @@ | ||
resource "oci_dns_zone" "dns_zone" { | ||
for_each = var.zones | ||
name = each.value.name | ||
compartment_id = var.compartment_id | ||
zone_type = var.zone_type | ||
view_id = var.view_id | ||
scope = var.scope | ||
### Private Custom Views Zones | ||
locals { | ||
private_dns_zones_custom_views = flatten([ | ||
for v_key, view in var.private_dns.custom_views : [ | ||
for z_key, zone in view.zones : { | ||
item_key = "${v_key}-${z_key}" | ||
view_key = v_key | ||
zone_name = zone.zone_name | ||
compartment_id = view.compartment_id | ||
} | ||
] | ||
]) | ||
|
||
private_dns_records_custom_views = flatten([ | ||
for v_key, view in var.private_dns.custom_views : [ | ||
for z_key, zone in view.zones : [ | ||
for r_key, record in zone.records : { | ||
item_key = "${v_key}-${z_key}-${r_key}" | ||
zone_key = "${v_key}-${z_key}" | ||
domain_name = record.domain_name | ||
rdata = record.rdata | ||
rtype = record.rtype | ||
ttl = record.ttl | ||
} | ||
] | ||
] | ||
]) | ||
} | ||
|
||
resource "oci_dns_view" "custom_view" { | ||
for_each = var.private_dns.custom_views | ||
|
||
display_name = each.value.view_name | ||
compartment_id = each.value.compartment_id | ||
scope = "PRIVATE" | ||
} | ||
|
||
resource "oci_dns_zone" "private_dns_zone_custom_view" { | ||
for_each = { for _, item in local.private_dns_zones_custom_views : "${item.item_key}" => item } | ||
|
||
name = each.value.zone_name | ||
compartment_id = each.value.compartment_id | ||
zone_type = "PRIMARY" | ||
view_id = oci_dns_view.custom_view[each.value.view_key].id | ||
scope = "PRIVATE" | ||
} | ||
|
||
resource "oci_dns_rrset" "dns_rrset_custom_view" { | ||
for_each = { for _, item in local.private_dns_records_custom_views : "${item.item_key}" => item } | ||
|
||
domain = each.value.domain_name | ||
rtype = each.value.rtype | ||
zone_name_or_id = oci_dns_zone.private_dns_zone_custom_view[each.value.zone_key].id | ||
|
||
items { | ||
domain = each.value.domain_name | ||
rdata = each.value.rdata | ||
rtype = each.value.rtype | ||
ttl = each.value.ttl | ||
} | ||
} | ||
|
||
### Private Protected Views Zones | ||
locals { | ||
private_dns_zones_protected_veiws = flatten([ | ||
for v_key, view in var.private_dns.protected_views : [ | ||
for z_key, zone in view.zones : { | ||
item_key = "${v_key}-${z_key}" | ||
view_id = view.view_id | ||
zone_name = zone.zone_name | ||
compartment_id = view.compartment_id | ||
} | ||
] | ||
]) | ||
|
||
private_dns_records_protected_veiws = flatten([ | ||
for v_key, view in var.private_dns.protected_views : [ | ||
for z_key, zone in view.zones : [ | ||
for r_key, record in zone.records : { | ||
item_key = "${v_key}-${z_key}-${r_key}" | ||
zone_key = "${v_key}-${z_key}" | ||
domain_name = record.domain_name | ||
rdata = record.rdata | ||
rtype = record.rtype | ||
ttl = record.ttl | ||
view_id = view.view_id | ||
} | ||
] | ||
] | ||
]) | ||
} | ||
|
||
resource "oci_dns_rrset" "dns_rrset" { | ||
for_each = var.records | ||
data "oci_dns_view" "protected_view" { | ||
for_each = { for _, item in var.private_dns.protected_views : item.view_id => item } | ||
|
||
view_id = each.value.view_id | ||
scope = "PRIVATE" | ||
} | ||
|
||
resource "oci_dns_zone" "private_dns_zone_protected_view" { | ||
for_each = { for _, item in local.private_dns_zones_protected_veiws : "${item.item_key}" => item } | ||
|
||
name = each.value.zone_name | ||
compartment_id = each.value.compartment_id | ||
view_id = each.value.view_id | ||
|
||
zone_type = "PRIMARY" | ||
scope = "PRIVATE" | ||
|
||
lifecycle { | ||
precondition { | ||
condition = data.oci_dns_view.protected_view[each.value.view_id].is_protected | ||
error_message = "ERROR: view ${each.value.view_id} is not protected, only protected view ids are allowed in private_dns.protected_views input" | ||
} | ||
} | ||
} | ||
|
||
resource "oci_dns_rrset" "dns_rrset_protected_view" { | ||
for_each = { for _, item in local.private_dns_records_protected_veiws : "${item.item_key}" => item } | ||
|
||
domain = each.value.domain_name | ||
rtype = each.value.rtype | ||
zone_name_or_id = each.value.zone_name | ||
compartment_id = var.compartment_id | ||
view_id = var.view_id | ||
scope = var.scope | ||
zone_name_or_id = oci_dns_zone.private_dns_zone_protected_view[each.value.zone_key].id | ||
|
||
items { | ||
domain = each.value.domain_name | ||
rdata = each.value.rdata | ||
rtype = each.value.rtype | ||
ttl = each.value.ttl | ||
} | ||
depends_on = [ | ||
oci_dns_zone.dns_zone | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,44 @@ | ||
output "dns_record" { | ||
value = { for items, value in oci_dns_rrset.dns_rrset : | ||
items => value | ||
output "dns_configuration" { | ||
description = "Hierarchical structure of DNS views, their zones, and records" | ||
value = { | ||
protected_views = { | ||
for view_key, view in data.oci_dns_view.protected_view : "${view.display_name}" => { | ||
name = view.display_name | ||
compartment_id = view.compartment_id | ||
id = view_key | ||
zones = { | ||
for zone_key, zone in oci_dns_zone.private_dns_zone_protected_view : "${zone.name}" => { | ||
name = zone.name | ||
compartment_id = zone.compartment_id | ||
id = zone.id | ||
records = { | ||
for record_key, record in oci_dns_rrset.dns_rrset_protected_view : "${record.domain}" => { | ||
items = record.items | ||
} if record.zone_name_or_id == zone.id | ||
} | ||
} if zone.view_id == view_key | ||
} | ||
} | ||
} | ||
|
||
custom_views = { | ||
for view_key, view in oci_dns_view.custom_view : "${view.display_name}" => { | ||
name = view.display_name | ||
compartment_id = view.compartment_id | ||
id = view.id | ||
zones = { | ||
for zone_key, zone in oci_dns_zone.private_dns_zone_custom_view : "${zone.name}" => { | ||
name = zone.name | ||
compartment_id = zone.compartment_id | ||
id = zone.id | ||
records = { | ||
for record_key, record in oci_dns_rrset.dns_rrset_custom_view : "${record.domain}" => { | ||
items = record.items | ||
} if record.zone_name_or_id == zone.id | ||
} | ||
} if zone.view_id == view.id | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.