Skip to content

Instantly share code, notes, and snippets.

@refayathaque
Last active March 21, 2021 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refayathaque/a32185d30798405e8a5f046348886767 to your computer and use it in GitHub Desktop.
Save refayathaque/a32185d30798405e8a5f046348886767 to your computer and use it in GitHub Desktop.
Part of "Automate hosting a static website on AWS with Terraform" post
resource "aws_route53_zone" "primary" {
name = var.DOMAIN_NAME
}
resource "aws_route53_record" "certificate_validation" {
for_each = {
for dvo in aws_acm_certificate.certificate.domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
type = dvo.resource_record_type
}
}
allow_overwrite = true
name = each.value.name
records = [each.value.record]
ttl = 60
type = each.value.type
zone_id = aws_route53_zone.primary.zone_id
}
resource "aws_route53_record" "cloudfront" {
zone_id = aws_route53_zone.primary.zone_id
name = var.DOMAIN_NAME
type = "A"
alias {
name = aws_cloudfront_distribution.distribution.domain_name
zone_id = aws_cloudfront_distribution.distribution.hosted_zone_id
evaluate_target_health = false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment