Skip to content

Commit

Permalink
allow for zone list
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Mar 28, 2023
1 parent 378f550 commit 19d7f43
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
7 changes: 6 additions & 1 deletion route53-zone-association/vpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ No modules.
| Name | Type |
|------|------|
| [aws_route53_vpc_association_authorization.peer_zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_vpc_association_authorization) | resource |
| [aws_route53_vpc_association_authorization.peer_zones](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_vpc_association_authorization) | resource |
| [aws_route53_zone_association.peer_zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone_association) | resource |
| [aws_route53_zone_association.peer_zones](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone_association) | resource |
| [aws_arn.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
| [aws_arn.peer](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
| [aws_arn.self](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
Expand All @@ -44,6 +46,7 @@ No modules.
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
| [aws_region.peer](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
| [aws_region.self](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
| [aws_route53_zone.zones](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source |

## Inputs

Expand All @@ -52,9 +55,11 @@ No modules.
| <a name="input_account_alias"></a> [account\_alias](#input\_account\_alias) | AWS Account Alias (default: will pull from current account\_alias) | `string` | `""` | no |
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | AWS Account ID (default: will pull from current user) | `string` | `""` | no |
| <a name="input_override_prefixes"></a> [override\_prefixes](#input\_override\_prefixes) | Override built-in prefixes by component. This should be used primarily for common infrastructure things | `map(string)` | `{}` | no |
| <a name="input_private_zone"></a> [private\_zone](#input\_private\_zone) | Selection either private or public (default: private) for named zones | `bool` | `true` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | AWS Tags to apply to appropriate resources (S3, KMS). Do not include safeguard tags here, use the data\_safeguard field for such things. | `map(string)` | `{}` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC ID with which to associate Route53 PHZs | `string` | n/a | yes |
| <a name="input_zone_ids"></a> [zone\_ids](#input\_zone\_ids) | List of Route53 PHZs to associate with a (local/remote) VPC | `list(string)` | `[]` | no |
| <a name="input_zone_ids"></a> [zone\_ids](#input\_zone\_ids) | List of Route53 PHZ IDs to associate with a (local/remote) VPC | `list(string)` | `[]` | no |
| <a name="input_zones"></a> [zones](#input\_zones) | List of Route53 PHZs to associate with a (local/remote) VPC | `list(string)` | `[]` | no |

## Outputs

Expand Down
35 changes: 35 additions & 0 deletions route53-zone-association/vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ locals {
}
}

#---
# zone ids
#---
resource "aws_route53_vpc_association_authorization" "peer_zone" {
provider = aws.peer
for_each = data.aws_caller_identity.self.account_id != data.aws_caller_identity.peer.account_id ? toset(var.zone_ids) : toset([])
Expand All @@ -35,3 +38,35 @@ resource "aws_route53_zone_association" "peer_zone" {

depends_on = [aws_route53_vpc_association_authorization.peer_zone]
}

#---
# zone list
#---
data "aws_route53_zone" "zones" {
for_each = toset(var.zones)
name = each.key
private_zone = var.private_zone
}

locals {
zones_ids = [for k, v in data.aws_route53_zone.zones : v.zone_id]
}

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

resource "aws_route53_zone_association" "peer_zones" {
provider = aws.self
for_each = toset(var.zones_ids)

zone_id = each.key
vpc_id = var.vpc_id
vpc_region = data.aws_region.self.name

depends_on = [aws_route53_vpc_association_authorization.peer_zones]
}
13 changes: 12 additions & 1 deletion route53-zone-association/vpc/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "zone_ids" {
description = "List of Route53 PHZs to associate with a (local/remote) VPC"
description = "List of Route53 PHZ IDs to associate with a (local/remote) VPC"
type = list(string)
default = []
}
Expand All @@ -9,3 +9,14 @@ variable "vpc_id" {
type = string
}

variable "zones" {
description = "List of Route53 PHZs to associate with a (local/remote) VPC"
type = list(string)
default = []
}

variable "private_zone" {
description = "Selection either private or public (default: private) for named zones"
type = bool
default = true
}
2 changes: 1 addition & 1 deletion route53-zone-association/zone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ No modules.
| <a name="input_override_prefixes"></a> [override\_prefixes](#input\_override\_prefixes) | Override built-in prefixes by component. This should be used primarily for common infrastructure things | `map(string)` | `{}` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | AWS Tags to apply to appropriate resources (S3, KMS). Do not include safeguard tags here, use the data\_safeguard field for such things. | `map(string)` | `{}` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC ID with which to associate Route53 PHZs | `string` | n/a | yes |
| <a name="input_zone_ids"></a> [zone\_ids](#input\_zone\_ids) | List of Route53 PHZs to associate with a (local/remote) VPC | `list(string)` | `[]` | no |
| <a name="input_zone_ids"></a> [zone\_ids](#input\_zone\_ids) | List of Route53 PHZ IDs to associate with a (local/remote) VPC | `list(string)` | `[]` | no |

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion route53-zone-association/zone/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "zone_ids" {
description = "List of Route53 PHZs to associate with a (local/remote) VPC"
description = "List of Route53 PHZ IDs to associate with a (local/remote) VPC"
type = list(string)
default = []
}
Expand Down

0 comments on commit 19d7f43

Please sign in to comment.