1
0
Fork 0
yatf/main.tf

93 lines
1.7 KiB
Terraform
Raw Permalink Normal View History

2024-04-26 22:19:59 +03:00
terraform {
required_providers {
yandex = {
source = "yandex-cloud/yandex"
}
}
}
provider "yandex" {
zone = "ru-central1-b"
}
resource "yandex_compute_instance" "vm" {
count = 2
name = "vm${count.index}"
platform_id = "standard-v1"
boot_disk {
initialize_params {
image_id = "fd87j6d92jlrbjqbl32q" # ubuntu 22.04
size = 8
2024-04-26 22:19:59 +03:00
}
}
network_interface {
2024-09-25 13:50:17 +03:00
subnet_id = yandex_vpc_subnet.subnet1.id
2024-04-26 22:19:59 +03:00
nat = true
}
resources {
core_fraction = 5
cores = 2
memory = 2
}
2024-04-27 00:04:31 +03:00
metadata = { user-data = "${file("users.yml")}" }
}
2024-04-26 22:19:59 +03:00
2024-09-25 13:50:17 +03:00
resource "yandex_vpc_network" "network1" {
name = "network1"
2024-04-26 22:19:59 +03:00
}
2024-09-25 13:50:17 +03:00
resource "yandex_vpc_subnet" "subnet1" {
name = "subnet1"
2024-09-26 19:32:13 +03:00
v4_cidr_blocks = [ "172.24.8.0/24" ]
2024-09-25 13:50:17 +03:00
network_id = yandex_vpc_network.network1.id
2024-04-26 22:19:59 +03:00
}
2024-09-25 13:50:17 +03:00
resource "yandex_lb_target_group" "group1" {
name = "group1"
2024-04-26 22:19:59 +03:00
target {
2024-09-25 13:50:17 +03:00
subnet_id = yandex_vpc_subnet.subnet1.id
2024-04-26 22:19:59 +03:00
address = yandex_compute_instance.vm[0].network_interface.0.ip_address
}
target {
2024-09-25 13:50:17 +03:00
subnet_id = yandex_vpc_subnet.subnet1.id
2024-04-26 22:19:59 +03:00
address = yandex_compute_instance.vm[1].network_interface.0.ip_address
}
}
2024-09-25 13:50:17 +03:00
resource "yandex_lb_network_load_balancer" "balancer1" {
name = "balancer1"
2024-04-26 22:19:59 +03:00
deletion_protection = "false"
listener {
name = "my-lb1"
port = 80
external_address_spec {
ip_version = "ipv4"
}
}
attached_target_group {
2024-09-25 13:50:17 +03:00
target_group_id = yandex_lb_target_group.group1.id
2024-04-26 22:19:59 +03:00
healthcheck {
name = "http"
http_options {
port = 80
path = "/"
}
}
}
}
2024-04-27 00:04:31 +03:00
output "lb-ip" {
2024-09-25 13:50:17 +03:00
value = yandex_lb_network_load_balancer.balancer1.listener
2024-04-27 00:04:31 +03:00
}
output "vm-ips" {
value = tomap({
for name, vm in yandex_compute_instance.vm : name => vm.network_interface.0.nat_ip_address
})
}