1
0
Fork 0
yatf/slinvm/main.tf

61 lines
1.1 KiB
Terraform
Raw Permalink Normal View History

2025-11-24 03:23:49 +02:00
terraform {
required_providers {
yandex = {
source = "yandex-cloud/yandex"
}
}
}
provider "yandex" {
zone = "ru-central1-b"
}
resource "yandex_compute_instance" "vm" {
count = 1
name = "vm${count.index}"
platform_id = "standard-v1"
boot_disk {
initialize_params {
image_id = "fd87j6d92jlrbjqbl32q" # ubuntu 22.04
size = 8
}
}
network_interface {
subnet_id = yandex_vpc_subnet.subnet1.id
nat = true
}
resources {
cores = 2
memory = 2
}
metadata = {
ssh-keys = "ubuntu:${file("~/.ssh/id_ed25519.pub")}"
hostname = "slinvm"
}
}
resource "yandex_vpc_network" "network1" {
name = "network1"
}
resource "yandex_vpc_subnet" "subnet1" {
name = "subnet1"
v4_cidr_blocks = ["172.24.8.0/24"]
network_id = yandex_vpc_network.network1.id
}
resource "local_file" "ssh_connect" {
file_permission = "0755"
filename = "${path.module}/ssh_connect"
content = <<EOT
#!/usr/bin/env bash
%{for host in yandex_compute_instance.vm~}
${trimspace("exec ssh ubuntu@${host.network_interface.0.nat_ip_address}")}
%{endfor~}
EOT
}