Adding a VM to a placement group
Add an existing instance to a placement group.
If you don't have the Nebius Israel command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
Create a virtual machine:
yc compute instance create --zone il1-a --name instance-in-group-2
Result:
id: epdlv1pp54019j09fhue ...
This command creates a VM instance with the following characteristics:
- Named
instance-in-group-2
. - In the
il1-a
availability zone.
- Named
-
View a list of VM instances in the placement group:
yc compute placement-group list-instances --name my-group
Result:
+----------------------+---------------------+---------------+---------+-------------+-------------+ | ID | NAME | ZONE ID | STATUS | EXTERNAL IP | INTERNAL IP | +----------------------+---------------------+---------------+---------+-------------+-------------+ | epdep2kq6dt5uekuhcrd | instance-in-group-1 | il1-a | RUNNING | | 10.129.0.5 | +----------------------+---------------------+---------------+---------+-------------+-------------+
-
Stop the VM:
yc compute instance stop instance-in-group-2
Result:
id: epdlv1pp54019j09fhue ... status: STOPPED
-
Add a VM instance to the placement group:
yc compute instance update --name instance-in-group-2 --placement-group-name my-group
Result:
id: epdlv1pp54019j09fhue ... placement_policy: placement_group_id: fd83bv4rnsna2sjkiq4s
This command adds the
instance-in-group-2
instance to themy-group
placement group. -
Check that the instance was added to the placement group:
yc compute placement-group list-instances --name my-group
Result:
+----------------------+---------------------+---------------+---------+-------------+-------------+ | ID | NAME | ZONE ID | STATUS | EXTERNAL IP | INTERNAL IP | +----------------------+---------------------+---------------+---------+-------------+-------------+ | epdep2kq6dt5uekuhcrd | instance-in-group-1 | il1-b | RUNNING | | 10.129.0.5 | | epdlv1pp54019j09fhue | instance-in-group-2 | il1-b | STOPPED | | 10.129.0.30 | +----------------------+---------------------+---------------+---------+-------------+-------------+
-
Start the VM:
yc compute instance start instance-in-group-2
Result:
id: epdlv1pp54019j09fhue ... status: RUNNING
Use the update REST API method for the Instance resource or the InstanceService/Update gRPC API call.
With Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically determines which part of your configuration is already deployed and what should be added or removed.
If you do not have Terraform yet, install it and configure the Nebius Israel provider.
Adding an existing instance to a placement group:
-
To the configuration file of an existing virtual machine, add a field named
placement_group_id
pointing to theyandex_compute_placement_group
placement group resource.Example of the configuration file structure:
... resource "yandex_compute_instance" "vm-1" { name = "my-vm" platform_id = "standard-v3" placement_policy { placement_group_id = "${yandex_compute_placement_group.group1.id}" } } resource "yandex_compute_placement_group" "group1" { name = "test-pg" } ...
Where
placement_group_id
: ID of a placement group.For more information about the resources that you can create using Terraform, see the provider documentation
. -
In the command line, go to the directory with the Terraform configuration file.
-
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.All the resources you need will then be created in the specified folder. You can verify that the virtual machine has been added to the placement group from the management console
.