Skip to content

Commit d507a23

Browse files
committed
fix: custom domain dns validation without manual intervention
1 parent d1f2fe7 commit d507a23

File tree

6 files changed

+38
-66
lines changed

6 files changed

+38
-66
lines changed

.DS_Store

6 KB
Binary file not shown.

examples/.DS_Store

6 KB
Binary file not shown.

examples/complete/main.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,12 @@ module "app_runner_image_base" {
126126
}
127127
}
128128

129-
# # Requires manual intervention to validate records
130-
# # https://github.com/hashicorp/terraform-provider-aws/issues/23460
131-
# create_custom_domain_association = true
132-
# hosted_zone_id = "<TODO>"
133-
# domain_name = "<TODO>"
134-
# enable_www_subdomain = true
135-
129+
# Create a custom domain
130+
create_custom_domain_association = true
131+
enable_www_subdomain = false
132+
hosted_zone_id = var.hosted_zone_id
133+
domain_name = "*.app.example.com"
134+
136135
create_vpc_connector = true
137136
vpc_connector_subnets = module.vpc.private_subnets
138137
vpc_connector_security_groups = [module.security_group.security_group_id]

examples/complete/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ variable "repository_url" {
33
type = string
44
default = "https://github.com/aws-containers/hello-app-runner" # clone to your account associated with the GitHub connection
55
}
6+
7+
variable "hosted_zone_id" {
8+
description = "The Route53 zone ID where the validation records for the custom domain will be created"
9+
type = string
10+
default = "Z0975817WMT8ITN8W25F"
11+
}

main.tf

Lines changed: 21 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -433,60 +433,27 @@ resource "aws_apprunner_custom_domain_association" "this" {
433433
service_arn = aws_apprunner_service.this[0].arn
434434
}
435435

436-
# # Requires manual intervention to validate records
437-
# # https://github.com/hashicorp/terraform-provider-aws/issues/23460
438-
# resource "aws_route53_record" "validation" {
439-
# count = length(aws_apprunner_custom_domain_association.this[0].certificate_validation_records)
440-
441-
# allow_overwrite = true
442-
# name = aws_apprunner_custom_domain_association.this[0].certificate_validation_records.*.name[count.index]
443-
# records = [aws_apprunner_custom_domain_association.this[0].certificate_validation_records.*.value[count.index]]
444-
# ttl = 60
445-
# type = aws_apprunner_custom_domain_association.this[0].certificate_validation_records.*.type[count.index]
446-
# zone_id = var.hosted_zone_id
447-
# }
448-
449-
# resource "aws_route53_record" "validation" {
450-
# for_each = {
451-
# for dvo in aws_apprunner_custom_domain_association.this[0].certificate_validation_records : dvo.name => {
452-
# name = dvo.name
453-
# record = dvo.value
454-
# type = dvo.type
455-
# } if local.create_custom_domain_association
456-
# }
457-
458-
# allow_overwrite = true
459-
# name = each.value.name
460-
# records = [each.value.record]
461-
# ttl = 60
462-
# type = each.value.type
463-
# zone_id = var.hosted_zone_id
464-
# }
465-
466-
# resource "aws_route53_record" "cname" {
467-
# count = local.create_custom_domain_association && var.domain_name_use_cname ? 1 : 0
468-
469-
# allow_overwrite = true
470-
# name = var.domain_name
471-
# records = [aws_apprunner_custom_domain_association.this[0].dns_target]
472-
# ttl = 3600
473-
# type = "CNAME"
474-
# zone_id = var.hosted_zone_id
475-
# }
476-
477-
# resource "aws_route53_record" "alias" {
478-
# for_each = { for k, v in toset(["A", "AAAA"]) : k => v if local.create_custom_domain_association && var.domain_name_use_cname }
479-
480-
# zone_id = var.hosted_zone_id
481-
# name = var.domain_name
482-
# type = each.value
483-
484-
# alias {
485-
# name = aws_apprunner_service.this[0].service_url
486-
# zone_id = <TODO> ???
487-
# evaluate_target_health = true
488-
# }
489-
# }
436+
locals {
437+
validation_records = tolist(aws_apprunner_custom_domain_association.this[0].certificate_validation_records)
438+
}
439+
440+
resource "aws_route53_record" "validation_records" {
441+
count = length([var.domain_name]) + 1
442+
name = local.validation_records[count.index].name
443+
type = local.validation_records[count.index].type
444+
records = [local.validation_records[count.index].value]
445+
allow_overwrite = true
446+
ttl = 300
447+
zone_id = var.hosted_zone_id
448+
}
449+
450+
resource "aws_route53_record" "custom_domain" {
451+
name = aws_apprunner_custom_domain_association.this[0].domain_name
452+
type = "CNAME"
453+
records = [aws_apprunner_service.this[0].service_url]
454+
ttl = 300
455+
zone_id = var.hosted_zone_id
456+
}
490457

491458
################################################################################
492459
# VPC Connector

variables.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ variable "enable_www_subdomain" {
220220
default = null
221221
}
222222

223-
# variable "hosted_zone_id" {
224-
# description = "The ID of the Route53 hosted zone that contains the domain for the `domain_name`"
225-
# type = string
226-
# default = ""
227-
# }
223+
variable "hosted_zone_id" {
224+
description = "The ID of the Route53 hosted zone that contains the domain for the `domain_name`"
225+
type = string
226+
default = ""
227+
}
228228

229229
################################################################################
230230
# VPC Connector

0 commit comments

Comments
 (0)