[Yandex Cloud documentation](../../../index.md) > [Yandex Compute Cloud](../../index.md) > [Step-by-step guides](../index.md) > Creating an instance group > Creating an instance group attached to a reserved instance pool

# Creating an instance group from a Yandex Compute Cloud reserved instance pool.


{% note warning %}

Reserved instance pools are billable: you pay for the whole unused volume of reserved computing resources of VMs, GPU clusters, and software accelerated networks according to the [Yandex Compute Cloud pricing policy](../../pricing.md). For more information, see [Using reserved instance pools](../../pricing.md#pool).

{% endnote %}

_The reserved instance pool feature is at the [Preview stage](../../../overview/concepts/launch-stages.md)._

A _reserved instance pool_ is the total of computing resources reserved by the user in a given [availability zone](../../../overview/concepts/geo-scope.md) to secure their guaranteed availability to the user for the purpose of creating [VMs](../../concepts/vm.md) of a particular [configuration](../../concepts/performance-levels.md#available-configurations) in this availability zone.

You can use reserved pools for [instance groups](../../concepts/instance-groups/index.md). This guarantees the availability of resources for the instance group.

Reserved instance pools are incompatible with [dedicated hosts](../../concepts/dedicated-host.md), [preemptible VMs](../../concepts/preemptible-vm.md), and VMs with [vCPU performance levels](../../concepts/performance-levels.md) below 100%. At present, reserved instance pools do not support [placement groups](../../concepts/placement-groups.md).

Reserved instance pools are created in specific availability zones. To automate the distribution of multi-zone group instances across reserved instance pools of a specific availability zone, use the [instance template variables](../../concepts/instance-groups/variables-in-the-template.md).

For more information, see [Reserved instance pools in Compute Cloud](../../concepts/reserved-pools.md).

## Creating a group in a single availability zone with instances from a reserved instance pool in that zone {#single-zone}

1. [Create](../../../iam/operations/sa/create.md) a service account with the [compute.admin](../../security/index.md#compute-admin) role which the group will use to manage instances.
1. [Create](../reserved-pools/create-reserved-pool.md) a reserved instance pool with a configuration you want to use for the instance group.

    {% note info %}
    
    The configuration of the instance reserve pool must match the configuration of the instance group you want to create in terms of:
    * [Platform](../../concepts/vm-platforms.md)
    * Number of vCPUs
    * Amount of RAM
    * [Availability zone](../../../overview/concepts/geo-scope.md)
    
    The number of VMs in each availability zone must not exceed the size of the reserved instance pools in those zones.
    
    {% endnote %}

1. Create an instance group:

    {% list tabs group=instructions %}

    - CLI {#cli}

      If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

      The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

      1. Create the `specification.yaml` file containing the instance group specification, for example:

          ```yaml
          name: first-fixed-group
          service_account_id: <service_account_ID>
          instance_template:
            platform_id: standard-v4a
            resources_spec:
              memory: 2g
              cores: 2
            boot_disk_spec:
              mode: READ_WRITE
              disk_spec:
                image_id: fd83esfomhq25p2ono90
                type_id: network-hdd
                size: 20g
            network_interface_specs:
              - network_id: <network_ID>
                primary_v4_address_spec: {}
                subnet_ids:
                  - <subnet_ID>
                security_group_ids:
                  - <security_group_ID>
            reserved_instance_pool_id: <reserved_instance_pool_ID>
          deploy_policy:
            max_unavailable: 1
            max_expansion: 0
          scale_policy:
            fixed_scale:
              size: 3
          allocation_policy:
            zones:
              - zone_id: ru-central1-a
          ```

          Where:
          * `service_account_id`: [ID of the service account](../../../iam/operations/sa/get-id.md) you created earlier.
          * `network_id`: [Network ID](../../../vpc/operations/network-get-info.md).
          * `subnet_ids`: [Subnet ID](../../../vpc/operations/subnet-get-info.md).
          * `security_group_ids`: [Security group ID](../../../vpc/operations/security-group-get-info.md).
          * `reserved_instance_pool_id`: Reserved instance pool [ID](../../cli-ref/reserved-instance-pool/list.md) you created earlier.
          * `zone_id`: Availability zone.

          For more information about the instance group parameters, see [Specification of an instance group in YAML format](../../concepts/instance-groups/specification.md).

      1. Apply the specification by running this command in the terminal:

          ```bash
          yc compute instance-group create \
            --file specification.yaml
          ```

          For more information about this command, see the [CLI reference](../../cli-ref/instance-group/create.md).

    - 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 configuration file, describe the instance group parameters:

          ```hcl
          resource "yandex_compute_instance_group" "first-fixed-group" {
            name                = "first-fixed-group"
            service_account_id  = "<service_account_ID>"

            instance_template {
              platform_id = "standard-v4a"
              resources {
                memory = 2
                cores  = 2
              }

              boot_disk {
                mode = "READ_WRITE"
                initialize_params {
                  image_id = "fd83esfomhq25p2ono90"
                }
              }

              network_interface {
                network_id         = "<network_ID>"
                subnet_ids         = ["<subnet_ID>"]
                security_group_ids = ["<security_group_ID>"]
              }

              reserved_instance_pool_id = "<reserved_instance_pool_ID>"
            }

            scale_policy {
              fixed_scale {
                size = 3
              }
            }

            allocation_policy {
              zones = ["ru-central1-a"]
            }

            deploy_policy {
              max_unavailable = 1
              max_expansion   = 0
            }
          }
          ```

          Where:
          * `service_account_id`: [ID of the service account](../../../iam/operations/sa/get-id.md) you created earlier.
          * `network_id`: [Network ID](../../../vpc/operations/network-get-info.md).
          * `subnet_ids`: [Subnet ID](../../../vpc/operations/subnet-get-info.md).
          * `security_group_ids`: [Security group ID](../../../vpc/operations/security-group-get-info.md).
          * `reserved_instance_pool_id`: Reserved instance pool [ID](../../cli-ref/reserved-instance-pool/list.md) you created earlier.
          * `zones`: Availability zone.

          For more information about the instance group parameters, see [Specification of an instance group in YAML format](../../concepts/instance-groups/specification.md).

      1. Create an instance group:

          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.

      For more information about `yandex_compute_instance_group`, see [this Terraform reference](../../../terraform/resources/compute_instance_group.md).

    - API {#api}

      Use the [create](../../instancegroup/api-ref/InstanceGroup/create.md) REST API method for the [InstanceGroup](../../instancegroup/api-ref/InstanceGroup/index.md) resource or the [InstanceGroupService/Create](../../instancegroup/api-ref/grpc/InstanceGroup/create.md) gRPC API call.

      To specify the reserved pool, use the `instanceTemplate.reservedInstancePoolId` (`instance_template.reserved_instance_pool_id`) parameter.

    {% endlist %}

## Creating a group in three availability zones with VMs from the reserve pools of each zone {#multi-zone}

1. [Create](../../../iam/operations/sa/create.md) a service account with the [compute.admin](../../security/index.md#compute-admin) role which the group will use to manage instances.
1. [Create](../reserved-pools/create-reserved-pool.md) reserved instance pools in three availability zones using a configuration you want to use for the instance group.

    {% note info %}
    
    The configuration of the instance reserve pool must match the configuration of the instance group you want to create in terms of:
    * [Platform](../../concepts/vm-platforms.md)
    * Number of vCPUs
    * Amount of RAM
    * [Availability zone](../../../overview/concepts/geo-scope.md)
    
    The number of VMs in each availability zone must not exceed the size of the reserved instance pools in those zones.
    
    {% endnote %}

1. Create an instance group:

    {% list tabs group=instructions %}

    - CLI {#cli}

      If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

      The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

      1. Create the `specification.yaml` file containing the instance group specification, for example:

          ```yaml
          name: first-fixed-group
          service_account_id: <service_account_ID>
          variables:
            - key: pool_ru-central1-a
              value: <reserved_instance_pool_ID_in_zone_a>
            - key: pool_ru-central1-b
              value: <reserved_instance_pool_ID_in_zone_b>
            - key: pool_ru-central1-d
              value: <reserved_instance_pool_ID_in_zone_d>
          instance_template:
            platform_id: standard-v4a
            resources_spec:
              memory: 2g
              cores: 2
            boot_disk_spec:
              mode: READ_WRITE
              disk_spec:
                image_id: fd83esfomhq25p2ono90
                type_id: network-hdd
                size: 20g
            network_interface_specs:
              - network_id: <network_ID>
                primary_v4_address_spec: {}
                subnet_ids:
                  - <subnet_ID_in_zone_a>
                  - <subnet_ID_in_zone_b>
                  - <subnet_ID_in_zone_d>
                security_group_ids:
                  - <security_group_ID>
            reserved_instance_pool_id: "{pool_{instance.zone_id}}"
          deploy_policy:
            max_unavailable: 1
            max_expansion: 0
          scale_policy:
            fixed_scale:
              size: 3
          allocation_policy:
            zones:
              - zone_id: ru-central1-a
              - zone_id: ru-central1-b
              - zone_id: ru-central1-d
          ```

          Where:
          * `service_account_id`: [ID of the service account](../../../iam/operations/sa/get-id.md) you created earlier.
          * `network_id`: [Network ID](../../../vpc/operations/network-get-info.md).
          * `subnet_ids`: [Subnet IDs](../../../vpc/operations/subnet-get-info.md).
          * `security_group_ids`: [Security group ID](../../../vpc/operations/security-group-get-info.md).
          * `variables`: User-defined variables with [IDs of reserved instance pools](../../cli-ref/reserved-instance-pool/list.md) in different availability zones.
          * `reserved_instance_pool_id`: Reserved instance pool IDs you will get as a result of substituting the `instance.zone_id` [system variable](../../concepts/instance-groups/variables-in-the-template.md#first-stage) (availability zone of a specific instance) and the [user-defined variables](../../concepts/instance-groups/variables-in-the-template.md#second-stage) specified in the `variables` parameter.
          * `zone_id`: Availability zone.

          For more information about the instance group parameters, see [Specification of an instance group in YAML format](../../concepts/instance-groups/specification.md).

      1. Apply the specification by running this command in the terminal:

          ```bash
          yc compute instance-group create \
            --file specification.yaml
          ```

          For more information about this command, see the [CLI reference](../../cli-ref/instance-group/create.md).

    - 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 configuration file, describe the instance group parameters:

          ```hcl
          resource "yandex_compute_instance_group" "ig-1" {
            name                = "fixed-group"
            service_account_id  = "<service_account_ID>"

            # Variables for reserved instance pools
            variables = {
              pool_ru-central1-a = "<reserved_instance_pool_ID_in_zone_a>"
              pool_ru-central1-b = "<reserved_instance_pool_ID_in_zone_b>"
              pool_ru-central1-d = "<reserved_instance_pool_ID_in_zone_d>"
            }

            instance_template {
              platform_id = "standard-v4a"
              resources {
                memory = 2
                cores  = 2
              }

              boot_disk {
                mode = "READ_WRITE"
                initialize_params {
                  image_id = "fd83esfomhq25p2ono90"
                }
              }

              network_interface {
                network_id         = "<network_ID>"
                subnet_ids         = ["<subnet_ID_in_zone_a>", "<subnet_ID_in_zone_b", "<subnet_ID_in_zone_d>"]
                security_group_ids = ["<security_group_ID>"]
              }

              # instance.zone_id: System variable with the zone ID
              reserved_instance_pool_id = "{pool_{instance.zone_id}}"
            }

            scale_policy {
              fixed_scale {
                size = 3
              }
            }

            allocation_policy {
              zones = ["ru-central1-a", "ru-central1-b", "ru-central1-d"]
            }

            deploy_policy {
              max_unavailable = 1
              max_expansion   = 0
            }
          }
          ```

          Where:
          * `service_account_id`: [ID of the service account](../../../iam/operations/sa/get-id.md) you created earlier.
          * `network_id`: [Network ID](../../../vpc/operations/network-get-info.md).
          * `subnet_ids`: [Subnet IDs](../../../vpc/operations/subnet-get-info.md).
          * `security_group_ids`: [Security group ID](../../../vpc/operations/security-group-get-info.md).
          * `variables`: User-defined variables with [IDs of reserved instance pools](../../cli-ref/reserved-instance-pool/list.md) in different availability zones.
          * `reserved_instance_pool_id`: Reserved instance pool IDs you will get as a result of substituting the `instance.zone_id` [system variable](../../concepts/instance-groups/variables-in-the-template.md#first-stage) (availability zone of a specific instance) and the [user-defined variables](../../concepts/instance-groups/variables-in-the-template.md#second-stage) specified in the `variables` parameter.
          * `zones`: Availability zones.

          For more information about the instance group parameters, see [Specification of an instance group in YAML format](../../concepts/instance-groups/specification.md).

      1. Create an instance group:

          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.

      For more information about `yandex_compute_instance_group`, see [this Terraform reference](../../../terraform/resources/compute_instance_group.md).

    - API {#api}

      Use the [create](../../instancegroup/api-ref/InstanceGroup/create.md) REST API method for the [InstanceGroup](../../instancegroup/api-ref/InstanceGroup/index.md) resource or the [InstanceGroupService/Create](../../instancegroup/api-ref/grpc/InstanceGroup/create.md) gRPC API call.

      To specify the reserved pool, use the `instanceTemplate.reservedInstancePoolId` (`instance_template.reserved_instance_pool_id`) parameter.

      Variables are set in the `variables` parameter.

    {% endlist %}

### See also {#see-also}

* [Instance Groups concepts](../../concepts/instance-groups/index.md)
* [Reserved instance pools in Compute Cloud](../../concepts/reserved-pools.md)
* [Variables in an instance template](../../concepts/instance-groups/variables-in-the-template.md)