Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Onyon authored and Richard Onyon committed Feb 13, 2022
0 parents commit 9704172
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
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 ]
}
```
13 changes: 13 additions & 0 deletions main.tf
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
}
4 changes: 4 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "record" {
value = aws_route53_record.tls-entry
sensitive = false
}
15 changes: 15 additions & 0 deletions variables.tf
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
}

0 comments on commit 9704172

Please sign in to comment.