> ## 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 an AKS cluster with Terraform

> Register your AKS 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.

## AKS configuration

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

```hcl theme={null}
resource "azurerm_kubernetes_cluster" "production" {
  name                = "production-aks"
  location            = var.region
  resource_group_name = var.resource_group_name
  dns_prefix          = "production"

  default_node_pool {
    name       = "system"
    node_count = 3
    vm_size    = var.node_vm_size
  }

  identity {
    type = "SystemAssigned"
  }
}
```

## 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      = azurerm_kubernetes_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.