The ACM certificate resource allows requesting and management of certificates from the Amazon Certificate Manager.
ACM certificates can be created in three ways: Amazon-issued, where AWS provides the certificate authority and automatically manages renewal; imported certificates, issued by another certificate authority; and private certificates, issued using an ACM Private Certificate Authority.
For Amazon-issued certificates, this resource deals with requesting certificates and managing their attributes and life-cycle.
This resource does not deal with validation of a certificate but can provide inputs
for other resources implementing the validation.
It does not wait for a certificate to be issued.
Use a aws_acm_certificate_validation
resource for this.
Most commonly, this resource is used together with aws_route53_record
and
aws_acm_certificate_validation
to request a DNS validated certificate,
deploy the required validation records and wait for validation to complete.
Domain validation through email is also supported but should be avoided as it requires a manual step outside of Terraform.
It's recommended to specify create_before_destroy = true
in a lifecycle block to replace a certificate
which is currently in use (eg, by aws_lb_listener
).
Imported certificates can be used to make certificates created with an external certificate authority available for AWS services.
As they are not managed by AWS, imported certificates are not eligible for automatic renewal. New certificate materials can be supplied to an existing imported certificate to update it in place.
Private certificates are issued by an ACM Private Cerificate Authority, which can be created using the resource type aws_acmpca_certificate_authority
.
Private certificates created using this resource are eligible for managed renewal if they have been exported or associated with another AWS service.
See managed renewal documentation for more information.
By default, a certificate is valid for 395 days and the managed renewal process will start 60 days before expiration.
To renew the certificate earlier than 60 days before expiration, configure early_renewal_duration
.
resource "aws_acm_certificate" "cert" {
domain_name = "example.com"
validation_method = "DNS"
tags = {
Environment = "test"
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_acm_certificate" "cert" {
domain_name = "testing.example.com"
validation_method = "EMAIL"
validation_option {
domain_name = "testing.example.com"
validation_domain = "example.com"
}
}
resource "tls_private_key" "example" {
algorithm = "RSA"
}
resource "tls_self_signed_cert" "example" {
key_algorithm = "RSA"
private_key_pem = tls_private_key.example.private_key_pem
subject {
common_name = "example.com"
organization = "ACME Examples, Inc"
}
validity_period_hours = 12
allowed_uses = [
"key_encipherment",
"digital_signature",
"server_auth",
]
}
resource "aws_acm_certificate" "cert" {
private_key = tls_private_key.example.private_key_pem
certificate_body = tls_self_signed_cert.example.cert_pem
}
See the aws_acm_certificate_validation
resource for a full example of performing DNS validation.
resource "aws_route53_record" "example" {
for_each = {
for dvo in aws_acm_certificate.example.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 = aws_route53_zone.example.zone_id
}
This resource supports the following arguments:
domain_name
- (Required) Domain name for which the certificate should be issuedsubject_alternative_names
- (Optional) Set of domains that should be SANs in the issued certificate. To remove all elements of a previously configured list, set this value equal to an empty list ([]
) or use the terraform taint
command to trigger recreation.validation_method
- (Optional) Which 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.key_algorithm
- (Optional) Specifies the algorithm of the public and private key pair that your Amazon issued certificate uses to encrypt data. See ACM Certificate characteristics for more details.options
- (Optional) Configuration block used to set certificate options. Detailed below.validation_option
- (Optional) Configuration block used to specify information about the initial validation of each domain name. Detailed below.private_key
- (Required) Certificate's PEM-formatted private keycertificate_body
- (Required) Certificate's PEM-formatted public keycertificate_chain
- (Optional) Certificate's PEM-formatted chaincertificate_authority_arn
- (Required) ARN of an ACM PCAdomain_name
- (Required) Domain name for which the certificate should be issued.early_renewal_duration
- (Optional) Amount of time to start automatic renewal process before expiration.
Has no effect if less than 60 days.
Represented by either
a subset of RFC 3339 duration supporting years, months, and days (e.g., P90D
),
or a string such as 2160h
.subject_alternative_names
- (Optional) Set of domains that should be SANs in the issued certificate.
To remove all elements of a previously configured list, set this value equal to an empty list ([]
)
or use the terraform taint
command to trigger recreation.tags
- (Optional) Map of tags to assign to the resource. If configured with a provider default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.Supported nested arguments for the options
configuration block:
certificate_transparency_logging_preference
- (Optional) Whether certificate details should be added to a certificate transparency log. Valid values are ENABLED
or DISABLED
. See https://docs.aws.amazon.com/acm/latest/userguide/acm-concepts.html#concept-transparency for more details.Supported nested arguments for the validation_option
configuration block:
domain_name
- (Required) Fully qualified domain name (FQDN) in the certificate.validation_domain
- (Required) 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. This must be the same as the domain_name
value or a superdomain of the domain_name
value. For example, if you request a certificate for "testing.example.com"
, you can specify "example.com"
for this value.This resource exports the following attributes in addition to the arguments above:
id
- ARN of the certificatearn
- ARN of the certificatedomain_name
- Domain name for which the certificate is issueddomain_validation_options
- Set of domain validation objects which can be used to complete certificate validation.
Can have more than one element, e.g., if SANs are defined.
Only set if DNS
-validation was used.not_after
- Expiration date and time of the certificate.not_before
- Start of the validity period of the certificate.pending_renewal
- true
if a Private certificate eligible for managed renewal is within the early_renewal_duration
period.renewal_eligibility
- Whether the certificate is eligible for managed renewal.renewal_summary
- Contains information about the status of ACM's managed renewal for the certificate.status
- Status of the certificate.type
- Source of the certificate.tags_all
- Map of tags assigned to the resource, including those inherited from the provider default_tags
configuration block.validation_emails
- List of addresses that received a validation email. Only set if EMAIL
validation was used.Domain validation objects export the following attributes:
domain_name
- Domain to be validatedresource_record_name
- The name of the DNS record to create to validate the certificateresource_record_type
- The type of DNS record to createresource_record_value
- The value the DNS record needs to haveRenewal summary objects export the following attributes:
renewal_status
- The status of ACM's managed renewal of the certificaterenewal_status_reason
- The reason that a renewal request was unsuccessful or is pendingIn Terraform v1.5.0 and later, use an import
block to import certificates using their ARN. For example:
import {
to = aws_acm_certificate.cert
id = "arn:aws:acm:eu-central-1:123456789012:certificate/7e7a28d2-163f-4b8f-b9cd-822f96c08d6a"
}
Using terraform import
, import certificates using their ARN. For example:
% terraform import aws_acm_certificate.cert arn:aws:acm:eu-central-1:123456789012:certificate/7e7a28d2-163f-4b8f-b9cd-822f96c08d6a