diff --git a/docs/examples/main.tf b/docs/examples/main.tf index c5375db..b5d96b6 100644 --- a/docs/examples/main.tf +++ b/docs/examples/main.tf @@ -14,15 +14,15 @@ module "peterdotcloud_vpc" { module "peterdotcloud_website" { source = "TechToSpeech/serverless-static-wordpress/aws" version = "0.1.2" - main_vpc_id = "vpc-e121c09b" - subnet_ids = ["subnet-04b97235", "subnet-08fb235", "subnet-04b97734"] + main_vpc_id = module.peterdotcloud_vpc.main_vpc_id + subnet_ids = tolist(module.peterdotcloud_vpc.subnet_ids) aws_account_id = data.aws_caller_identity.current.account_id # site_name will be used to prepend resource names - use no spaces or special characters site_name = local.site_name site_domain = local.site_domain wordpress_subdomain = "wordpress" - hosted_zone_id = "Z00437553UWAVIRHANGCN" + hosted_zone_id = aws_route53_zone.apex.id s3_region = local.aws_region slack_webhook = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX" ecs_cpu = 1024 @@ -47,7 +47,7 @@ module "docker_pullpush" { aws_account_id = data.aws_caller_identity.current.account_id aws_region = local.aws_region docker_source = "wordpress:php7.4-apache" - aws_profile = "peterdotcloud" + aws_profile = local.profile ecr_repo_name = module.peterdotcloud_website.wordpress_ecr_repository ecr_repo_tag = "base" depends_on = [module.peterdotcloud_website] @@ -80,7 +80,7 @@ resource "null_resource" "update_nameservers" { nameservers = aws_route53_zone.apex.id } provisioner "local-exec" { - command = "aws route53domains update-domain-nameservers --region us-east-1 --domain-name ${local.site_domain} --nameservers Name=${aws_route53_zone.apex.name_servers.0} Name=${aws_route53_zone.apex.name_servers.1} Name=${aws_route53_zone.apex.name_servers.2} Name=${aws_route53_zone.apex.name_servers.3} --profile peterdotcloud" + command = "aws route53domains update-domain-nameservers --region us-east-1 --domain-name ${local.site_domain} --nameservers Name=${aws_route53_zone.apex.name_servers.0} Name=${aws_route53_zone.apex.name_servers.1} Name=${aws_route53_zone.apex.name_servers.2} Name=${aws_route53_zone.apex.name_servers.3} --profile ${local.profile}" } depends_on = [aws_route53_zone.apex] } diff --git a/docs/examples/vpc_setup/vpc.tf b/docs/examples/vpc_setup/vpc.tf index d42ae59..4723032 100644 --- a/docs/examples/vpc_setup/vpc.tf +++ b/docs/examples/vpc_setup/vpc.tf @@ -89,14 +89,14 @@ resource "aws_route_table" "main_private" { } resource "aws_route_table_association" "main_subnets_public" { - count = length(data.aws_subnet_ids.main_public.ids) - subnet_id = tolist(data.aws_subnet_ids.main_public.ids)[count.index] + count = length(data.aws_subnet_ids.main_public) > 0 ? length(data.aws_subnet_ids.main_public) : 0 + subnet_id = element(aws_subnet.main_public.*.id, count.index) route_table_id = aws_route_table.main_public.id } resource "aws_route_table_association" "main_subnets_private" { - count = length(data.aws_subnet_ids.main_private.ids) - subnet_id = tolist(data.aws_subnet_ids.main_private.ids)[count.index] + count = length(data.aws_subnet_ids.main_private) > 0 ? length(data.aws_subnet_ids.main_private) : 0 + subnet_id = element(aws_subnet.main_private.*.id, count.index) route_table_id = aws_route_table.main_private.id } diff --git a/r53.tf b/r53.tf index bc15ba9..a6e1006 100644 --- a/r53.tf +++ b/r53.tf @@ -1,14 +1,15 @@ resource "aws_route53_record" "www" { + count = var.site_prefix == "www" ? 0 : 1 zone_id = var.hosted_zone_id - name = "www" + name = "www.${var.site_prefix}.${var.site_domain}" type = "CNAME" ttl = "600" - records = [var.site_domain] + records = ["${var.site_prefix}${var.site_prefix == "" ? "" : "."}${var.site_domain}"] } resource "aws_route53_record" "apex" { zone_id = var.hosted_zone_id - name = var.site_domain + name = "${var.site_prefix}${var.site_prefix == "" ? "" : "."}${var.site_domain}" type = "A" alias { name = module.cloudfront.wordpress_cloudfront_distribution_domain_name @@ -16,3 +17,14 @@ resource "aws_route53_record" "apex" { evaluate_target_health = false } } + +resource "aws_route53_record" "apex_aaaa" { + zone_id = var.hosted_zone_id + name = "${var.site_prefix}${var.site_prefix == "" ? "" : "."}${var.site_domain}" + type = "AAAA" + alias { + name = module.cloudfront.wordpress_cloudfront_distribution_domain_name + zone_id = module.cloudfront.wordpress_cloudfront_distrubtion_hostedzone_id + evaluate_target_health = false + } +}