Home

Awesome

AWS Certificate Manager (ACM) Terraform module

Terraform module which creates ACM certificates and validates them using Route53 DNS (recommended) or e-mail.

SWUbanner

Usage with Route53 DNS validation (recommended)

module "acm" {
  source  = "terraform-aws-modules/acm/aws"
  version = "~> 4.0"

  domain_name  = "my-domain.com"
  zone_id      = "Z2ES7B9AZ6SHAE"

  validation_method = "DNS"

  subject_alternative_names = [
    "*.my-domain.com",
    "app.sub.my-domain.com",
  ]

  wait_for_validation = true

  tags = {
    Name = "my-domain.com"
  }
}

Usage with external DNS validation (e.g. CloudFlare)

module "acm" {
  source  = "terraform-aws-modules/acm/aws"
  version = "~> 4.0"

  domain_name = "weekly.tf"
  zone_id     = "b7d259641bf30b89887c943ffc9d2138"

  validation_method = "DNS"

  subject_alternative_names = [
    "*.weekly.tf",
  ]

  create_route53_records  = false
  validation_record_fqdns = [
    "_689571ee9a5f9ec307c512c5d851e25a.weekly.tf",
  ]

  tags = {
    Name = "weekly.tf"
  }
}

Usage with CloudFront

# CloudFront supports US East (N. Virginia) Region only.
provider "aws" {
  alias  = "us-east-1"
  region = "us-east-1"
}

module "acm" {
  source = "terraform-aws-modules/acm/aws"

  providers = {
    aws = aws.us-east-1
  }

  domain_name = "my-domain.com"
  zone_id     = "Z266PL4W4W6MSG"

  validation_method = "DNS"

  wait_for_validation = true

  tags = {
    Name = "my-domain.com"
  }
}

Usage with Route53 DNS validation and separate AWS providers

provider "aws" {
  alias = "acm"
}

provider "aws" {
  alias = "route53"
}

module "acm" {
  source  = "terraform-aws-modules/acm/aws"
  version = "~> 4.0"

  providers = {
    aws = aws.acm
  }

  domain_name  = "my-domain.com"

  subject_alternative_names = [
    "*.my-domain.com",
    "app.sub.my-domain.com",
  ]

  validation_method = "DNS"

  create_route53_records  = false
  validation_record_fqdns = module.route53_records.validation_route53_record_fqdns
}

module "route53_records" {
  source  = "terraform-aws-modules/acm/aws"
  version = "~> 4.0"

  providers = {
    aws = aws.route53
  }

  create_certificate          = false
  create_route53_records_only = true

  validation_method = "DNS"

  distinct_domain_names = module.acm.distinct_domain_names
  zone_id               = "Z266PL4W4W6MSG"

  acm_certificate_domain_validation_options = module.acm.acm_certificate_domain_validation_options
}

Examples

Conditional creation and validation

Sometimes you need to have a way to create ACM certificate conditionally but Terraform does not allow to use count inside module block, so the solution is to specify argument create_certificate.

module "acm" {
  source = "terraform-aws-modules/acm/aws"

  create_certificate = false
  # ... omitted
}

Similarly, to disable DNS validation of ACM certificate:

module "acm" {
  source = "terraform-aws-modules/acm/aws"

  validate_certificate = false
  # ... omitted
}

Notes

<!-- BEGIN_TF_DOCS -->

Requirements

NameVersion
<a name="requirement_terraform"></a> terraform>= 1.0
<a name="requirement_aws"></a> aws>= 4.40

Providers

NameVersion
<a name="provider_aws"></a> aws>= 4.40

Modules

No modules.

Resources

NameType
aws_acm_certificate.thisresource
aws_acm_certificate_validation.thisresource
aws_route53_record.validationresource

Inputs

NameDescriptionTypeDefaultRequired
<a name="input_acm_certificate_domain_validation_options"></a> acm_certificate_domain_validation_optionsA list of domain_validation_options created by the ACM certificate to create required Route53 records from it (used when create_route53_records_only is set to true)any{}no
<a name="input_certificate_transparency_logging_preference"></a> certificate_transparency_logging_preferenceSpecifies whether certificate details should be added to a certificate transparency logbooltrueno
<a name="input_create_certificate"></a> create_certificateWhether to create ACM certificatebooltrueno
<a name="input_create_route53_records"></a> create_route53_recordsWhen validation is set to DNS, define whether to create the DNS records internally via Route53 or externally using any DNS providerbooltrueno
<a name="input_create_route53_records_only"></a> create_route53_records_onlyWhether to create only Route53 records (e.g. using separate AWS provider)boolfalseno
<a name="input_distinct_domain_names"></a> distinct_domain_namesList of distinct domains and SANs (used when create_route53_records_only is set to true)list(string)[]no
<a name="input_dns_ttl"></a> dns_ttlThe TTL of DNS recursive resolvers to cache information about this record.number60no
<a name="input_domain_name"></a> domain_nameA domain name for which the certificate should be issuedstring""no
<a name="input_key_algorithm"></a> key_algorithmSpecifies the algorithm of the public and private key pair that your Amazon issued certificate uses to encrypt datastringnullno
<a name="input_putin_khuylo"></a> putin_khuyloDo you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo!booltrueno
<a name="input_subject_alternative_names"></a> subject_alternative_namesA list of domains that should be SANs in the issued certificatelist(string)[]no
<a name="input_tags"></a> tagsA mapping of tags to assign to the resourcemap(string){}no
<a name="input_validate_certificate"></a> validate_certificateWhether to validate certificate by creating Route53 recordbooltrueno
<a name="input_validation_allow_overwrite_records"></a> validation_allow_overwrite_recordsWhether to allow overwrite of Route53 recordsbooltrueno
<a name="input_validation_method"></a> validation_methodWhich method to use for validation. DNS or EMAIL are valid. This parameter must not be set for certificates that were imported into ACM and then into Terraform.stringnullno
<a name="input_validation_option"></a> validation_optionThe domain name that you want ACM to use to send you validation emails. This domain name is the suffix of the email addresses that you want ACM to use.any{}no
<a name="input_validation_record_fqdns"></a> validation_record_fqdnsWhen validation is set to DNS and the DNS validation records are set externally, provide the fqdns for the validationlist(string)[]no
<a name="input_validation_timeout"></a> validation_timeoutDefine maximum timeout to wait for the validation to completestringnullno
<a name="input_wait_for_validation"></a> wait_for_validationWhether to wait for the validation to completebooltrueno
<a name="input_zone_id"></a> zone_idThe ID of the hosted zone to contain this record. Required when validating via Route53string""no
<a name="input_zones"></a> zonesMap containing the Route53 Zone IDs for additional domains.map(string){}no

Outputs

NameDescription
<a name="output_acm_certificate_arn"></a> acm_certificate_arnThe ARN of the certificate
<a name="output_acm_certificate_domain_validation_options"></a> acm_certificate_domain_validation_optionsA list of attributes to feed into other resources to complete certificate validation. Can have more than one element, e.g. if SANs are defined. Only set if DNS-validation was used.
<a name="output_acm_certificate_status"></a> acm_certificate_statusStatus of the certificate.
<a name="output_acm_certificate_validation_emails"></a> acm_certificate_validation_emailsA list of addresses that received a validation E-Mail. Only set if EMAIL-validation was used.
<a name="output_distinct_domain_names"></a> distinct_domain_namesList of distinct domains names used for the validation.
<a name="output_validation_domains"></a> validation_domainsList of distinct domain validation options. This is useful if subject alternative names contain wildcards.
<a name="output_validation_route53_record_fqdns"></a> validation_route53_record_fqdnsList of FQDNs built using the zone domain and name.
<!-- END_TF_DOCS -->

Authors

Module is maintained by Anton Babenko with help from these awesome contributors.

License

Apache 2 Licensed. See LICENSE for full details.

Additional information for users from Russia and Belarus