On this page
Automate with the Patrii Terraform provider
The Patrii Terraform provider describes your networks, instances, volumes, DNS, load balancers and more as code, so you can review, repeat and version your infrastructure.
Declare the provider, give it an application credential through environment variables, and run terraform plan and terraform apply as usual. Each service guide in this documentation shows the matching resources next to the console and CLI steps.
PATRII_APPLICATION_CREDENTIAL_ID and PATRII_APPLICATION_CREDENTIAL_SECRET. The Patrii CLI uses shorter names, PATRII_APP_CREDENTIAL_ID and PATRII_APP_CREDENTIAL_SECRET; set both pairs if one pipeline runs both tools.Before you start
- Terraform installed on your computer or in your pipeline.
- An application credential for the target project, created from Application credentials in your account or the project's actions menu.
Step by step
- Declare the provider
Add the
required_providersblock and aprovider "patrii"block to your configuration. - Provide the credential
Export the application credential ID and secret. Optional variables
PATRII_PROJECT_ID,PATRII_PROJECT_NAME,PATRII_REGIONandPATRII_AUTH_URLmatch the provider attributes of the same name. - Plan and apply
Run
terraform init, reviewterraform plan, thenterraform apply.
Examples
terraform {
required_providers {
patrii = {
source = "PatriiCloud/patrii"
}
}
}
provider "patrii" {
auth_url = "https://api.patrii.cloud"
# region, project_id and the credential come from the environment
}export PATRII_APPLICATION_CREDENTIAL_ID=<credential-id> export PATRII_APPLICATION_CREDENTIAL_SECRET=<credential-secret> export PATRII_PROJECT_ID=<project-id> # optional: the credential is project-scoped export PATRII_REGION=<region> # optional terraform init terraform plan
Limits & specifications
Provider settings:
| Attribute | Environment variable |
|---|---|
auth_url | PATRII_AUTH_URL |
application_credential_id | PATRII_APPLICATION_CREDENTIAL_ID |
application_credential_secret | PATRII_APPLICATION_CREDENTIAL_SECRET |
project_id | PATRII_PROJECT_ID |
project_name | PATRII_PROJECT_NAME |
region | PATRII_REGION |
Best practices
- Keep the credential secret out of your
.tffiles and state outputs; pass it through the environment or your pipeline's secret store. - Use one application credential per pipeline so you can revoke one without breaking the others.
Learn more
Everything you can do here in the console is also available through the Patrii Cloud API for automation and scripting.