Skip to content

Commit

Permalink
Merge pull request #172 from tablexi/va-add-certificate-module
Browse files Browse the repository at this point in the history
Add aws/certificate module
  • Loading branch information
vandrijevik committed Nov 12, 2020
2 parents 94c5d6b + 7fe81d9 commit fc7bfbf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
44 changes: 44 additions & 0 deletions aws/certificate/main.tf
@@ -0,0 +1,44 @@
locals {
domain_names_parts = {
for domain in var.domain_names: domain => split(".", domain)
}

zone_names = {
for domain, parts in local.domain_names_parts:
domain => join(".", length(parts) > 2 ? slice(parts, 1, length(parts)) : parts)
}
}

data "aws_route53_zone" "validation_zones" {
for_each = toset(values(local.zone_names))

name = each.value
}

resource "aws_acm_certificate" "certificate" {
domain_name = var.domain_names[0]
subject_alternative_names = slice(var.domain_names, 1, length(var.domain_names))
validation_method = "DNS"
}

resource "aws_route53_record" "validation_records" {
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 = data.aws_route53_zone.validation_zones[local.zone_names[each.key]].zone_id
}

resource "aws_acm_certificate_validation" "certificate_validation" {
certificate_arn = aws_acm_certificate.certificate.arn
validation_record_fqdns = [for record in aws_route53_record.validation_records : record.fqdn]
}
3 changes: 3 additions & 0 deletions aws/certificate/outputs.tf
@@ -0,0 +1,3 @@
output "certificate_arn" {
value = aws_acm_certificate_validation.certificate_validation.certificate_arn
}
4 changes: 4 additions & 0 deletions aws/certificate/variables.tf
@@ -0,0 +1,4 @@
variable "domain_names" {
description = "(Required) List of domain names for which the certificate should be issued. All domain names after the first one will be specified as subject alternative names."
type = list(string)
}

0 comments on commit fc7bfbf

Please sign in to comment.