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. Production uses a managed database from a blueprint, which needs an AWS cluster.

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 runs Amazon RDS for PostgreSQL, created from a blueprint of the service catalog with qovery_blueprint. This blueprint needs an AWS cluster. instance_class and allocated_storage are variables of the blueprint.
  • Auto-deploy: new commits redeploy development and staging. Production is deployed by qovery_deployment or from the Console: to deploy it again after a change, set version on its qovery_deployment to a new UUID.
The application reads the database connection string from DATABASE_URL. For a container database, it is an alias of a built-in secret. For the managed database, it is a secret that Qovery builds from the outputs of the blueprint when it deploys the application. Application with Database explains both.

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