Aptible Terraform Provider
Overview
The Aptible Terraform provider allows you to manage your Aptible resources directly from Terraform - enabling infrastructure as code (IaC) instead of manually initiating Operations from the Aptible Dashboard of Aptible CLI. You can use the Aptible Terraform to automate the process of setting up new Environments, including:- Creating, scaling, modifying, and deprovisioning Apps and Databases
- Creating and deprovisioning Log Drains and Metric Drains (including the Aptible Terraform Metrics Module, which provisions built Grafana dashboards with alerting)
- Creating, modifying, and provisioning App Endpoints and Database Endpoints
Using the Aptible Terraform Provider
Environment definition
The Environment resource is used to create and manage Environments running on Aptible Deploy.Deployment and managing Docker images
Direct Docker Image Deployment is currently the only deployment method supported with Terraform. If you’d like to use Terraform to deploy your Apps and you’re currently using Dockerfile Deployment you’ll need to switch. See Migrating from Dockerfile Deploy for tips on how to do so. If you’re already using Direct Docker Image Deployment, managing this is pretty easy. Set your Docker repo, registry username, and registry password as the configuration variablesAPTIBLE_DOCKER_IMAGE
, APTIBLE_PRIVATE_REGISTRY_USERNAME
, and APTIBLE_PRIVATE_REGISTRY_PASSWORD
.
Please ensure you have the correct image, username, and password set every time you run
terraform apply
. If you are deploying outside of Terraform, you will also need to keep your Terraform configuration up to date. See Terraform’s refresh Terraform configuration documentation for more information. For a step-by-step tutorial in deploying a metric drain with Terraform, please visit our Terraform Metric Drain Deployment Guide
Managing Services
Managing Services
The serviceprocess_type
should match what’s contained in your Procfile. Otherwise, service container sizes and container counts cannot be defined and managed individually. The process_type maps directly to the Service name used in the Procfile. If you are not using a Procfile, you will have a single Service with the process_type of cmd.
Referencing Resources in Configurations
Resources can easily be referenced in configurations when using Terraform. Here is an example of an App configuration that references Databases:aptible_endpoint.example-endpoint.virtual_domain
will be the domain used to access the Endpoint (so app-0000.on-aptible.com
or www.example.com
).
If your Endpoint uses a wildcard certificate/domain,
virtual_domain
would be something like *.example.com
which is not a valid domain name. Therefore, when using a wildcard domain, you should provide the subdomain you want your application to use to access the Endpoint, like www.example.com
, rather than relying solely on the Endpoint’s virtual_domain
.Circular Dependencies
One potential risk of relying on URLs to be set in App configurations is circular dependencies. This happens when your App uses the Endpoint URL in its configuration, but the Endpoint cannot be created until the App exists. Terraform does not have a graceful way of handling circular dependencies. While this approach won’t work for default domains, the easiest option is to define a variable that can be referenced in both the Endpoint resource and the App configuration:Managing DNS
While Aptible does not directly manage your DNS, we do provide you the information you need to manage DNS. For example, if you are using Cloudflare for your DNS, and you have an endpoint calledexample-endpoint
, you would be able to create the record:
Secure/Sensitive Values
You can use Terraform to mark values as secure. These values are redacted in the output ofterraform plan
and terraform apply
.
terraform state show
these values will also be marked as sensitive. For example: