Просмотр исходного кода

terraform hetzner volumes

master
Markus Katharina Brechtel 4 лет назад
Родитель
Сommit
b6a013c8d5
3 измененных файлов: 45 добавлений и 7 удалений
  1. +1
    -0
      .gitignore
  2. +7
    -1
      inventory_input.tf
  3. +37
    -6
      provider_hetzner.tf

+ 1
- 0
.gitignore Просмотреть файл

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

+ 7
- 1
inventory_input.tf Просмотреть файл

@@ -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 Просмотреть файл

@@ -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"
}


Загрузка…
Отмена
Сохранить