-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Richard Onyon
authored and
Richard Onyon
committed
Feb 13, 2022
0 parents
commit 9704172
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Terraform Create AWS ACM Certificate For Multiple Domains | ||
|
||
The [Terraform documentation for `acm_certificate_validation`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate_validation) | ||
only supports a single domain in the request. This module allows you to support multiple | ||
domains in the request as long as they are the APEX or *.APEX domain. This will | ||
reduce code complexity and cost by allowing you to have a single certificate | ||
with more domains. | ||
|
||
``` | ||
resource "aws_acm_certificate" "certificate" { | ||
domain_name = "mydomain.dev" | ||
validation_method = "DNS" | ||
subject_alternative_names = [ | ||
"*.mydomain.dev", | ||
"myseconddomain.co", | ||
"*.myseconddomain.co", | ||
"*.mythirddomain.co.uk" | ||
] | ||
} | ||
module "acm-r53-records" { | ||
for_each = {for domain in aws_acm_certificate.certificate.domain_validation_options: domain.domain_name => domain} | ||
source = "github.com/cebollia/terraform-aws-acm-multiple-domains" | ||
certificate_arn = aws_acm_certificate.certificate.arn | ||
domain = each.key | ||
name = each.value.resource_record_name | ||
type = each.value.resource_record_type | ||
record = each.value.resource_record_value | ||
ttl = 3600 | ||
} | ||
resource "aws_acm_certificate_validation" "validate" { | ||
certificate_arn = aws_acm_certificate.certificate.arn | ||
validation_record_fqdns = [for domain in module.acm-r53-records : domain.record.fqdn ] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
data "aws_route53_zone" "domain" { | ||
name = local.domain | ||
private_zone = false | ||
} | ||
|
||
resource "aws_route53_record" "tls-entry" { | ||
allow_overwrite = true | ||
name = local.name | ||
records = [local.record] | ||
ttl = local.ttl | ||
type = local.type | ||
zone_id = data.aws_route53_zone.domain.zone_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "record" { | ||
value = aws_route53_record.tls-entry | ||
sensitive = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
variable "certificate_arn" {} | ||
variable "domain" {} | ||
variable "name" {} | ||
variable "type" {} | ||
variable "record" {} | ||
variable "ttl" {} | ||
|
||
locals { | ||
certificate_arn = var.certificate_arn | ||
domain = replace(var.domain,"*.","") | ||
name = var.name | ||
type = var.type | ||
record = var.record | ||
ttl = var.ttl | ||
} |