terraform-install | yandex-cli | terraform
mkdir -p ~/dev/cloud-terraform/ cd ~/dev/cloud-terraform/ vi providers.tf
terraform {
required_version = ">= 1.0.0"
required_providers {
yandex = {
source = "yandex-cloud/yandex"
}
}
}
–either– find your favorite image branch/family from the cli – BEWARE you need to increase output limit AFTER specifying folder-id
yc compute image list --format json --folder-id standard-images --limit 10000 | \
jq -r '.[] | select( .family == "debian-11-oslogin" )' | \
jq -r '.name + "," + .id + "," + .status' | sort -V | tail -5
yc compute image list --format json --folder-id standard-images --limit 10000 | \
jq -r '.[] | select( .family == "debian-12" )' | \
jq -r '.name + "," + .id + "," + .status ' | sort -V | tail -5
–or– just select one from the web console
Create instance Marketplace > search Debian
we want
standard-v3 (don't ask me why, it's cheaper than v1) 2 vCPU 1 GB RAM SSD 5GB garanteed 5% preemptible define service account os-login enabled login & ssh key serial console optional public ip
that is
resource "yandex_compute_disk" "boot-disk-1" {
name = "host1-disk"
type = "network-ssd"
zone = "ru-central1-b"
size = "5"
image_id = "fd8q49fvba72foa1ol22"
}
resource "yandex_compute_instance" "vm-1" {
name = "test-host1"
platform_id = "standard-v1"
zone = "ru-central1-b"
# changing hostname re-defines everything - avoid that here even for the first shot
#hostname = "host1"
resources {
cores = 2
memory = 1
core_fraction = 5
}
boot_disk {
disk_id = yandex_compute_disk.boot-disk-1.id
}
network_interface {
# test-ru-central1-b
subnet_id = "ZONE-B-SUBNET-ID-HERE"
# public ip unless you have access to the internal subnet
nat = false
}
metadata = {
# username does not matter, as it depends on the image
ssh-keys = "debian:OPENSSH-FORMAT-PUBKEY"
serial-port-enable = 1
# enable only once helper tools are installed
enable-oslogin = false
}
scheduling_policy {
preemptible = true
}
# some settings here need a compute node restart - ok for testing
allow_stopping_for_update = true
}
mkdir ~/dev/test-host1/ cd ~/dev/test-host1/ vi terragrunt.hcl
terragrunt init yc config profile list yc config profile activate test export YC_TOKEN=`yc iam create-token` export YC_CLOUD_ID=`yc config get cloud-id` export YC_FOLDER_ID=`yc config get folder-id` echo $YC_TOKEN echo $YC_CLOUD_ID echo $YC_FOLDER_ID terragrunt plan rm -f /tmp/ssh_privkey terragrunt apply
terraform import -no-color
https://yandex.cloud/en/docs/tutorials/infrastructure-management/terraform-quickstart#cli_1
https://yandex.cloud/en/docs/tutorials/infrastructure-management/terraform-modules
https://yandex.cloud/en/docs/tutorials/infrastructure-management/terraform-data-sources
https://terraform-provider.yandexcloud.net/Resources/compute_instance
https://terraform-provider.yandexcloud.net/Resources/organizationmanager_os_login_settings
https://github.com/yandex-cloud/terraform-provider-yandex
https://registry.terraform.io/providers/yandex-cloud/yandex/latest
https://spacelift.io/blog/importing-exisiting-infrastructure-into-terraform