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

> ## Agent Instructions
> Use the documentation index to find relevant pages, then read the linked Markdown before answering and cite the source URL.
> Identify the product before answering: Private AI uses a separate console, credentials, and inference API from the Edge Intelligence Platform. Do not apply instructions from one product to the other.
> Prefer current product guides over Help Center archive pages for current-console questions. Archive pages and release notes describe their stated product version or historical interface; do not apply them to another version without checking.
> Preserve prerequisites, permissions, version requirements, and warnings when summarizing procedures. Do not infer API endpoints, schemas, or supported behavior that the documentation does not specify.

# Use Case: Terraform for Clusters

> Use the Terraform Provider for ZEDEDA Cloud to automate the creation, replacement, and deletion of clusters as code.

## Introduction

This article covers using the Terraform Provider for ZEDEDA Cloud to manage clusters as code. It assumes familiarity with Terraform and with clusters in Edge Infrastructure Services. For a complete introduction to the Terraform provider, see [ZEDEDA Terraform Provider](https://zededa.mintlify.site/new-ui/infrastructure-services/integrations-and-automation/terraform-provider.md).

### Prerequisites

* You have the SysManager or SysAdmin role in your enterprise. See [Manage Roles](https://zededa.mintlify.site/new-ui/infrastructure-services/administration/manage-roles.md).
* The Terraform CLI is installed on your local system.
* A ZEDEDA Cloud API token. To generate one, go to your user profile (select your name in the header) and select the **API Tokens** tab.
* Nodes are onboarded to Edge Infrastructure Services and running an EVE-OS Kubevirt image. Clusters require Kubevirt-capable nodes.
* A project exists to associate the cluster with.

## Create a Cluster

### Dependencies

Before creating the cluster resource, declare its dependencies. A `zedcloud_edgenode_cluster` resource requires:

* A `zedcloud_project` resource (or data source) providing the project ID.
* At least one `zedcloud_edgenode` resource per node in the cluster, each running the EVE-OS Kubevirt image.

### Example configuration

The following is a minimum proof-of-concept configuration for a three-node cluster. Revise it to match your environment before use.

```text theme={"dark"}
terraform {
  required_providers {
    zedcloud = {
      source  = "zededa/zedcloud"
      version = "2.4.0"
    }
  }
}

resource "zedcloud_project" "my_project" {
  name  = "my_project"
  title = "my_project"
  type  = "TAG_TYPE_PROJECT"
}

resource "zedcloud_brand" "my_brand" {
  name        = "my_brand"
  title       = "my_brand"
  description = "description"
  origin_type = "ORIGIN_LOCAL"
}

resource "zedcloud_model" "my_model" {
  brand_id    = zedcloud_brand.my_brand.id
  name        = "my_model"
  title       = "my_model"
  type        = "AMD64"
  origin_type = "ORIGIN_LOCAL"
  state       = "SYS_MODEL_STATE_ACTIVE"
  attr = {
    memory  = "8G"
    storage = "100G"
    Cpus    = "4"
  }
  io_member_list {
    ztype        = "IO_TYPE_ETH"
    phylabel     = "firstEth"
    usage        = "ADAPTER_USAGE_MANAGEMENT"
    assigngrp    = "eth0"
    phyaddrs     = { Ifname = "eth0", PciLong = "0000:02:00.0" }
    logicallabel = "ethernet0"
    usage_policy = { FreeUplink = true }
    cost         = 0
  }
  io_member_list {
    ztype        = "IO_TYPE_ETH"
    phylabel     = "secondEth"
    assigngrp    = "eth1"
    phyaddrs     = { Ifname = "eth1", PciLong = "0000:03:00.0" }
    logicallabel = "ethernet1"
    usage_policy = { FreeUplink = true }
    cost         = 0
  }
}

resource "zedcloud_edgenode" "cluster_node_1" {
  name                 = "cluster_node_1"
  model_id             = zedcloud_model.my_model.id
  project_id           = zedcloud_project.my_project.id
  title                = "cluster_node_1"
  generate_soft_serial = true
}

resource "zedcloud_edgenode" "cluster_node_2" {
  name                 = "cluster_node_2"
  model_id             = zedcloud_model.my_model.id
  project_id           = zedcloud_project.my_project.id
  title                = "cluster_node_2"
  generate_soft_serial = true
}

resource "zedcloud_edgenode" "cluster_node_3" {
  name                 = "cluster_node_3"
  model_id             = zedcloud_model.my_model.id
  project_id           = zedcloud_project.my_project.id
  title                = "cluster_node_3"
  generate_soft_serial = true
}

resource "zedcloud_edgenode_cluster" "my_cluster" {
  project_id  = zedcloud_project.my_project.id
  name        = "my_cluster"
  title       = "my_cluster"
  description = "Three-node cluster"
  nodes {
    id                = zedcloud_edgenode.cluster_node_1.id
    cluster_interface = "ethernet0"
  }
  nodes {
    id                = zedcloud_edgenode.cluster_node_2.id
    cluster_interface = "ethernet0"
  }
  nodes {
    id                = zedcloud_edgenode.cluster_node_3.id
    cluster_interface = "ethernet0"
  }
}
```

For the full `zedcloud_edgenode_cluster` schema including all required and optional parameters, see the [Terraform Registry: ZEDEDA Cloud Node Cluster](https://registry.terraform.io/providers/zededa/zedcloud/latest/docs/resources/edgenode_cluster).

## Replace a Node in a Cluster

To replace a node in the cluster, update the node ID reference in the `zedcloud_edgenode_cluster` resource to point to the new node, then apply the configuration.

Original reference:

```text theme={"dark"}
nodes {
  id                = zedcloud_edgenode.cluster_node_original.id
  cluster_interface = "ethernet0"
}
```

Updated reference:

```text theme={"dark"}
nodes {
  id                = zedcloud_edgenode.cluster_node_replacement.id
  cluster_interface = "ethernet0"
}
```

Run `terraform plan` to preview the change, then `terraform apply` to apply it.

**Constraint:** You cannot add a node to or remove a node from a cluster. You can only replace an existing node.

## Delete a Cluster

To delete a cluster, remove the `zedcloud_edgenode_cluster` resource block from your Terraform configuration, then run `terraform apply`.

**Constraint:** You cannot delete a cluster if any application instance, network instance, or volume instance is running on a node in the cluster. Remove those resources first.

## Next Steps

> [card] [ZEDEDA Terraform Provider](https://zededa.mintlify.site/new-ui/infrastructure-services/integrations-and-automation/terraform-provider.md)
>
> Full provider setup, authentication, and common commands.

> [card] [Rename Terraform Objects](https://zededa.mintlify.site/new-ui/infrastructure-services/integrations-and-automation/rename-terraform-objects.md)
>
> Safely rename Terraform-managed resources without triggering unintended deletions.

> [card] [Terraform Registry: ZEDEDA Cloud Node Cluster](https://registry.terraform.io/providers/zededa/zedcloud/latest/docs/resources/edgenode_cluster)
>
> Full resource schema reference.
