Using this Terraform configuration, you will deploy an instance group with an autoscaling policy to apply if the load limit is exceeded.
VM instances will be deployed in two availability zones, with the load distributed using Yandex Network Load Balancer.
For more information about the provider resources, see the documentation on the Terraform website or its mirror.
If you modify the configuration files, Terraform automatically detects which part of your configuration is already deployed and what should be added or removed.
For a detailed tutorial, see Running an instance group with autoscaling.
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:
-
Clone the repository with Terraform configuration files:
git clone https://github.com/yandex-cloud-examples/yc-vm-group-with-autoscale.git
-
Go to the directory with the repository. Make sure it contains the following files:
vm-autoscale.tf: New infrastructure configuration.declaration.yaml: Description of the Docker container with a web server that will run on the VM to simulate load on the service.config.tpl: Description of VM user parameters.vm-autoscale.auto.tfvars: User data.
For more information about the parameters of resources used in Terraform, see the relevant provider documentation:
-
-
In the
vm-autoscale.auto.tfvarsfile, set the following user-defined properties:folder_id: Folder ID.vm_user: VM user name.ssh_key: Contents of the file with a public SSH key to authenticate the user on the VM. For details, see Creating an SSH key pair.
-
Create resources:
-
In the terminal, navigate to the directory containing the downloaded repository.
-
Make sure the configuration file is correct 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 will be made at this step. If there are errors in the configuration, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yesinto the terminal and press Enter.
-