Skip to content

Commit

Permalink
rename files
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenschneider committed Sep 9, 2024
1 parent 22edf2f commit 2b48b18
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 98 deletions.
23 changes: 3 additions & 20 deletions envs/vserver-2.ez.soeren.cloud/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 0 additions & 71 deletions envs/vserver-2.ez.soeren.cloud/main.tf

This file was deleted.

2 changes: 1 addition & 1 deletion envs/vserver-2.ez.soeren.cloud/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ datacenter = "ez"
vm_host = "vserver-2"

iso_urls = {
"debian-12" = "https://cdimage.debian.org/images/cloud/bookworm/20230723-1450/debian-12-generic-amd64-20230723-1450.qcow2"
"debian-12" = "https://cloud.debian.org/images/cloud/bookworm/20240901-1857/debian-12-generic-amd64-20240901-1857.qcow2"
}
29 changes: 29 additions & 0 deletions envs/vserver-2.ez.soeren.cloud/tf_locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
locals {
hosts_file = "~/src/github/ansible-inventory-prod/group_vars/all/hosts.yml"
hosts_yaml = file(local.hosts_file)
hosts_data = try(yamldecode(local.hosts_yaml), [])

ssh_pubkeys = distinct(compact(concat(try([chomp(file(var.ssh_public_key_file))], []), split(",", var.ssh_fallback_public_keys))))

defined_hosts = flatten([for hosts_key, hosts_value in local.hosts_data : [
for datacenter_key, datacenter_values in hosts_value : [
for host in datacenter_values : host if lookup(host, "physical", null) != null
] if datacenter_key == var.datacenter
] if hosts_key == "local_hosts"
])

hosts_macs = {
for host in local.defined_hosts :
host.host => host.physical
}

domains = {
for host in local.hosts_data.local_hosts[var.datacenter] :
host.host => host.vm_config
if try(host.vm_config.host, "") == var.vm_host && try(host.vm_config.disabled, false) == false
}

mac_domains = { for domain, val in local.domains :
domain => merge(val, { "mac" = lookup(val, "mac", null) != null ? val["mac"] : lookup(local.hosts_macs, domain, null) })
}
}
40 changes: 40 additions & 0 deletions envs/vserver-2.ez.soeren.cloud/tf_main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resource "libvirt_pool" "default" {
name = "default"
type = "dir"
path = "/var/lib/libvirt/images"
}

resource "libvirt_network" "bridge" {
name = "bridge"
mode = "bridge"
bridge = "br0"
autostart = true
}

resource "libvirt_volume" "base" {
for_each = var.iso_urls
name = "base-${each.key}"
source = each.value
format = "qcow2"
pool = libvirt_pool.default.name
}

module "domains" {
for_each = local.mac_domains
source = "../../domain-cloudinit"
domain_name = each.key

memory_m = each.value.memory
vcpus = each.value.vcpus
running = lookup(each.value, "running", true)
base_image_id = try(each.value.create_volume, false) ? libvirt_volume.base[each.value.os].id : null
block_devices = try(each.value.block_devices, [])
domain_mac = each.value.mac
create_volume = try(each.value.create_volume, false)
disk_size_bytes = each.value.disk_size_b

ssh_public_keys = local.ssh_pubkeys

pool_name = libvirt_pool.default.name
network_name = libvirt_network.bridge.name
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ terraform {
version = "0.7.6"
}
}

backend "s3" {
bucket = "soerenschneider-terraform"
key = "libvirt-prd-vserver-2.ez.soeren.cloud"
region = "us-east-1"
}
}

provider "libvirt" {
Expand Down
File renamed without changes.

0 comments on commit 2b48b18

Please sign in to comment.