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

# Terraform quickstart

> Describe GPU servers, volumes and SSH access as code with the Infinite Compute Terraform provider.

The Infinite Compute Terraform provider manages servers, volumes, volume attachments and SSH keys through the [API](https://docs.infinitecompute.ai/api/overview.md).

## Install the provider

Terraform installs the provider from the [Terraform Registry](https://registry.terraform.io/providers/cloud-infinitecompute/infinitecompute) when you run `terraform init`; the `required_providers` block below is all it needs. Releases are signed, and Terraform checks the signature.

## Configure

Create an [API key](https://docs.infinitecompute.ai/api/keys.md) with the **Read and write** scope and export it, with your API address (your console address followed by `/api/public/v1`; the console address is in your welcome email):

```bash theme={null}
export INFINITECOMPUTE_API_KEY=ic_ck_...
export INFINITECOMPUTE_API_URL=https://<your-console-address>/api/public/v1
```

## A server with a volume and SSH access

Save this as `main.tf`:

```hcl theme={null}
terraform {
  required_providers {
    infinitecompute = {
      source  = "cloud-infinitecompute/infinitecompute"
      version = "~> 0.1"
    }
  }
}

provider "infinitecompute" {}

# A GPU server type your project can use
data "infinitecompute_server_type" "gpu" {
  name = "<server type>"
}

# An image built for that type's GPU
data "infinitecompute_image" "os" {
  name      = "<image>"
  gpu_model = data.infinitecompute_server_type.gpu.gpu_model
}

resource "infinitecompute_ssh_key" "laptop" {
  name       = "laptop"
  public_key = file("~/.ssh/id_ed25519.pub")
}

resource "infinitecompute_server" "train" {
  name        = "llm-finetune-01"
  server_type = data.infinitecompute_server_type.gpu.name
  image       = data.infinitecompute_image.os.id
  ssh_key     = infinitecompute_ssh_key.laptop.name
  disk_gb     = 100

  ssh_access = {
    enabled = true
  }
}

resource "infinitecompute_volume" "data" {
  name    = "datasets"
  size_gb = 500
  site    = data.infinitecompute_server_type.gpu.site
}

resource "infinitecompute_volume_attachment" "data" {
  server_id = infinitecompute_server.train.id
  volume_id = infinitecompute_volume.data.id
}

output "ssh" {
  value = infinitecompute_server.train.ssh_access.command
}
```

Replace `<server type>` and `<image>` with names from your console, or from `ic server-types` and `ic images`. The server types available to you depend on your agreement.

Then:

```bash theme={null}
terraform init
terraform apply      # creates the key, the server, the volume and the attachment
terraform output ssh # the ssh command for your server
```

`terraform apply` waits until the server is `active` (up to 20 minutes by default). Running `terraform plan` again shows no changes.

## Resources and data sources

| Name | Kind | Manages |
| - | - | - |
| `infinitecompute_server` | Resource | A GPU server, with `disk_gb` and `ssh_access` (opened or closed in place). |
| `infinitecompute_volume` | Resource | A volume at a site. |
| `infinitecompute_volume_attachment` | Resource | A volume attached to a server at the same site. |
| `infinitecompute_ssh_key` | Resource | One of your SSH public keys. |
| `infinitecompute_server_type` | Data source | A server type by name: GPU, vCPUs, memory and site. |
| `infinitecompute_image` | Data source | An image by name, optionally for a GPU model. |

Existing resources can be brought under Terraform with `terraform import`: servers and volumes by id, SSH keys by name, attachments by `<server id>/<volume id>`.

## Clean up

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

This deletes the attachment, the volume, the server and the SSH key. Copy anything you want to keep off the server and the volume first.

> [!TIP]
>
> The provider sends an `Idempotency-Key` with every create, so a retried `apply` never launches a second server.


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