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

# Terraform Infrastructure on GCP

> Provision GCP infrastructure for CrewAI Platform with Terraform and map outputs to Helm values.

## Overview

Use this guide to provision core Google Cloud infrastructure for CrewAI Platform with Terraform, then continue with Helm installation.

<Warning>
  Request the Terraform files from the CrewAI Factory Engineering team before following this guide.
</Warning>

This flow aligns with the GCP Terraform example in the installer and covers:

* GKE cluster
* Cloud SQL for PostgreSQL
* GCS buckets for data and logs
* Artifact Registry for crew image builds
* Cluster add-ons required by the platform

## Prerequisites

* Terraform `>= 1.13.4`
* `gcloud` CLI installed and authenticated
* `gke-gcloud-auth-plugin` installed for `kubectl` access
* `kubectl` and Helm installed
* A GCP project with billing enabled and permissions to create required infrastructure resources

## Step 1: Authenticate and Enable APIs

```bash theme={null}
gcloud auth login
gcloud config set project YOUR_PROJECT_ID
gcloud auth application-default login

gcloud services enable compute.googleapis.com \
  container.googleapis.com \
  sqladmin.googleapis.com \
  servicenetworking.googleapis.com \
  secretmanager.googleapis.com \
  storage-api.googleapis.com \
  certificatemanager.googleapis.com
```

## Step 2: Configure Terraform State

From your `crewai-installer` checkout, open `terraform/examples/gcp/main.tf`.

The example uses a GCS backend for remote state:

```hcl theme={null}
backend "gcs" {
  bucket = "YOUR-UNIQUE-STATE-BUCKET-NAME"
  prefix = "terraform/state"
}
```

* Create the state bucket before running `terraform init`.
* For temporary testing only, you can comment out the backend block and use local state.

## Step 3: Configure Variables

```bash theme={null}
cd terraform/examples/gcp
cp terraform.tfvars.example terraform.tfvars
```

Update at least:

* `project_id`
* `region`
* `gcs_data_bucket_name` (globally unique)
* `gcs_logs_bucket_name` (globally unique)

The example also auto-detects the Terraform runner public IP and adds it to cluster authorized networks.

## Step 4: Apply Infrastructure

```bash theme={null}
terraform init
terraform plan
terraform apply
```

After apply, configure `kubectl` using Terraform output:

```bash theme={null}
terraform output configure_kubectl_command
```

## Step 5: Map Terraform Outputs to Helm Values

Use Terraform outputs to build your `my-values.yaml`:

* `database_ip` -> `envVars.DB_HOST`
* `registry_uri` -> `envVars.CREW_IMAGE_REGISTRY_OVERRIDE`
* `gcs_data_bucket` -> object storage bucket setting used in your deployment

For object storage configuration in CrewAI Platform, follow the [Configuration Guide](/configuration/configuration) and ensure your storage integration matches your GCS access pattern.

Continue with the [Installation Guide](/installation/installation).

## Troubleshooting Notes

* If `terraform init` fails, verify backend bucket settings and project access.
* If `kubectl` cannot connect to the cluster API, confirm your current source IP is authorized.
* If image pushes fail during crew builds, validate `envVars.CREW_IMAGE_REGISTRY_OVERRIDE` points to a writable Artifact Registry path.

## Next Steps

* [Installation Guide](/installation/installation)
* [Configuration Guide](/configuration/configuration)
