|
- locals {
- volumes = { for item in flatten([
- for hostname, host in var.vms: [
- 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.default_location
- size = each.value.size
-
- for_each = local.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.volumes
- }
|