Skip to content

create a map of zones #19

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions route53-zone-association/zone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Associate my Private Hosted Zone(s) (PHZ) in aws.self with a VPC in aws.peer

<!-- BEGIN_TF_DOCS -->
# About aws-vpc-setup :: route53-zone-assoication :: zone

Associate my Private Hosted Zone(s) (PHZ) in aws.self with a VPC in aws.peer

## Requirements

| Name | Version |
Expand All @@ -18,9 +23,9 @@ Associate my Private Hosted Zone(s) (PHZ) in aws.self with a VPC in aws.peer

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0.0 |
| <a name="provider_aws.peer"></a> [aws.peer](#provider\_aws.peer) | >= 4.0.0 |
| <a name="provider_aws.self"></a> [aws.self](#provider\_aws.self) | >= 4.0.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.74.0 |
| <a name="provider_aws.peer"></a> [aws.peer](#provider\_aws.peer) | 5.74.0 |
| <a name="provider_aws.self"></a> [aws.self](#provider\_aws.self) | 5.74.0 |

## Modules

Expand Down Expand Up @@ -64,3 +69,4 @@ No modules.
| Name | Description |
|------|-------------|
| <a name="output_zones"></a> [zones](#output\_zones) | Map of zone ids to zone names for PHZs |
<!-- END_TF_DOCS -->
9 changes: 5 additions & 4 deletions route53-zone-association/zone/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ locals {
"boc:tf_module_name" = lookup(local._module_names, local._module_name, local._module_names["_main_"])
"boc:created_by" = "terraform"
}
zone_ids = compact(var.zone_ids)
zone_ids = compact(var.zone_ids)
zone_ids_map = { for z in local.zone_ids : z => z }
}

resource "aws_route53_vpc_association_authorization" "self_zone" {
provider = aws.self
for_each = data.aws_caller_identity.self.account_id != data.aws_caller_identity.peer.account_id ? toset(local.zone_ids) : toset([])
for_each = data.aws_caller_identity.self.account_id != data.aws_caller_identity.peer.account_id ? local.zone_ids_map : {}
zone_id = each.key
vpc_region = var.region == null ? data.aws_region.peer.name : var.region
vpc_id = var.vpc_id
}

resource "aws_route53_zone_association" "self_zone" {
provider = aws.peer
for_each = toset(local.zone_ids)
for_each = local.zone_ids_map

zone_id = each.key
vpc_id = var.vpc_id
Expand All @@ -42,7 +43,7 @@ resource "aws_route53_zone_association" "self_zone" {
#---
data "aws_route53_zone" "zones" {
provider = aws.self
for_each = toset(local.zone_ids)
for_each = local.zone_ids_map
zone_id = each.key
private_zone = var.private_zone
}
Expand Down