-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use terragrunt, remove links
- Loading branch information
1 parent
1444a88
commit 251d275
Showing
16 changed files
with
336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
generate "backend" { | ||
path = "tf_backend.tf" | ||
if_exists = "overwrite_terragrunt" | ||
contents = <<EOF | ||
terraform { | ||
backend "s3" { | ||
bucket = "soerenschneider-terraform" | ||
key = "${replace(basename(get_repo_root()), "/^tf-/", "")}-${path_relative_to_include()}/terraform.tfstate" | ||
region = "us-east-1" | ||
encrypt = true | ||
} | ||
} | ||
EOF | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
provider_uri = "qemu+ssh://soeren@testserver.dd.soeren.cloud/system" | ||
datacenter = "dd" | ||
vm_host = "testserver" | ||
|
||
iso_urls = { | ||
"debian-12" = "https://cloud.debian.org/images/cloud/bookworm/20240901-1857/debian-12-generic-amd64-20240901-1857.qcow2" | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
locals { | ||
hosts_file = "~/src/gitlab/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) }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
required_providers { | ||
libvirt = { | ||
source = "dmacvicar/libvirt" | ||
version = "0.7.6" | ||
} | ||
} | ||
} | ||
|
||
provider "libvirt" { | ||
uri = var.provider_uri | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
variable "provider_uri" { | ||
description = "uri to the provider endpoint" | ||
type = string | ||
} | ||
|
||
variable "ssh_public_key_file" { | ||
description = "file that contains the ssh public key" | ||
type = string | ||
default = "~/.ssh/id_ed25519.pub" | ||
} | ||
|
||
variable "ssh_fallback_public_keys" { | ||
description = "ssh public key" | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "vm_host" { | ||
type = string | ||
description = "the name of this vm host" | ||
} | ||
|
||
variable "iso_urls" { | ||
description = "url to fetch debian iso from" | ||
type = map(string) | ||
} | ||
|
||
variable "datacenter" { | ||
type = string | ||
default = "" | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
locals { | ||
hosts_file = "~/src/gitlab/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) }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
locals { | ||
hosts_file = "~/src/gitlab/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) }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |