chore: small improvements

This commit is contained in:
ITQ
2025-12-26 15:41:30 +03:00
parent 8fa3647642
commit d07b051b9c
5 changed files with 109 additions and 46 deletions
+22 -25
View File
@@ -16,9 +16,11 @@ locals {
image_filename = "noble-server-cloudimg-amd64.img" # да, можно было и ссылку, но я не хочу, чтобы кто-то качал его
client_ip = "10.6.6.10"
server_ip = "10.6.6.20"
client_ip = "10.6.6.10/24"
server_ip = "10.6.6.20/24"
network_cidr = "10.6.6.0/24"
gateway = "10.6.6.1"
nameservers = "1.1.1.1"
mtu = 1500
cpu_per_node = 4
@@ -30,7 +32,7 @@ provider "libvirt" {
}
resource "libvirt_network" "default" {
name = "task5_default"
name = "net_research_default"
mode = "nat"
addresses = [local.network_cidr]
@@ -41,57 +43,53 @@ resource "libvirt_network" "default" {
local_only = false
forwarders {
address = "1.1.1.1"
}
hosts {
hostname = "client"
ip = local.client_ip
}
hosts {
hostname = "server"
ip = local.server_ip
address = local.nameservers
}
}
}
resource "libvirt_volume" "ubuntu_noble" {
name = "task5_ubuntu_noble"
name = "net_research_ubuntu_noble"
source = "${local.image_pool_folder}/${local.image_filename}"
}
resource "libvirt_volume" "client_image" {
name = "task5_client_image"
name = "net_research_client_image"
base_volume_id = libvirt_volume.ubuntu_noble.id
}
resource "libvirt_volume" "server_image" {
name = "task5_server_image"
name = "net_research_server_image"
base_volume_id = libvirt_volume.ubuntu_noble.id
}
data "template_file" "client_user_data" {
template = file("${path.module}/configs/cloud-init/client.yaml.tpl")
vars = {
hosts_file = base64encode(file("${path.module}/configs/hosts"))
hosts_file = base64encode(file("${path.module}/configs/hosts"))
ip = local.client_ip
gateway = local.gateway
nameservers = local.nameservers
}
}
data "template_file" "server_user_data" {
template = file("${path.module}/configs/cloud-init/server.yaml.tpl")
vars = {
nginx_conf = base64encode(file("${path.module}/configs/nginx/nginx.conf"))
tftpd_conf = base64encode(file("${path.module}/configs/tftpd/tftpd-hpa"))
caddy_conf = base64encode(file("${path.module}/configs/caddy/Caddyfile"))
hosts_file = base64encode(file("${path.module}/configs/hosts"))
nginx_conf = base64encode(file("${path.module}/configs/nginx/nginx.conf"))
tftpd_conf = base64encode(file("${path.module}/configs/tftpd/tftpd-hpa"))
caddy_conf = base64encode(file("${path.module}/configs/caddy/Caddyfile"))
hosts_file = base64encode(file("${path.module}/configs/hosts"))
ip = local.server_ip
gateway = local.gateway
nameservers = local.nameservers
}
}
module "client" {
source = "./modules/instance"
name = "task5_client"
name = "net_research_client"
network_id = libvirt_network.default.id
ip = local.client_ip
volume_base_id = libvirt_volume.ubuntu_noble.id
user_data = data.template_file.client_user_data.rendered
vcpu = local.cpu_per_node
@@ -100,9 +98,8 @@ module "client" {
module "server" {
source = "./modules/instance"
name = "task5_server"
name = "net_research_server"
network_id = libvirt_network.default.id
ip = local.server_ip
volume_base_id = libvirt_volume.ubuntu_noble.id
user_data = data.template_file.server_user_data.rendered
vcpu = local.cpu_per_node