Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use site_prefix in DNS entries #68

Open
wants to merge 2 commits into
base: release/0.2.0
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions docs/examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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]
}
8 changes: 4 additions & 4 deletions docs/examples/vpc_setup/vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 15 additions & 3 deletions r53.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
resource "aws_route53_record" "www" {
count = var.site_prefix == "www" ? 0 : 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the prefix is www, we shouldn't create www.www.example.com.

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
zone_id = module.cloudfront.wordpress_cloudfront_distrubtion_hostedzone_id
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"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create AAAA record for ipv6 support

alias {
name = module.cloudfront.wordpress_cloudfront_distribution_domain_name
zone_id = module.cloudfront.wordpress_cloudfront_distrubtion_hostedzone_id
evaluate_target_health = false
}
}