Przeglądaj źródła

terraform hetzner volumes

master
rodzic
commit
b6a013c8d5
3 zmienionych plików z 45 dodań i 7 usunięć
  1. +1
    -0
      .gitignore
  2. +7
    -1
      inventory_input.tf
  3. +37
    -6
      provider_hetzner.tf

+ 1
- 0
.gitignore Wyświetl plik

@@ -2,3 +2,4 @@
*.auto.tfvars
*.tfstate
*.tfstate.backup
inventory.json

+ 7
- 1
inventory_input.tf Wyświetl plik

@@ -1,6 +1,12 @@
variable "vm_hosts" {
default = {
"controller.testing.thengo.net" = { provider = "hetzner", groups = [ "controllers" ] }
"controller.testing.thengo.net" = {
provider = "hetzner"
groups = [ "controllers" ]
volumes = {
data = { size = 32 }
}
}
#"ns.testing.thengo.net" = { provider = "hetzner", groups = [ "nameservers" ] }
}
}


+ 37
- 6
provider_hetzner.tf Wyświetl plik

@@ -83,12 +83,38 @@ resource "hcloud_server" "vms" {
for_each = local.hetzner_vm_hosts
}

#resource "hcloud_server_network" "vms" {
# server_id = hcloud_server.vms[each.key].id
# network_id = hcloud_network.internal_network.id
#
# for_each = local.hetzner_vm_hosts
#}

# Volumes

locals {
hetzner_volumes = { for item in flatten([
for hostname, host in local.hetzner_vm_hosts: [
for volumename, volume in lookup(host, "volumes", {}): {
hostname = hostname
volumename = volumename
volume = volume
host = host
}
]
]): "${item.hostname}--${item.volumename}" => merge(item.volume,{hostname=item.hostname}) }
}

resource "hcloud_volume" "volumes" {
name = each.key

location = var.hetzner_default_location
size = each.value.size

for_each = local.hetzner_volumes
}

resource "hcloud_volume_attachment" "volume_attachments" {
volume_id = hcloud_volume.volumes[each.key].id
server_id = hcloud_server.vms[each.value.hostname].id
#automount = true
for_each = local.hetzner_volumes
}


# Provider Variable

@@ -100,6 +126,11 @@ locals {
external_ip = hcloud_server.vms[hostname].ipv4_address
ansible_host = hcloud_server.vms[hostname].ipv4_address
#internal_ip = hcloud_server_network.vms[hostname].ip
volumes = {
for volumename, volume in lookup(host, "volumes", {}): volumename => merge(volume,{
device = hcloud_volume.volumes["${hostname}--${volumename}"].linux_device
})
}
}
if host.provider == "hetzner"
}


Ładowanie…
Anuluj
Zapisz