Overview
The Lifecycle Job feature enables executing commands before or after environment deployment. Use cases include running infrastructure-as-code tools, creating cloud resources (SQS, SNS, Lambdas), deploying managed services, or seeding databases.Execution Flow
Deployment sequence:- Qovery builds the Lifecycle Job and other services
- Qovery executes the Job’s Start Event
- Job creates AWS RDS MySQL instance
- Job writes database credentials to
/qovery-output/qovery-output.json - Qovery injects credentials as environment variables
- Services access the database
- Qovery runs Job’s Deleted Event
- Job destroys AWS RDS MySQL instance
- Qovery releases all resources
Prerequisites
- Active Qovery account
- Existing project and environment
- S3 bucket for Terraform state backend
Step 1: Repository Setup
Fork the lifecycle-job-examples repository Root application path:/examples/aws-rds-with-terraform
Step 2: Add Lifecycle Job



- Start Event command:
["-c","terraform apply -no-color -auto-approve && terraform output -json > /qovery-output/qovery-output.json"] - Deleted Event command:
["-c","terraform destroy -no-color -auto-approve"]


- CPU: 0.5
- RAM: 256 MB
Step 3: Environment Variables

TF_VAR_terraform_backend_bucketTF_VAR_aws_regionTF_VAR_aws_access_key_idTF_VAR_aws_secret_access_keyTF_VAR_qovery_environment_id

Step 4: Multi-Environment Support


QOVERY_ENVIRONMENT_ID to TF_VAR_qovery_environment_id at service scope level.

Step 5: Deploy





Output Credentials
After deployment, Terraform output automatically generatesQOVERY_OUTPUT_** environment variables containing database credentials for application use.

FAQ
Environment Deletion: Deleted Event executesterraform destroy automatically.
Application Deployment: Lifecycle Jobs can deploy applications but official Qovery methods are recommended.
Environment Cloning: Cloned environments receive unique QOVERY_ENVIRONMENT_ID values; S3 state management preserves existing resources.
Post-Deployment Modifications: Redeploying updated Jobs uses existing S3 state; resource modifications depend on configuration file changes.