Skip to content

Commit 3728289

Browse files
committed
ACM validation
1 parent 13256df commit 3728289

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

static-site/acm.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ resource "aws_acm_certificate" "cloudfront_cert" {
33
validation_method = "DNS"
44
tags = var.tags
55
provider = aws.acm
6+
}
7+
8+
resource "aws_acm_certificate_validation" "cert_validation" {
9+
certificate_arn = aws_acm_certificate.cloudfront_cert.arn
10+
validation_record_fqdns = [for record in data.hosted_zone : record.fqdn]
611
}

static-site/data.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ data "aws_iam_policy_document" "deploy_web" {
6060
}
6161
}
6262

63+
data "aws_route53_zone" "hosted_zone" {
64+
name = var.domain_name
65+
}
66+
6367
data "aws_iam_openid_connect_provider" "github" {
6468
url = "https://token.actions.githubusercontent.com"
6569
}

static-site/route53.tf

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1+
#############################################
2+
# Validation for the ACM cert
3+
#############################################
4+
5+
resource "aws_route53_record" "acm_records" {
6+
for_each = {
7+
for dvo in aws_acm_certificate.aws_acm_certificate.cloudfront_cert.domain_validation_options : dvo.domain_name => {
8+
name = dvo.resource_record_name
9+
record = dvo.resource_record_value
10+
type = dvo.resource_record_type
11+
}
12+
}
13+
14+
allow_overwrite = true
15+
name = each.value.name
16+
records = [each.value.record]
17+
ttl = 60
18+
type = each.value.type
19+
zone_id = data.aws_route53_zone.hosted_zone.zone_id
20+
}
21+
122
#############################################
223
# Setup the A record for your custom domain
324
#############################################
425

526
resource "aws_route53_record" "static_site_a_record" {
6-
zone_id = var.hosted_zone_id
27+
zone_id = data.aws_route53_zone.hosted_zone.zone_id
728
name = var.domain_name
829
type = "A"
930

static-site/variables.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ variable "bucket_name" {
33
description = "The name of the bucket which will hold your static site"
44
}
55

6-
variable "hosted_zone_id" {
7-
type = string
8-
description = "The hosted zone ID to attach the A record for your custom domain"
9-
}
10-
116
variable "domain_name" {
127
type = string
138
description = "The custom domain for your CloudFront distribution"

0 commit comments

Comments
 (0)