> ## Documentation Index
> Fetch the complete documentation index at: https://qovery-gdubroeucq-qov-2319.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Basic Application

> Deploy an application built from a git repository with Terraform

This example creates a project, an environment and an application built from the Dockerfile of a public git repository, then deploys the environment on an existing cluster.

## Prerequisites

* The provider set up as described in the [overview](/terraform-provider/overview), with the `QOVERY_API_TOKEN` environment variable set.
* The ID of your organization and the ID of an existing cluster. See [Find resource IDs](/terraform-provider/overview#find-resource-ids).

## Configuration

```hcl variables.tf theme={null}
variable "organization_id" {
  description = "ID of the Qovery organization"
  type        = string
}

variable "cluster_id" {
  description = "ID of the cluster that runs the environment"
  type        = string
}
```

```hcl main.tf theme={null}
terraform {
  required_providers {
    qovery = {
      source  = "qovery/qovery"
      version = "~> 1.0"
    }
  }
}

provider "qovery" {}

resource "qovery_project" "demo" {
  organization_id = var.organization_id
  name            = "demo"
}

resource "qovery_environment" "production" {
  project_id = qovery_project.demo.id
  cluster_id = var.cluster_id
  name       = "production"
  mode       = "PRODUCTION"
}

resource "qovery_application" "api" {
  environment_id = qovery_environment.production.id
  name           = "api"

  git_repository = {
    url    = "https://github.com/your-org/your-app.git"
    branch = "main"
  }
  build_mode      = "DOCKER"
  dockerfile_path = "Dockerfile"

  cpu                   = 500
  memory                = 512
  min_running_instances = 1
  max_running_instances = 1

  ports = [
    {
      internal_port       = 8080
      external_port       = 443
      protocol            = "HTTP"
      publicly_accessible = true
    }
  ]

  healthchecks = {
    readiness_probe = {
      type = {
        http = {
          port   = 8080
          path   = "/"
          scheme = "HTTP"
        }
      }
      initial_delay_seconds = 30
      period_seconds        = 10
      timeout_seconds       = 5
      success_threshold     = 1
      failure_threshold     = 3
    }
    liveness_probe = {
      type = {
        tcp = {
          port = 8080
        }
      }
      initial_delay_seconds = 30
      period_seconds        = 10
      timeout_seconds       = 5
      success_threshold     = 1
      failure_threshold     = 3
    }
  }
}

# Creating a service does not deploy it: this resource deploys the environment.
resource "qovery_deployment" "production" {
  environment_id = qovery_environment.production.id
  desired_state  = "RUNNING"

  depends_on = [qovery_application.api]
}

output "application_url" {
  value = "https://${qovery_application.api.external_host}"
}
```

About this configuration:

* `healthchecks` is required. Set the probe ports and path to what your application serves. An HTTP probe requires `scheme`.
* `auto_deploy` is `true` by default: Qovery redeploys the application on each new commit to `main`.
* Changing the application in the configuration updates it in Qovery but does not redeploy it. To redeploy on the next `terraform apply`, set `version` on `qovery_deployment` to a new UUID, or deploy from the Console.

## Deploy

```bash theme={null}
export TF_VAR_organization_id="<organization_id>"
export TF_VAR_cluster_id="<cluster_id>"

terraform init
terraform plan
terraform apply
```

`terraform apply` waits for the deployment to finish, then prints the application URL.

## Clean up

```bash theme={null}
terraform destroy
```

This deletes the application, the environment and the project.

## Next steps

<CardGroup cols={2}>
  <Card title="Application with Database" icon="database" href="/terraform-provider/application-with-database">
    Connect the application to a database
  </Card>

  <Card title="Multi-Environment Setup" icon="layer-group" href="/terraform-provider/multi-environment">
    Deploy the same stack to several environments
  </Card>

  <Card title="qovery_application reference" icon="book-open" href="https://registry.terraform.io/providers/qovery/qovery/latest/docs/resources/application">
    Every attribute of the application resource
  </Card>

  <Card title="qovery_deployment reference" icon="book-open" href="https://registry.terraform.io/providers/qovery/qovery/latest/docs/resources/deployment">
    Deploy, stop or restart an environment
  </Card>
</CardGroup>
