> ## Documentation Index
> Fetch the complete documentation index at: https://www.qovery.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Terraform Provider

> Manage your Qovery infrastructure as code with Terraform

## Overview

The Qovery Terraform Provider allows you to manage your Qovery infrastructure using Infrastructure as Code (IaC). Define, provision, and manage your applications, databases, environments, and entire stacks declaratively with Terraform.

<Info>
  **Complete Documentation**: For detailed resource schemas, arguments, and
  attributes, visit the [Qovery Terraform Provider on Terraform
  Registry](https://registry.terraform.io/providers/Qovery/qovery/latest/docs).
</Info>

## Why Use Terraform with Qovery?

<CardGroup cols={2}>
  <Card title="Infrastructure as Code" icon="file-code">
    Version control your infrastructure alongside your application code
  </Card>

  <Card title="Reproducible Deployments" icon="copy">
    Deploy identical environments across dev, staging, and production
  </Card>

  <Card title="Team Collaboration" icon="users">
    Review infrastructure changes through pull requests
  </Card>

  <Card title="Automation" icon="robot">
    Integrate with CI/CD pipelines for automated deployments
  </Card>
</CardGroup>

## Getting Started

<Note>
  This guide provides a quick overview of the Qovery Terraform Provider. For
  comprehensive documentation including all resources, data sources, and
  configuration options, please refer to the [official provider documentation on
  Terraform
  Registry](https://registry.terraform.io/providers/Qovery/qovery/latest/docs).
</Note>

### Installation

Add the Qovery provider to your Terraform configuration:

```hcl theme={null}
terraform {
  required_providers {
    qovery = {
      source  = "qovery/qovery"
      version = "~> 0.48.2"
    }
  }
}

provider "qovery" {
  token = var.qovery_api_token
}
```

## Authentication

To authenticate with the Qovery API, you need an API token. You can generate one from the [Qovery Console](https://console.qovery.com).

Set your token as an environment variable:

```bash theme={null}
export QOVERY_API_TOKEN="your-api-token"
```

Or pass it directly in your Terraform configuration:

```hcl theme={null}
provider "qovery" {
  token = "your-api-token"
}
```

<Warning>
  Never commit API tokens to version control. Use environment variables or a
  secure secrets management solution.
</Warning>

## Quick Start

<Steps>
  <Step title="Install Terraform">
    Download Terraform from [terraform.io](https://www.terraform.io/downloads)

    ```bash theme={null}
    # Verify installation
    terraform version
    ```
  </Step>

  <Step title="Generate API Token">
    1. Go to [Qovery Console](https://console.qovery.com)
    2. Navigate to Organization Settings → API Tokens
    3. Click "Generate Token" and copy it
  </Step>

  <Step title="Create Terraform Configuration">
    Create a `main.tf` file:

    ```hcl theme={null}
    terraform {
      required_providers {
        qovery = {
          source = "qovery/qovery"
          version = "~> 0.48.2"
        }
      }
    }

    provider "qovery" {
      token = var.qovery_api_token
    }

    # Get organization and project IDs
    data "qovery_organization" "my_org" {
      name = "My Organization"
    }

    data "qovery_project" "my_project" {
      organization_id = data.qovery_organization.my_org.id
      name = "My Project"
    }
    ```
  </Step>

  <Step title="Initialize and Apply">
    ```bash theme={null}
    # Initialize Terraform
    terraform init

    # Set your API token
    export TF_VAR_qovery_api_token="your-api-token"

    # Plan changes
    terraform plan

    # Apply changes
    terraform apply
    ```
  </Step>
</Steps>

## Getting Your IDs

You'll need various IDs from Qovery for your Terraform configuration:

<Tabs>
  <Tab title="Via Console">
    **Organization ID**:

    * Go to Organization Settings
    * Copy Organization ID from the URL or settings page

    **Project ID**:

    * Navigate to your project
    * Copy Project ID from project settings

    **Cluster ID**:

    * Go to Settings → Clusters
    * Copy Cluster ID from cluster details
  </Tab>

  <Tab title="Via Terraform Data Sources">
    Use data sources to look up resources by name:

    ```hcl theme={null}
    # Find organization by name
    data "qovery_organization" "my_org" {
      name = "My Organization"
    }

    # Find project by name
    data "qovery_project" "my_project" {
      organization_id = data.qovery_organization.my_org.id
      name = "My Project"
    }

    # Find cluster by name
    data "qovery_cluster" "my_cluster" {
      organization_id = data.qovery_organization.my_org.id
      name = "production"
    }

    # Use in resources
    resource "qovery_environment" "prod" {
      project_id = data.qovery_project.my_project.id
      cluster_id = data.qovery_cluster.my_cluster.id
      name = "production"
      mode = "PRODUCTION"
    }
    ```
  </Tab>

  <Tab title="Via CLI">
    ```bash theme={null}
    # Install Qovery CLI
    curl -s https://get.qovery.com | bash

    # Login
    qovery auth

    # Set context (interactive selection of organization)
    qovery context set

    # List projects in current organization
    qovery project list

    # List clusters in current organization
    qovery cluster list

    # List environments in current project
    qovery environment list

    # List applications in current environment
    qovery application list
    ```

    <Note>
      The CLI uses a context-based approach. Use `qovery context set` to interactively select your organization, then run list commands to get IDs of resources within that context. See [CLI documentation](/cli/overview) for more details.
    </Note>
  </Tab>
</Tabs>

## Key Resources

The Qovery Terraform provider supports managing:

<AccordionGroup>
  <Accordion title="Organization & Structure" icon="building">
    * `qovery_organization` - Organization settings (read-only)
    * `qovery_project` - Projects to organize applications
    * `qovery_environment` - Development, staging, production environments
    * `qovery_labels_group` - Organize resources with labels
  </Accordion>

  <Accordion title="Applications & Services" icon="rocket">
    * `qovery_application` - Containerized applications
    * `qovery_container` - Custom container deployments
    * `qovery_job` - Cron jobs and lifecycle jobs
    * `qovery_helm` - Helm chart deployments
  </Accordion>

  <Accordion title="Databases" icon="database">
    * `qovery_database` - Managed databases (PostgreSQL, MySQL, MongoDB, Redis)
    * Container mode or cloud-managed mode
    * Automatic connection string injection
  </Accordion>

  <Accordion title="Configuration" icon="sliders">
    * `qovery_environment_variable` - Environment-level variables
    * `qovery_environment_variable_alias` - Variable aliases
    * `qovery_environment_variable_override` - Override variables
    * `qovery_deployment_stage` - Control deployment order
  </Accordion>

  <Accordion title="Infrastructure" icon="server">
    * `qovery_cluster` - Kubernetes cluster configuration
    * `qovery_aws_credentials` - AWS cloud credentials
    * `qovery_scaleway_credentials` - Scaleway cloud credentials
    * `qovery_gcp_credentials` - GCP cloud credentials
  </Accordion>

  <Accordion title="Integrations" icon="plug">
    * `qovery_container_registry` - Connect container registries
    * `qovery_git_token` - Git provider authentication
    * `qovery_helm_repository` - Add Helm chart repositories
  </Accordion>
</AccordionGroup>

## Best Practices

### Use Variables

Keep tokens in environment variables, not in code:

```hcl theme={null}
variable "qovery_api_token" {
  type = string
  sensitive = true
}

variable "environment" {
  type = string
  default = "production"
}
```

### Use Data Sources

Look up existing resources instead of hardcoding IDs:

```hcl theme={null}
data "qovery_project" "my_project" {
  organization_id = var.org_id
  name = "My Project"
}
```

### Organize with Modules

Create reusable modules for common patterns:

```
modules/
  ├── application/
  ├── database/
  └── environment/
```

### Use Remote State

Store state remotely for team collaboration:

```hcl theme={null}
terraform {
  backend "s3" {
    bucket = "my-terraform-state"
    key = "qovery/terraform.tfstate"
  }
}
```

## Importing Existing Resources

Import existing Qovery resources into Terraform:

```bash theme={null}
# Import an application
terraform import qovery_application.my_app <application-id>

# Import an environment
terraform import qovery_environment.prod <environment-id>

# Import a database
terraform import qovery_database.postgres <database-id>
```

***

## Complete Documentation

<Warning>
  **Important**: This page provides an introduction to the Qovery Terraform Provider. For complete and up-to-date documentation, including:

  * All available resources and data sources
  * Detailed resource schemas and arguments
  * Complete attribute references
  * Advanced configuration options
  * Latest provider updates

  Please visit the **[Qovery Terraform Provider on Terraform Registry](https://registry.terraform.io/providers/Qovery/qovery/latest/docs)**.
</Warning>

## Next Steps

<CardGroup cols={2}>
  <Card title="Basic Application" icon="rocket" href="/terraform-provider/basic-application">
    Deploy your first application with Terraform
  </Card>

  <Card title="Application with Database" icon="database" href="/terraform-provider/application-with-database">
    Deploy an application connected to a database
  </Card>

  <Card title="Multi-Environment Setup" icon="layer-group" href="/terraform-provider/multi-environment">
    Create dev, staging, and production environments
  </Card>

  <Card title="Advanced Patterns" icon="code" href="/terraform-provider/advanced-patterns">
    Deployment pipelines, modules, and advanced configurations
  </Card>
</CardGroup>

## Additional Resources

<CardGroup cols={2}>
  <Card title="Terraform Registry" icon="book-open" href="https://registry.terraform.io/providers/Qovery/qovery/latest/docs">
    Complete provider documentation and reference
  </Card>

  <Card title="GitHub Repository" icon="https://mintcdn.com/qovery/Nvnl0g5BHzA0XQmy/images/logos/github-icon.svg?fit=max&auto=format&n=Nvnl0g5BHzA0XQmy&q=85&s=8bd221fee047ba947afcfd39bd14ef08" href="https://github.com/Qovery/terraform-provider-qovery" width="24" height="24" data-path="images/logos/github-icon.svg">
    Provider source code and issue tracking
  </Card>

  <Card title="Example Templates" icon="file-code" href="https://github.com/Qovery/terraform-examples">
    Ready-to-use Terraform templates
  </Card>

  <Card title="API Documentation" icon="brackets-curly" href="/api-reference/introduction">
    Qovery API reference
  </Card>
</CardGroup>
