Scheduled scaling of instance groups
Create a Yandex Compute Cloud instance group and set up scheduled scaling for it. A Yandex Cloud Functions function triggered by a timer will manage the instance group size.
To set up scaling for your instance group using standard tools, such as the management console, CLI, or API:
- Prepare your cloud.
- Create auxiliary resources.
- Create an instance group.
- Create Cloud Functions resources.
- Test instance group scaling.
If you no longer need the resources you created, delete them.
You can also deploy an infrastructure for scaling your instance group via Terraform using a ready-made configuration file.
Prepare your cloud
Sign up for Yandex Cloud and create a billing account:
- Go to the management console
and log in to Yandex Cloud or create an account if you do not have one yet. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not have a billing account, create one.
If you have an active billing account, you can go to the cloud page
Learn more about clouds and folders.
We will use a folder named example-folder
as an example.
Required paid resources
The infrastructure cost includes:
- Using a VM (see Compute Cloud pricing).
- Function calls, computing resources allocated to executing the function, and outgoing traffic (see Cloud Functions pricing).
Create auxiliary resources
Create a service account
The service account will be linked to the Compute Cloud instance group and Cloud Functions function.
- In the management console
, selectexample-folder
. - In the list of services, select Identity and Access Management.
- Click Create service account.
- In the Name field, specify
vm-scale-scheduled-sa
. - Click
Add role and select the following roles:compute.admin
: To manage the instance group.iam.serviceAccounts.user
: To link the service account to instances in the group.functions.functionInvoker
: To call the Cloud Functions function.
- Click Create.
-
Create a service account:
yc iam service-account create --name vm-scale-scheduled-sa \ --folder-name example-folder
Result:
id: ajeab0cnib1p******** folder_id: b0g12ga82bcv******** created_at: "2022-03-15T09:44:35.989446Z" name: vm-scale-scheduled-sa
For more information about the
yc iam service-account create
command, see the CLI reference. -
Assign the following roles to the service account:
-
compute.admin
: To manage the instance group:yc resource-manager folder add-access-binding example-folder \ --service-account-name vm-scale-scheduled-sa \ --role compute.admin \ --folder-name example-folder
-
iam.serviceAccounts.user
: To link the service account to instances in the group:yc resource-manager folder add-access-binding example-folder \ --service-account-name vm-scale-scheduled-sa \ --role iam.serviceAccounts.user \ --folder-name example-folder
-
functions.functionInvoker
: To call the Cloud Functions function:yc resource-manager folder add-access-binding example-folder \ --service-account-name vm-scale-scheduled-sa \ --role functions.functionInvoker \ --folder-name example-folder
For more information about the
yc resource-manager folder add-access-binding
command, see the CLI reference. -
See How to create an infrastructure using Terraform for details.
-
Create a service account named
vm-scale-scheduled-sa
. To do this, use the create REST API method for the ServiceAccount resource or the ServiceAccountService/Create gRPC API call. -
Assign the service account the following roles for the current folder:
compute.admin
: To manage the instance group.iam.serviceAccounts.user
: To link the service account to instances in the group.functions.functionInvoker
: To call the Cloud Functions function.
To do this, use the setAccessBindings REST API method for the Folder resource or the FolderService/SetAccessBindings gRPC API call.
See How to create an infrastructure using Terraform for details.
Create a cloud network
The instance group will be hosted in the Yandex Virtual Private Cloud cloud network and its subnets.
- In the management console
, select theexample-folder
folder. - In the list of services, select Virtual Private Cloud.
- At the top right, click Create network.
- In the Name field, specify
vm-scale-scheduled-network
. - Select Create subnets.
- Click Create network.
-
Create a network named
vm-scale-scheduled-network
:yc vpc network create --name vm-scale-scheduled-network \ --folder-name example-folder
Result:
id: enpabce123hd******** folder_id: b0g12ga82bcv******** created_at: "2022-03-15T09:55:50.004472Z" name: vm-scale-scheduled-network
For more information about the
yc vpc network create
command, see the CLI reference. -
Create a subnet named
vm-scale-scheduled-subnet-a
in theru-central1-a
availability zone:yc vpc subnet create --name vm-scale-scheduled-subnet-a \ --folder-name example-folder \ --network-name vm-scale-scheduled-network --range 192.168.1.0/24 \ --zone ru-central1-a
Result:
id: e1lnabc23r1c******** folder_id: b0g12ga82bcv******** created_at: "2022-03-15T09:56:51.859345Z" name: vm-scale-scheduled-subnet-a network_id: enpabce123hd******** zone_id: ru-central1-a v4_cidr_blocks: - 192.168.1.0/24
For more information about the
yc vpc subnet create
command, see the CLI reference. -
Create a subnet named
vm-scale-scheduled-network-b
in theru-central1-b
availability zone:yc vpc subnet create --name vm-scale-scheduled-subnet-b \ --folder-name example-folder \ --network-name vm-scale-scheduled-network --range 192.168.2.0/24 \ --zone ru-central1-b
Result:
id: b1csa2b3clid******** folder_id: b0g12ga82bcv******** created_at: "2022-03-15T09:57:48.934429Z" name: vm-scale-scheduled-subnet-b network_id: enpabce123hd******** zone_id: ru-central1-b v4_cidr_blocks: - 192.168.2.0/24
See How to create an infrastructure using Terraform for details.
- Create a network named
vm-scale-scheduled-network
using the create REST API method for the Network resource or the NetworkService/Create gRPC API call. - Create a subnet named
vm-scale-scheduled-subnet-a
in theru-central1-a
availability zone andvm-scale-scheduled-subnet-b
in theru-central1-b
availability zone using the create REST API method for the Subnet resource or the SubnetService/Create gRPC API call.
Create an instance group
An instance group will be created with manual scaling so that a Cloud Functions function can manage the group size.
- In the management console
, selectexample-folder
. - In the list of services, select Compute Cloud.
- In the left-hand panel, select
Instance groups. - At the top right, click Create group of virtual machines.
- Under Basic parameters:
- In the Name field, specify
vm-scale-scheduled-ig
. - Select Service account
vm-scale-scheduled-sa
.
- In the Name field, specify
- Under Allocation, select
ru-central1-a
andru-central1-b
in the Availability zone field. - Under Instance template, click Define and do the following in the window that opens:
- Under Boot disk image, select the Ubuntu 20.04 image.
- Under Computing resources, specify the following configuration:
- Platform:
Intel Ice Lake
. - vCPU:
2
. - Guaranteed vCPU performance:
20%
. - RAM:
2 GB
- Platform:
- Under Network settings:
- In the Network field, select
vm-scale-scheduled-network
. - In the Public address field, select
No address
.
- In the Network field, select
- Under Access:
- In the Service account field, select
vm-scale-scheduled-sa
. - In the Login field, enter the name of the user to be created on the VM. You can come up with any username you like.
- In the SSH key field, paste the contents of the public SSH key. You can create a key pair by following this guide.
- In the Service account field, select
- Click Save.
- Under Allow when creating and updating, specify the following configuration:
- Add above target value:
2
. - Reduce below target value:
2
. - Create simultaneously:
2
. - Stop simultaneously:
2
.
- Add above target value:
- Under Scaling:
- In the Type field, select
Fixed
. - Specify Size
2
.
- In the Type field, select
- Click Create.
-
Get the IDs of the resources you created at the previous steps:
-
vm-scale-scheduled-sa
service account ID:yc iam service-account get vm-scale-scheduled-sa \ --folder-name example-folder | grep "^id"
Result:
id: ajeab0cnib1p********
For more information about the
yc iam service-account get
command, see the CLI reference. -
vm-scale-scheduled-network
network ID:yc vpc network get vm-scale-scheduled-network \ --folder-name example-folder | grep "^id"
Result:
id: enpabce123hd********
For more information about the
yc vpc network get
command, see the CLI reference. -
vm-scale-scheduled-subnet-a
subnet ID:yc vpc subnet get vm-scale-scheduled-subnet-a \ --folder-name example-folder | grep "^id"
Result:
id: e1lnabc23r1c********
For more information about the
yc vpc subnet get
command, see the CLI reference. -
vm-scale-scheduled-subnet-b
subnet ID:yc vpc subnet get vm-scale-scheduled-subnet-b \ --folder-name example-folder | grep "^id"
Result:
id: b1csa2b3clid********
For more information about the
yc vpc subnet get
command, see the CLI reference.
-
-
Get the ID of the latest version of the Ubuntu 20.04 LTS public image:
yc compute image get-latest-from-family ubuntu-2004-lts \ --folder-id standard-images | grep "^id"
Result:
id: fd83n3uou8m0********
For more information about the
yc compute image get-latest-from-family
command, see the CLI reference. -
Insert the obtained IDs in the
specification.yaml
file with the VM group specification:name: vm-scale-scheduled-ig service_account_id: <service_ account_ID> allocation_policy: zones: - zone_id: ru-central1-a - zone_id: ru-central1-b instance_template: platform_id: standard-v3 resources_spec: memory: 2G cores: 2 core_fraction: 20 boot_disk_spec: mode: READ_WRITE disk_spec: type_id: network-hdd size: 15G image_id: <ID_of_Ubuntu_20.04_LTS_latest_version> network_interface_specs: - network_id: <network_ID> subnet_ids: - <subnet_ID_in_ru-central1-a_zone> - <subnet_ID_in_ru-central1-b_zone> primary_v4_address_spec: {} scale_policy: fixed_scale: size: 2 deploy_policy: max_unavailable: 2 max_creating: 2 max_expansion: 2 max_deleting: 2
-
Create an instance group named
vm-scale-scheduled-ig
based onspecification.yaml
:yc compute instance-group create --file specification.yaml \ --folder-name example-folder
Result:
done (2m18s) id: cl0kabcquk1g******** folder_id: b0g12ga82bcv******** ... service_account_id: ajeab0cnib1p******** status: ACTIVE
See How to create an infrastructure using Terraform for details.
-
Get the IDs of the resources you created at the previous steps:
vm-scale-scheduled-sa
service account ID: Using the get REST API method for the ServiceAccount resource or the ServiceAccountService/Get gRPC API call.vm-scale-scheduled-network
network ID: Using the get REST API method for the Network resource or the NetworkService/Get gRPC API call.vm-scale-scheduled-subnet-a
andvm-scale-scheduled-subnet-b
subnet IDs: Using the get REST API method for the Subnet resource or the SubnetService/Get gRPC API call.
-
Get the ID of the latest version of the public Ubuntu 20.04 image in the
standard-images
family using the getLatestByFamily REST API method for the Image resource or the ImageService/GetLatestByFamily gRPC API call. -
Insert the obtained IDs in the
specification.yaml
file with the VM group specification:name: vm-scale-scheduled-ig service_account_id: <service_ account_ID> allocation_policy: zones: - zone_id: ru-central1-a - zone_id: ru-central1-b instance_template: platform_id: standard-v3 resources_spec: memory: 2G cores: 2 core_fraction: 20 boot_disk_spec: mode: READ_WRITE disk_spec: type_id: network-hdd size: 15G image_id: <ID_of_Ubuntu_20.04_LTS_latest_version> network_interface_specs: - network_id: <network_ID> subnet_ids: - <subnet_ID_in_ru-central1-a_zone> - <subnet_ID_in_ru-central1-b_zone> primary_v4_address_spec: {} scale_policy: fixed_scale: size: 2 deploy_policy: max_unavailable: 2 max_creating: 2 max_expansion: 2 max_deleting: 2
-
Create an instance group named
vm-scale-scheduled-ig
based onspecification.yaml
. To do this, use the createFromYaml REST API method for the InstanceGroup resource or the InstanceGroupService/CreateFromYaml gRPC API call.
See How to create an infrastructure using Terraform for details.
Create Cloud Functions resources
Create a function
The function will contain the code with the Yandex Cloud CLI commands that update the instance group.
-
In the management console
, selectexample-folder
. -
Select Cloud Functions.
-
At the top right, click Create function.
-
In the Name field, specify
vm-scale-scheduled-function
. -
Click Create.
-
Select the Bash runtime environment.
-
Enable Add files with code examples.
-
Click Continue.
-
Under Editor, select the
handler.sh
file. -
Replace the file contents with the code below:
# Get ID and current size of the instance group IG_SPEC=$(yc compute instance-group get --name $IG_NAME --folder-id $FOLDER_ID --format json) IG_ID=$(jq -r ".id" <<< $IG_SPEC) IG_SIZE=$(jq -r ".scale_policy.fixed_scale.size" <<< $IG_SPEC) # Calculate new size for the instance group if [ $IG_SIZE = $IG_BASE_SIZE ]; then IG_SIZE="$(($IG_BASE_SIZE + 1))" else IG_SIZE=$IG_BASE_SIZE fi # Update the instance group yc compute instance-group update --id $IG_ID --scale-policy-fixed-scale-size $IG_SIZE
-
Under Parameters:
- Set the Timeout, sec field value to
60
. - In the Service account field, select
vm-scale-scheduled-sa
. - Under Environment variables, add the following variables:
IG_NAME
=vm-scale-scheduled-ig
.IG_BASE_SIZE
=2
.FOLDER_ID
= Folder ID. You can get the ID by following this guide.
- Set the Timeout, sec field value to
-
In the top-right corner, click Save changes.
-
Create a file named
config.pkr.hcl
with the following code:# Get ID and current size of the instance group IG_SPEC=$(yc compute instance-group get --name $IG_NAME --folder-id $FOLDER_ID --format json) IG_ID=$(jq -r ".id" <<< $IG_SPEC) IG_SIZE=$(jq -r ".scale_policy.fixed_scale.size" <<< $IG_SPEC) # Calculate new size for the instance group if [ $IG_SIZE = $IG_BASE_SIZE ]; then IG_SIZE="$(($IG_BASE_SIZE + 1))" else IG_SIZE=$IG_BASE_SIZE fi # Update the instance group yc compute instance-group update --id $IG_ID --scale-policy-fixed-scale-size $IG_SIZE
-
Create a function:
yc serverless function create vm-scale-scheduled-function \ --folder-name example-folder
Result:
done (1s) id: d4e7d67ikvmq******** folder_id: b1g9hv2loamq******** ... log_group_id: ckgij6l0845h******** http_invoke_url: https://functions.yandexcloud.net/d4e7d67ikvmq******** status: ACTIVE
-
Create a function version:
yc serverless function version create --folder-name example-folder \ --function-name vm-scale-scheduled-function --runtime bash \ --source-path ./handler.sh --entrypoint "handler.sh" \ --execution-timeout 60s \ --service-account-id <service_account_ID> \ --environment \ IG_NAME=vm-scale-scheduled-ig,IG_BASE_SIZE=2,FOLDER_ID=<folder_ID>
Where:
--service-account-id
:vm-scale-schedule-sa
service account ID. To get the ID, follow the Create a VM group step on the CLI tab.FOLDER_ID
in--environment
: Folder ID. You can get the ID by following this guide.
Result:
done (1s) id: d4efmv9n3qf1******** function_id: d4e7d67ikvmq******** ... FOLDER_ID: b1g9hv2loamq******** IG_BASE_SIZE: "2" IG_NAME: vm-scale-scheduled-ig
See How to create an infrastructure using Terraform for details.
-
Create a function named
vm-scale-scheduled-function
using the create REST API method for the Function resource or the FunctionService/Create gRPC API call. You can find the ID of the created function in the output. -
Create a function version using the createVersion REST API method for the Function resource or the FunctionService/CreateVersion gRPC API call. The function version should have the following code:
# Get ID and current size of the instance group IG_SPEC=$(yc compute instance-group get --name $IG_NAME --folder-id $FOLDER_ID --format json) IG_ID=$(jq -r ".id" <<< $IG_SPEC) IG_SIZE=$(jq -r ".scale_policy.fixed_scale.size" <<< $IG_SPEC) # Calculate new size for the instance group if [ $IG_SIZE = $IG_BASE_SIZE ]; then IG_SIZE="$(($IG_BASE_SIZE + 1))" else IG_SIZE=$IG_BASE_SIZE fi # Update the instance group yc compute instance-group update --id $IG_ID --scale-policy-fixed-scale-size $IG_SIZE
See How to create an infrastructure using Terraform for details.
Create a trigger
A trigger sets conditions for running a function. For scheduled function calls, use a timer trigger.
- In the management console
, selectexample-folder
. - Select Cloud Functions.
- In the left-hand panel, select
Triggers. - At the top right, click Create trigger.
- Under Basic settings:
- In the Name field, specify
vm-scale-scheduled-trigger
. - In the Type field, select
Timer
. - In the Launched resource field, select
Function
.
- In the Name field, specify
- Under Timer settings, in the Cron expression field, specify
*/2 * * * ? *
. The trigger will fire every two minutes, e.g., at 09:58, 10:00, 10:02, 10:04, etc. - Under Function settings:
- In the Function field, specify
vm-scale-scheduled-function
. - In the Function version tag field, select
$latest
. - Select Service account
vm-scale-scheduled-sa
.
- In the Function field, specify
- Under Dead Letter Queue settings, reset the Service account (
Not selected
) field. - Click Create trigger.
Run the following command:
yc serverless trigger create timer --folder-name example-folder \
--name vm-scale-scheduled-trigger \
--cron-expression "*/2 * * * ? *" \
--invoke-function-name vm-scale-scheduled-function \
--invoke-function-tag '$latest' \
--invoke-function-service-account-name vm-scale-scheduled-sa
Result:
id: a1s22pb0v5i4********
folder_id: b1g9hv2loamq********
created_at: "2022-04-06T14:56:54.253709098Z"
...
function_tag: $latest
service_account_id: aje9s4pud13h********
status: ACTIVE
See How to create an infrastructure using Terraform for details.
Use the create REST API method for the Trigger resource or the TriggerService/Create gRPC API call to create a trigger of the timer
type with the */2 * * * ? *
cron expression. This trigger will be linked with the vm-scale-scheduled-function
function of the $latest
version and the vm-scale-scheduled-sa
service account.
Test instance group scaling
- In the management console
, selectexample-folder
. - In the list of services, select Compute Cloud.
- In the left-hand panel, select
Instance groups. - Select the
vm-scale-scheduled-ig
group. - Under VM states, make sure the number of instances changes every two minutes: increases from 2 to 3, then decreases from 3 to 2, etc. You can also check if the instance group has been updated by opening the
Operations tab.
Run the following command several times:
yc compute instance-group get vm-scale-scheduled-ig \
--folder-name example-folder
Result:
id: cl1l0ljqbmkp********
folder_id: b1g9hv2loamq********
created_at: "2022-03-28T13:24:20.693Z"
...
managed_instances_state:
target_size: "2"
running_actual_count: "2"
...
The value of the target_size
field for the group should change from 2
to 3
and back.
Get information about the vm-scale-scheduled-ig
instance group multiple times using the get REST API method for the InstanceGroup resource or the InstanceGroupService/Get gRPC API call. The value of the target_size
field for the group should change from 2
to 3
and back.
How to delete the resources you created
To stop paying for the resources you created:
- Delete the
vm-scale-scheduled-trigger
trigger. - Delete the
vm-scale-scheduled-function
function. - Delete the
vm-scale-scheduled-ig
instance group.
How to create an infrastructure using Terraform
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
To set up scaling for your instance group using Terraform:
-
Install Terraform and specify the source for installing the Yandex Cloud provider (see Configure a provider, step 1).
-
Prepare files with the infrastructure description:
Ready-made archiveManually- Create a folder for files.
- Download the archive
(2 KB). - Unpack the archive to the directory. As a result, it should contain the
vm-scale-scheduled.tf
configuration file and thevm-scale-scheduled-function.zip
archive with the Cloud Functions function code.
-
Create a folder for files.
-
In the folder, create:
-
vm-scale-scheduled.tf
configuration filevm-scale-scheduled.tf
locals { token = "<OAuth_or_IAM_token>" cloud_id = "<cloud_ID>" folder_id = "<folder_ID>" username = "<VM_user_name>" ssh_key_path = "<path_to_public_SSH_key>" } terraform { required_providers { yandex = { source = "yandex-cloud/yandex" version = ">= 0.47.0" } } } provider "yandex" { token = local.token cloud_id = local.cloud_id folder_id = local.folder_id } resource "yandex_iam_service_account" "vm-scale-scheduled-sa" { name = "vm-scale-scheduled-sa" } resource "yandex_resourcemanager_folder_iam_member" "vm-scale-scheduled-sa-role-compute" { folder_id = "<folder_ID>" role = "compute.admin" member = "serviceAccount:${yandex_iam_service_account.vm-scale-scheduled-sa.id}" } resource "yandex_resourcemanager_folder_iam_member" "vm-scale-scheduled-sa-role-iam" { folder_id = "<folder_ID>" role = "iam.serviceAccounts.user" member = "serviceAccount:${yandex_iam_service_account.vm-scale-scheduled-sa.id}" } resource "yandex_resourcemanager_folder_iam_member" "vm-scale-scheduled-sa-role-functions" { folder_id = "<folder_ID>" role = "functions.functionInvoker" member = "serviceAccount:${yandex_iam_service_account.vm-scale-scheduled-sa.id}" } resource "yandex_vpc_network" "vm-scale-scheduled-network" { name = "vm-scale-scheduled-network" } resource "yandex_vpc_subnet" "vm-scale-scheduled-subnet-a" { name = "vm-scale-scheduled-subnet-a" zone = "ru-central1-a" v4_cidr_blocks = ["192.168.1.0/24"] network_id = yandex_vpc_network.vm-scale-scheduled-network.id } resource "yandex_vpc_subnet" "vm-scale-scheduled-subnet-b" { name = "vm-scale-scheduled-subnet-b" zone = "ru-central1-b" v4_cidr_blocks = ["192.168.2.0/24"] network_id = yandex_vpc_network.vm-scale-scheduled-network.id } resource "yandex_compute_image" "vm-scale-scheduled-image" { source_family = "ubuntu-2004-lts" } resource "yandex_compute_instance_group" "vm-scale-scheduled-ig" { name = "vm-scale-scheduled-ig" service_account_id = yandex_iam_service_account.vm-scale-scheduled-sa.id allocation_policy { zones = [ "ru-central1-a", "ru-central1-b" ] } instance_template { boot_disk { mode = "READ_WRITE" initialize_params { image_id = yandex_compute_image.vm-scale-scheduled-image.id size = 15 } } platform_id = "standard-v3" resources { cores = 2 core_fraction = 20 memory = 2 } network_interface { network_id = yandex_vpc_network.vm-scale-scheduled-network.id subnet_ids = [ yandex_vpc_subnet.vm-scale-scheduled-subnet-a.id, yandex_vpc_subnet.vm-scale-scheduled-subnet-b.id ] } metadata = { user-data = "#cloud-config\nusers:\n - name: ${local.username}\n groups: sudo\n shell: /bin/bash\n sudo: 'ALL=(ALL) NOPASSWD:ALL'\n ssh_authorized_keys:\n - ${file("${local.ssh_key_path}")}" } } scale_policy { fixed_scale { size = 2 } } deploy_policy { max_unavailable = 2 max_creating = 2 max_expansion = 2 max_deleting = 2 } depends_on = [ yandex_resourcemanager_folder_iam_member.vm-scale-scheduled-sa-role-compute, yandex_resourcemanager_folder_iam_member.vm-scale-scheduled-sa-role-iam ] } resource "yandex_function" "vm-scale-scheduled-function" { name = "vm-scale-scheduled-function" runtime = "bash" user_hash = "function-v1" entrypoint = "handler.sh" content { zip_filename = "vm-scale-scheduled-function.zip" } execution_timeout = "60" memory = "128" service_account_id = yandex_iam_service_account.vm-scale-scheduled-sa.id environment = { IG_NAME = yandex_compute_instance_group.vm-scale-scheduled-ig.name IG_BASE_SIZE = "2" FOLDER_ID = local.folder_id } depends_on = [ yandex_resourcemanager_folder_iam_member.vm-scale-scheduled-sa-role-functions ] } resource "yandex_function_trigger" "vm-scale-scheduled-trigger" { name = "vm-scale-scheduled-trigger" timer { cron_expression = "*/2 * * * ? *" } function { id = yandex_function.vm-scale-scheduled-function.id tag = "$latest" service_account_id = yandex_iam_service_account.vm-scale-scheduled-sa.id } depends_on = [ yandex_resourcemanager_folder_iam_member.vm-scale-scheduled-sa-role-functions ] }
-
handler.sh
file with the Cloud Functions function code:handler.sh
Warning
# Get ID and current size of the instance group IG_SPEC=$(yc compute instance-group get --name $IG_NAME --folder-id $FOLDER_ID --format json) IG_ID=$(jq -r ".id" <<< $IG_SPEC) IG_SIZE=$(jq -r ".scale_policy.fixed_scale.size" <<< $IG_SPEC) # Calculate new size for the instance group if [ $IG_SIZE = $IG_BASE_SIZE ]; then IG_SIZE="$(($IG_BASE_SIZE + 1))" else IG_SIZE=$IG_BASE_SIZE fi # Update the instance group yc compute instance-group update --id $IG_ID --scale-policy-fixed-scale-size $IG_SIZE
-
-
In the folder, create the
vm-scale-scheduled-function.zip
archive that contains thehandler.sh
file. Next, delete thehandler.sh
file outside the archive.
-
Under
vm-scale-scheduled.tf
, insert the following values in thelocals
section:token
: OAuth token (if you are using a Yandex account) or Yandex Identity and Access Management token (if you are using a Yandex account or federated account) to access Yandex Cloud. The Identity and Access Management token is valid for up to 12 hours but cannot exceed the federation cookie lifetime.cloud_id
: ID of the cloud to create the resources in.folder_id
: ID of the folder to create the resources in.username
: Name of the user to create in the VM. You can come up with any username you like.ssh_key_path
: Path to the file with a public SSH key to authenticate the user on the VM. You can create a key pair by following this guide.
-
Create resources:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
-