Acme - Registration: Example
Acme - Registration: Example
Acme - Registration: Example
» Example
The following creates an account off of a private key generated with the
tls_private_key resource.
provider "acme" {
server_url = "https://acme-staging-v02.api.letsencrypt.org/directory"
}
» Argument Reference
NOTE: All arguments in acme_registration force a new resource if changed.
The resource takes the following arguments:
• account_key_pem (Required) - The private key used to identity the ac-
count.
• email_address (Required) - The contact email address for the account.
1
» Attribute Reference
The following attributes are exported:
• id: The original full URL of the account.
• registration_url: The current full URL of the account.
id and registration_url will usually be the same and will usually only diverge
when migrating protocols, ie: ACME v1 to v2.
» acme_certificate
The acme_certificate resource can be used to create and manage an ACME
TLS certificate.
NOTE: As the usage model of Terraform generally sees it as being run
on a different server than a certificate would normally be placed on, the
acme_certificate resource only supports DNS challenges.
» Example
The below example is the same example that can be found on the index page,
and creates both an account and certificate within the same configuration. The
account is created using the acme_registration resource.
NOTE: When creating accounts and certificates within the same config-
uration, ensure that you reference the account_key_pem argument in the
acme_registration resource as the corresponding account_key_pem argu-
ment in the acme_certificate resource. This will ensure that the account
gets created before the certificate and avoid errors.
provider "acme" {
server_url = "https://acme-staging-v02.api.letsencrypt.org/directory"
}
2
common_name = "www.example.com"
subject_alternative_names = ["www2.example.com"]
dns_challenge {
provider = "route53"
}
}
The acme_certificate resource can also take an external CSR. In this exam-
ple, we create one using tls_cert_request first, before supplying it to the
certificate_request_pem argument.
NOTE: Some current ACME CA implementations (including Let’s Encrypt)
strip most of the organization information out of a certificate request subject.
You may wish to confirm with the CA what behavior to expect when using the
certificate_request_pem argument with this resource.
NOTE: It is not a good practice to use the same private key for both your
account and your certificate. Make sure you use different keys.
provider "acme" {
server_url = "https://acme-staging-v02.api.letsencrypt.org/directory"
}
subject {
common_name = "www.example.com"
3
}
}
dns_challenge {
provider = "route53"
}
}
» Argument Reference
4
the downloading of the staple from the CA’s OCSP endpoints, and should be
configured to tolerate prolonged outages of the OCSP service. Consider this
when using must_staple, and only enable it if you are sure your webserver or
service provider can be configured correctly.
• min_days_remaining (Optional) - The minimum amount of days remain-
ing on the expiration of a certificate before a renewal is attempted. The
default is 30. A value of less than 0 means that the certificate will never
be renewed.
• certificate_p12_password - (Optional) Password to be used when gen-
erating the PFX file stored in certificate_p12. Defaults to an empty
string.
dns_challenge {
provider = "route53"
config = {
AWS_ACCESS_KEY_ID = "${var.aws_access_key}"
AWS_SECRET_ACCESS_KEY = "${var.aws_secret_key}"
AWS_DEFAULT_REGION = "us-east-1"
}
}
#...
}
5
» Using Variable Files for Provider Arguments
Most provider arguments can be suffixed with _FILE to specify that you wish
to store that value in a local file. This can be useful if local storage for these
values is desired over configuration as variables or within the environment.
Building on the above Route 53 provider example, the following example uses
local files to get the access key ID and secret access key.
resource "acme_certificate" "certificate" {
#...
dns_challenge {
provider = "route53"
config = {
AWS_ACCESS_KEY_ID_FILE = "/data/secrets/aws_access_key_id"
AWS_SECRET_ACCESS_KEY_FILE = "/data/secrets/aws_secret_access_key"
AWS_DEFAULT_REGION = "us-east-1"
}
}
#...
}
The ACME provider will normally use your system-configured DNS resolvers to
check for propagation of the TXT records before proceeding with the certificate
request. In split horizon scenarios, this check may never succeed, as the machine
running Terraform may not have visibility into these public DNS records.
To override this default behavior, supply the recursive_nameservers to use
as a list in host:port form within the dns_challenge block:
resource "acme_certificate" "certificate" {
#...
recursive_nameservers = ["8.8.8.8:53"]
dns_challenge {
provider = "route53"
}
#...
}
6
» Using multiple primary DNS providers
The ACME provider will allow you to configure multiple DNS challenges in the
event that you have more than one primary DNS provider.
resource "acme_certificate" "certificate" {
#...
dns_challenge {
provider = "azure"
}
dns_challenge {
provider = "gcloud"
}
dns_challenge {
provider = "route53"
}
#...
}
Some considerations need to be kept in mind when using multiple providers:
• You cannot use more than one provider of the same type at once.
• Your NS records must be correctly configured so that each DNS challenge
provider can correctly discover the appropriate zone to update.
• DNS propagation checks are conducted once per configured common
name and subject alternative name, using the highest configured or
default propagation timeout (*_PROPAGATION_TIMEOUT) and polling
interval (*_POLLING_INTERVAL) settings.
7
Check the DNS provider page of a specific provider for more details on exactly
what variables are supported.
» Certificate renewal
» Attribute Reference