Add certificates using Terraform
Use the f5ads_certificate resource to upload certificates for F5 Application Delivery Service.
The resource supports SSL/TLS certificates with matching private keys and CA certificate bundles without private keys.
To use a certificate, reference its resource ID in an NGINX configuration payload, then apply that configuration to a deployment.
See Manage NGINX configurations using Terraform.
- Create F5 ADS client credentials. See Automate access with client credentials.
- Install Terraform.
Have a PEM-encoded certificate and matching private key for the example below.
-
Save your certificate as
server.crtand its matching private key asserver.keyin your Terraform module directory. -
Add the following resource to your Terraform configuration:
hcl resource "f5ads_certificate" "tls" { name_prefix = "example-tls" public_certs = filebase64("${path.module}/server.crt") private_key = filebase64("${path.module}/server.key") lifecycle { create_before_destroy = true } }Use either
nameorname_prefixto name the certificate. The example usesname_prefixto give replacement certificates unique names. The resource requires Base64-encoded PEM contents. Thefilebase64()function reads and encodes each file. For a CA certificate bundle, supply the bundle inpublic_certsand omitprivate_key.Certificates are immutable. Changing the certificate or private key requires Terraform to replace the resource. By default, Terraform removes a resource before creating its replacement. The
create_before_destroysetting reverses that order, but the replacement must have a different name because certificate names must be unique. Usename_prefixto let the provider generate a unique name for the replacement. Together, these settings let Terraform create the new certificate before it removes the old one. Update configuration references to the new certificate before Terraform removes the old one.ImportantTerraform stores the private key in its state, even though CLI output marks it as sensitive. Restrict who can read your state backend and use encryption at rest. Don’t commit private keys or state files to version control. -
Initialize Terraform, review the plan, and apply the changes:
shell terraform init terraform plan terraform applyTerraform creates the certificate. Use
f5ads_certificate.tls.idwhen referencing it in your Terraform configuration.
Certificates with the same name can’t coexist.
Use name_prefix with create_before_destroy, as shown above, to give the replacement a unique name.
If you already use a fixed name, create a certificate with a new name and update its configuration references first.
- Certificate resource reference
- Configuration resource reference
- Use a certificate in an NGINX configuration with the console