# Adding a VM to a GPU cluster


In [GPU clusters](../../concepts/gpus.md#gpu-clusters), you can only create [VMs](../../concepts/vm.md) running on the [AMD EPYC™ with NVIDIA® Ampere® A100](../../concepts/vm-platforms.md#gpu-platforms) [platform](../../concepts/vm-platforms.md) with 8 GPUs. You will need to prepare a [disk](../../concepts/disk.md) [image](../../concepts/image.md) with drivers by following [this guide](../image-create/custom-image.md) and use it when creating your VM.


{% note info %}

Currently, GPU clusters are only available in the `ru-central1-a` and `ru-central1-d` [availability zones](../../../overview/concepts/geo-scope.md). You can only add a VM to a GPU cluster from the same availability zone.

{% endnote %}


{% list tabs group=instructions %}

- CLI {#cli}

  ```bash
  export YC_GPU_CLUSTER=$(yc compute gpu-cluster list --format=json | jq -r .[].id)
  export YC_ZONE="ru-central1-a"
  export SUBNET_NAME="my-subnet-name"
  export SUBNET_ID=$(yc vpc subnet get --name=$SUBNET_NAME --format=json | jq -r .id)
  yc compute instance create --name node-gpu-test \
    --create-boot-disk size=64G,image-id=<image_ID_with_drivers>,type=network-ssd \
    --ssh-key=$HOME/.ssh/id_rsa.pub \
    --gpus 8 --cores 224 --memory=952G \
    --zone $YC_ZONE \
    --network-interface subnet-id=$SUBNET_ID,nat-ip-version=ipv4 \
    --platform gpu-standard-v3 \
    --gpu-cluster-id=$YC_GPU_CLUSTER
  ```

- Terraform {#tf}

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../../terraform/authentication.md) using the appropriate method.

  1. In the Terraform configuration file, describe the resource you want to create:

     ```hcl
     provider "yandex" {
       zone = "ru-central1-a"
     }

     resource "yandex_compute_disk" "boot-disk" {
       name     = "<disk_name>"
       type     = "<disk_type>"
       zone     = "ru-central1-a"
       size     = "<disk_size>"
       image_id = "<image_ID_with_drivers>"
     }

     resource "yandex_compute_instance" "default" {
       name           = "vm-gpu"
       platform_id    = "gpu-standard-v3"
       zone           = "ru-central1-a"
       gpu_cluster_id = "<GPU_cluster_ID>"

       resources {
         cores  = "224"
         memory = "952"
         gpus   = "8"
       }

       boot_disk {
         disk_id = yandex_compute_disk.boot-disk.id
       }

       network_interface {
         subnet_id = "${yandex_vpc_subnet.subnet-1.id}"
         nat       = true
       }

       metadata = {
         user-data = "#cloud-config\nusers:\n  - name: <username>\n    groups: sudo\n    shell: /bin/bash\n    sudo: 'ALL=(ALL) NOPASSWD:ALL'\n    ssh_authorized_keys:\n      - ${file("<path_to_public_SSH_key>")}"
       }
     }

     resource "yandex_vpc_network" "network-1" {
       name = "network1"
     }

     resource "yandex_vpc_subnet" "subnet-1" {
       name           = "subnet1"
       zone           = "<availability_zone>"
       v4_cidr_blocks = ["192.168.10.0/24"]
       network_id     = "${yandex_vpc_network.network-1.id}"
     }
     ```

     Where:
     * `yandex_compute_disk`: Boot disk description, where `image_id` is the ID of the image with the drivers.
     * `gpu_cluster_id`: GPU cluster ID. This is a required setting.
     * `yandex_vpc_network`: [Cloud network](../../../vpc/concepts/network.md#network) description.
     * `yandex_vpc_subnet`: Description of the [subnet](../../../vpc/concepts/network.md#subnet) to create your VM in.

       {% note info %}

       If you already have suitable resources, such as a cloud network and subnet, you do not need to redefine them. Specify their names and IDs in the appropriate parameters.

       {% endnote %}

       For more information about `yandex_compute_instance` properties, see [this Terraform provider guide](../../../terraform/resources/compute_instance.md).
  1. Under `metadata`, specify your username and path to the public SSH key. For more information, see [VM metadata](../../concepts/vm-metadata.md).
  1. Create the resources:

      1. In the terminal, navigate to the configuration file directory.
      1. Make sure the configuration is correct using this command:
      
         ```bash
         terraform validate
         ```
      
         If the configuration is valid, you will get this message:
      
         ```bash
         Success! The configuration is valid.
         ```
      
      1. Run this command:
      
         ```bash
         terraform plan
         ```
      
         You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
      1. Apply the configuration changes:
      
         ```bash
         terraform apply
         ```
      
      1. Type `yes` and press **Enter** to confirm the changes.

  This will create a VM in the specified GPU cluster. You can check the new VM and its configuration using the [management console](https://console.yandex.cloud) or this [CLI](../../../cli/index.md) command:

  ```bash
  yc compute instance get <VM_name>
  ```

{% endlist %}