Add monitoring auto-deployment

This commit is contained in:
Your Name
2026-09-19 13:13:47 +05:00
commit 86e1c44d85
16 changed files with 422 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
locals {
ssh_user = "ubuntu"
ssh_private_key = "~/.ssh/ssh-key-1789658954721"
}
resource "local_file" "ansible_host_vars" {
count = length(yandex_compute_instance.server)
filename = "${path.module}/../host_vars/${yandex_compute_instance.server[count.index].name}.yml"
directory_permission = "0755"
file_permission = "0644"
content = <<-EOT
ansible_host: "${yandex_compute_instance.server[count.index].network_interface.0.nat_ip_address}"
ansible_user: "${local.ssh_user}"
ansible_ssh_private_key_file: "${local.ssh_private_key}"
EOT
}
resource "local_file" "ansible_inventory" {
filename = "${path.module}/inventory.ini"
directory_permission = "0755"
file_permission = "0644"
content = templatefile("${path.module}/inventory.ini.tftpl", {
hosts = yandex_compute_instance.server[*].name
})
depends_on = [local_file.ansible_host_vars]
}
+5
View File
@@ -0,0 +1,5 @@
[servers]
general_server
%{ for host in hosts ~}
${host}
%{ endfor ~}
Binary file not shown.
+48
View File
@@ -0,0 +1,48 @@
data "yandex_compute_image" "ubuntu" {
family = "ubuntu-2204-lts"
}
resource "yandex_vpc_network" "main_network" {
name = "main-network"
}
resource "yandex_vpc_subnet" "main_subnet" {
name = "main-subnet"
zone = "ru-central1-a"
network_id = yandex_vpc_network.main_network.id
v4_cidr_blocks = ["192.168.10.0/24"]
}
resource "yandex_compute_instance" "server" {
count = 5
name = "server_${count.index + 1}"
platform_id = "standard-v3"
zone = "ru-central1-a"
resources {
cores = 2
memory = 2
}
boot_disk {
initialize_params {
image_id = data.yandex_compute_image.ubuntu.id
size = 15
}
}
network_interface {
subnet_id = yandex_vpc_subnet.main_subnet.id
nat = true
}
metadata = {
ssh-keys = "ubuntu:${file("~/.ssh/ssh-key-1789658954721.pub")}"
}
}
output "public_ips" {
description = "Публичные IP адреса созданных серверов"
value = yandex_compute_instance.server[*].network_interface.0.nat_ip_address
}
+14
View File
@@ -0,0 +1,14 @@
terraform {
required_providers {
yandex = {
source = "yandex-cloud/yandex"
}
}
required_version = ">= 0.13"
}
provider "yandex" {
service_account_key_file = "authorized_key.json"
cloud_id = "b1gl9hdpdr35i83uh5t5"
folder_id = "b1gbb5kej5tlskp8i5oq"
zone = "ru-central1-a"
}