Skip to main content
This example deploys the same application and PostgreSQL database to three environments of one project. A locals map holds what differs between the environments, and for_each creates one copy of each resource per entry.

Configuration

variables.tf
main.tf
What differs between the environments:
  • Git branch: each environment builds its own branch.
  • Instances: production runs three instances of the application.
  • Database: development and staging run PostgreSQL in a container on the cluster. Production uses your cloud provider’s managed database service, which requires instance_type. db.t3.medium is an AWS RDS instance type: use one that your cloud provider offers. The database mode cannot change after creation.
  • Auto-deploy: new commits redeploy development and staging. Production is deployed by qovery_deployment or from the Console.
The application reads the database connection string from DATABASE_URL, as explained in Application with Database.

Deploy

To add an environment, add an entry to local.environments. To keep a separate state per environment, move the resources into a module and call it from one root configuration per environment, or use workspaces: see Advanced Patterns.

Next steps

Application with Database

Connect services with built-in variables

Advanced Patterns

Modules, workspaces and remote state

Terraform Exporter

Generate the configuration of an existing environment

Terraform Registry

Reference of every resource and data source