Skip to content

Instantly share code, notes, and snippets.

@wlonkly
Created February 10, 2020 20:19
Show Gist options
  • Save wlonkly/3afd886bcbe746387976dfa41122b45d to your computer and use it in GitHub Desktop.
Save wlonkly/3afd886bcbe746387976dfa41122b45d to your computer and use it in GitHub Desktop.
Manual vs. module-ized ACM certificates in terraform
data "aws_route53_zone" "alias_zone" {
name = "example.com"
private_zone = false
}
resource "aws_acm_certificate" "certificate" {
domain_name = "example.com"
validation_method = "DNS"
tags = { some list of tags }
lifecycle {
create_before_destroy = true
}
}
resource "aws_route53_record" "cert_validation" {
name = aws_acm_certificate.certificate.domain_validation_options.0.resource_record_name
type = aws_acm_certificate.certificate.domain_validation_options.0.resource_record_type
zone_id = data.aws_route53_zone.zone.id
records = [aws_acm_certificate.certificate.domain_validation_options.0.resource_record_value]
ttl = 60
}
resource "aws_acm_certificate_validation" "cert" {
certificate_arn = aws_acm_certificate.certificate.arn
validation_record_fqdns = [aws_route53_record.cert_validation.fqdn]
}
module "acm_certificate" {
source = "../acm_certificate/"
domain_name = "example.com"
tags = { some list of tags }
}
@wlonkly
Copy link
Author

wlonkly commented Feb 10, 2020

Oversimplification, but the intent was to let people write what's in "module.tf" instead of having to basically cut and paste all the DNS boilerplate that's in "manual.tf".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment