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
Deploying via Docker image is currently the only deployment method supported with Terraform. If you’d like to use Terraform to deploy your Apps and you’re currently deploying via Git, you’ll need to switch. See Migrating from deploying via Git for tips on how to do so. If you’re already deploying via Docker image, managing this is pretty easy. The app resource uses three separate attributes:docker_image- The Docker image to deploy (e.g.quay.io/aptible/deploy-demo-app).private_registry_username- (Optional) Username for authenticating with a private Docker registry.private_registry_password- (Optional) Password for authenticating with a private Docker registry.
If you previously configured these settings through
aptible_app.config, you can remove them from the configManaging 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:
Endpoint Settings
You can configure endpoint settings like timeouts, HTTPS redirects, and maintenance pages directly on theaptible_endpoint resource using various attributes. See the App Endpoints documentation for available options by endpoint type.
If you previously configured these settings through
aptible_app.config, move them to aptible_endpoint for cleaner resource organization.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:

