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

# Onboard a GKE cluster with Terraform

> Register your GKE cluster in CostGraph and install the operator in your existing Terraform configuration.

## Prerequisites

* A Helm provider configured for your cluster.
* An organization owner's API key with `organization:manage`, set as `COSTGRAPH_API_KEY`.
* An operator API key with `operator:read` and `operator:write` for your CostGraph tenant.
* That operator key stored as `apiKey` in the `costgraph-collector` Secret, in the `costgraph` namespace.

For GKE Autopilot, complete the [operator prerequisites](https://docs.costgraph.ai/costgraph/operator/overview.md#prerequisites) before installing.

## GKE configuration

Assuming your Terraform configuration already defines a GKE cluster like this, use its name when registering it in CostGraph.

```hcl theme={null}
resource "google_container_cluster" "production" {
  name               = "production-gke"
  location           = var.region
  initial_node_count = 3
}
```

## Register the cluster

Add CostGraph to your existing Terraform provider configuration.

```hcl theme={null}
terraform {
  required_providers {
    costgraph = {
      source  = "baselinehq/costgraph"
      version = "~> 0.3.0"
    }
  }
}

provider "costgraph" {}
```

Look up your CostGraph tenant by name and reference the existing cluster. Replace `production` with your tenant's name.

```hcl theme={null}
data "costgraph_tenant" "production" {
  name = "production"
}

resource "costgraph_kubernetes_cluster" "production" {
  name      = google_container_cluster.production.name
  tenant_id = data.costgraph_tenant.production.id
}
```

## Install the operator

Add a Helm release that uses the registered cluster name and your operator key.

```hcl theme={null}
resource "helm_release" "costgraph_operator" {
  name       = "costgraph-operator"
  repository = "https://charts.costgraph.ai"
  chart      = "costgraph-operator"
  version    = "0.8.27"
  namespace  = "costgraph"

  values = [yamlencode({
    global = {
      clusterName       = costgraph_kubernetes_cluster.production.name
      existingSecret    = "costgraph-collector"
      existingSecretKey = "apiKey"
    }
  })]
}
```

Review and apply the changes.

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

Terraform registers the cluster and installs the operator. Open [Kubernetes clusters](https://app.costgraph.ai/compute/clusters) to view its costs and usage.

For full provider resource coverage, see the [CostGraph Terraform provider documentation in the Terraform Registry](https://registry.terraform.io/providers/baselinehq/costgraph/latest/docs).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.