Introduction
Terraform Native Service enables you to deploy and manage Terraform or OpenTofu infrastructure code directly within Qovery. This service type allows you to provision cloud resources, configure external services, and manage infrastructure as code (IaC) using the same environment structure as your applications. Terraform executes within Kubernetes pods on your cluster, with automatic state management, variable injection, and integrated deployment workflows.qovery_terraform_service resource.Demo: Deploy S3 and Connect to Qovery Services
Watch this interactive demo to see how to deploy S3 infrastructure using Terraform and connect it to services deployed with Qovery:Creating a Terraform Service
Open Environment Overview
Create New Service
Configure Service Name
aws-infrastructure, cloudflare-config).Select Git Repository
.tf configuration files.Specify the branch and root path if your Terraform code is in a subdirectory.Select Engine
- Terraform - Official HashiCorp Terraform
- OpenTofu - Open-source Terraform fork
Select Terraform Version
State Management
- Default (Cluster-Managed)
- Custom Backend (AWS S3)
- Zero configuration required
- Automatic state management
- Secure storage within your cluster
- No external dependencies
Execution Timeout (Default)
Cloud Credentials (Default Behavior)
Compute Resources (Default)
- CPU: 500 millicores (500 mCPU or 0.5 vCPU)
- Memory: 256 MiB
- Storage: 5 GiB
qovery_terraform_service resource page.Configure Terraform Variables
main.tfvariables.tf
tf_var_.Example:If your variables.tf contains:tf_var_bucket_nametf_var_environment
.tfvars files to configure multiple variables at once:- Click Import TFVAR
- Select the TFVAR file(s) to import
- Choose which TFVAR files to apply
- Reorder the TFVAR files as needed
.tfvars file using the "{{ VARIABLE_NAME }}" syntax. The file stays in your git repository, and Qovery substitutes the references at deploy time against the variables of the environment being deployed..tfvars template in source control while injecting sensitive or generated values (database credentials, infrastructure outputs from another service) from the matching Qovery environment.- Direct Value Entry - Enter a value directly:
- Reference Environment Variable - Reference another environment variable:
.tf files that are not in main.tf or variables.tf, Qovery will not automatically detect them. You can create these variables manually using the tf_var_ prefix:
Configure Environment Variables
Review and Create
terraform plan immediately and preview the execution plan before applying changes.Running Terraform
After creating your Terraform service, you can execute Terraform commands using the Action Toolbar.
Available Actions
The following Terraform operations are available from the service’s Action Toolbar:Plan
Plan
terraform plan to preview infrastructure changes without applying them.Use this to:- Review what Terraform will create, modify, or destroy
- Validate your Terraform configuration
- Check for drift between your code and actual infrastructure
Plan & Apply
Plan & Apply
terraform plan followed by terraform apply to provision or update infrastructure.This is the standard deployment action that:- Generates an execution plan
- Applies changes to your infrastructure
- Updates the Terraform state
Destroy
Destroy
terraform destroy to remove all resources managed by this Terraform service.Force Unlock
Force Unlock
- A previous Terraform operation was interrupted
- State is locked and preventing new operations
- You see “state is locked” errors
Migrate State
Migrate State
terraform init -migrate-state to:- Move state to a new backend
- Upgrade state file format
- Reconfigure state storage
Create & Run Plan
During service creation, you can select Create & Run Plan to immediately executeterraform plan after the service is created.
This allows you to:
- Preview infrastructure changes before deployment
- Validate your Terraform configuration
- Review the execution plan before committing to apply
Terraform Service Settings
After creating your Terraform service, you can update all configuration options in the Service Settings.General Configuration
All parameters from the creation flow can be modified:Git Repository
Git Repository
- Change the Git repository source
- Update the branch to deploy from
- Modify the root path for Terraform code location
Engine
Engine
- Switch between Terraform and OpenTofu
- This change will take effect on the next deployment
Version
Version
- Update the Terraform or OpenTofu version
- Useful for testing new versions or maintaining compatibility
State Management
State Management
- Modify state storage configuration
- Update state backend settings if using custom backend
Timeout
Timeout
- Adjust the execution timeout (default: 1 hour)
- Increase for long-running Terraform operations
- Decrease to fail faster for quick validations
Execution Resources
Execution Resources
- Update CPU allocation (default: 500 mCPU)
- Modify memory allocation (default: 256 MiB)
- Adjust storage allocation (default: 5 GiB)
- Manage a large number of resources
- Require significant memory for state processing
- Need more CPU for provider operations
Environment Variables
Environment Variables
- Add or update cloud provider credentials
- Configure Terraform input variables (
TF_VAR_*) - Set provider-specific environment variables
- Reference secrets for sensitive values
Terraform Arguments
The Terraform Arguments section allows you to specify additional CLI arguments for each Terraform command. These arguments override default behaviors and enable advanced customization.
Init Arguments
Init Arguments
terraform init behavior.Common arguments:-upgrade- Upgrade modules and providers to latest versions-reconfigure- Reconfigure backend ignoring existing configuration-backend-config=...- Override backend configuration
Validate Arguments
Validate Arguments
terraform validate behavior.Common arguments:-json- Output validation results in JSON format-no-color- Disable colored output
Plan Arguments
Plan Arguments
terraform plan behavior.Common arguments:-target=resource.name- Plan changes for specific resource only-var="key=value"- Set a variable value-var-file=filename- Load variables from file-out=filename- Save plan to a file-refresh=false- Skip state refresh-parallelism=n- Limit concurrent operations
Apply Arguments
Apply Arguments
terraform apply behavior.Common arguments:-target=resource.name- Apply changes to specific resource only-var="key=value"- Set a variable value-var-file=filename- Load variables from file-parallelism=n- Limit concurrent operations-refresh=false- Skip state refresh
Destroy Arguments
Destroy Arguments
terraform destroy behavior.Common arguments:-target=resource.name- Destroy specific resource only-var="key=value"- Set a variable value-parallelism=n- Limit concurrent operations-refresh=false- Skip state refresh
- Separate multiple arguments with spaces
- Quote values containing spaces:
-var="name=my value" - Use multiple
-varflags for multiple variables:-var="a=1" -var="b=2"
Use ARN role for AWS services
Create a dedicated IAM role
<cluster-credentials-role-arn> with your cluster credentials role ARN:Assume the role in your Terraform code
assume_role block to the provider "aws" block of your Terraform code:Set the role ARN
aws_role_arn variable declared in main.tf or variables.tf and exposes it as tf_var_aws_role_arn (see the Configure Terraform Variables step of Creating a Terraform Service). Set it to the ARN of the dedicated IAM role, then redeploy the Terraform service.Custom Build Image
By default, Terraform services run using a base Docker image (Debian-based) containing Terraform (or OpenTofu),dumb-init, rsync, bash, and ca-certificates. If your Terraform code requires additional binaries or tools (e.g., AWS CLI, kubectl, jq, custom scripts), you can customize the build image using a Dockerfile fragment.
Configuring a Dockerfile Fragment
Qovery provides two ways to inject custom Dockerfile commands during the build:- File-based: Reference a Dockerfile fragment file stored in your Git repository
- Inline: Provide Dockerfile commands directly in the service configuration
- File-based Fragment
- Inline Fragment
Create Fragment File
Add Dockerfile Instructions
Configure Service
- Navigate to Service Settings → Dockerfile Fragment
- Select Custom file path
- Enter the absolute path to your fragment file (e.g.,
/terraform/custom-build.dockerfile)
/) and located within your service’s root_path.Deploy
Fragment Examples
Installing AWS CLI and common tools:Supported Dockerfile Instructions
The fragment supports the following Dockerfile instructions:RUN- Execute commands during build (install packages, configure tools, etc.)ADD- Add files with URL/archive support (download and extract remote archives)
/data before the fragment executes, so you can reference them in RUN commands without needing COPY.Clone Service
You can create a clone of the service via the clone feature. A new service with the same configuration will be created into the target environment.Select Service
Clone Service
Select Target Environment