Commit c4d01fc7 authored by Nicholas Henry's avatar Nicholas Henry Committed by GitHub

feat: Add support for multiple VPCs when creating private hosted zones (#27)

parent 72f4d3a2
...@@ -22,9 +22,14 @@ module "zones" { ...@@ -22,9 +22,14 @@ module "zones" {
"private-vpc.terraform-aws-modules-example.com" = { "private-vpc.terraform-aws-modules-example.com" = {
comment = "private-vpc.terraform-aws-modules-example.com" comment = "private-vpc.terraform-aws-modules-example.com"
vpc = { vpc = [
{
vpc_id = module.vpc.vpc_id vpc_id = module.vpc.vpc_id
} },
{
vpc_id = module.vpc2.vpc_id
},
]
tags = { tags = {
Name = "private-vpc.terraform-aws-modules-example.com" Name = "private-vpc.terraform-aws-modules-example.com"
} }
...@@ -141,3 +146,10 @@ module "vpc" { ...@@ -141,3 +146,10 @@ module "vpc" {
name = "my-vpc-for-private-route53-zone" name = "my-vpc-for-private-route53-zone"
cidr = "10.0.0.0/16" cidr = "10.0.0.0/16"
} }
module "vpc2" {
source = "terraform-aws-modules/vpc/aws"
name = "my-second-vpc-for-private-route53-zone"
cidr = "10.1.0.0/16"
}
# zones
output "this_route53_zone_zone_id" {
description = "Zone ID of Route53 zone"
value = module.zones.this_route53_zone_zone_id
}
output "this_route53_zone_name_servers" {
description = "Name servers of Route53 zone"
value = module.zones.this_route53_zone_name_servers
}
output "this_route53_zone_name" {
description = "Name of Route53 zone"
value = module.zones.this_route53_zone_name
}
# records
output "this_route53_record_name" { output "this_route53_record_name" {
description = "The name of the record" description = "The name of the record"
value = module.records.this_route53_record_name value = module.records.this_route53_record_name
......
...@@ -6,7 +6,7 @@ resource "aws_route53_zone" "this" { ...@@ -6,7 +6,7 @@ resource "aws_route53_zone" "this" {
force_destroy = lookup(each.value, "force_destroy", false) force_destroy = lookup(each.value, "force_destroy", false)
dynamic "vpc" { dynamic "vpc" {
for_each = length(keys(lookup(each.value, "vpc", {}))) == 0 ? [] : [lookup(each.value, "vpc", {})] for_each = try(tolist(lookup(each.value, "vpc", [])), [lookup(each.value, "vpc", {})])
content { content {
vpc_id = vpc.value.vpc_id vpc_id = vpc.value.vpc_id
......
...@@ -7,3 +7,8 @@ output "this_route53_zone_name_servers" { ...@@ -7,3 +7,8 @@ output "this_route53_zone_name_servers" {
description = "Name servers of Route53 zone" description = "Name servers of Route53 zone"
value = { for k, v in aws_route53_zone.this : k => v.name_servers } value = { for k, v in aws_route53_zone.this : k => v.name_servers }
} }
output "this_route53_zone_name" {
description = "Name of Route53 zone"
value = { for k, v in aws_route53_zone.this : k => v.name }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment