You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728
  1. locals {
  2. volumes = { for item in flatten([
  3. for hostname, host in var.vms: [
  4. for volumename, volume in lookup(host, "volumes", {}): {
  5. hostname = hostname
  6. volumename = volumename
  7. volume = volume
  8. host = host
  9. }
  10. ]
  11. ]): "${item.hostname}--${item.volumename}" => merge(item.volume,{hostname=item.hostname}) }
  12. }
  13. resource "hcloud_volume" "volumes" {
  14. name = each.key
  15. location = var.default_location
  16. size = each.value.size
  17. for_each = local.volumes
  18. }
  19. resource "hcloud_volume_attachment" "volume_attachments" {
  20. volume_id = hcloud_volume.volumes[each.key].id
  21. server_id = hcloud_server.vms[each.value.hostname].id
  22. #automount = true
  23. for_each = local.volumes
  24. }