From 9f08d12bf0cc1ad3ea98c8759ec919648d53d163 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 13 Jan 2025 15:48:20 -0500 Subject: [PATCH 01/17] add volume_id as a parameter to volumes --- openstack/infrastructure.tf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index ecd79399..f1bc809e 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -98,7 +98,9 @@ resource "openstack_compute_instance_v2" "instances" { } resource "openstack_blockstorage_volume_v3" "volumes" { - for_each = module.design.volumes + for_each = { + for x, values in module.design.volumes : x => true if values.volume_id != undef + } name = "${var.cluster_name}-${each.key}" description = "${var.cluster_name} ${each.key}" size = each.value.size @@ -110,7 +112,7 @@ resource "openstack_blockstorage_volume_v3" "volumes" { resource "openstack_compute_volume_attach_v2" "attachments" { for_each = module.design.volumes instance_id = openstack_compute_instance_v2.instances[each.value.instance].id - volume_id = openstack_blockstorage_volume_v3.volumes[each.key].id + volume_id = try(each.value.volume_id, openstack_blockstorage_volume_v3.volumes[each.key].id) } locals { From 397d50efddcad9b34fcb7a59ff27a6cfbcac6c02 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 13 Jan 2025 16:05:51 -0500 Subject: [PATCH 02/17] try with cluster_name and instance name as prefix for volume_id --- openstack/infrastructure.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index f1bc809e..4023a6f2 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -112,7 +112,7 @@ resource "openstack_blockstorage_volume_v3" "volumes" { resource "openstack_compute_volume_attach_v2" "attachments" { for_each = module.design.volumes instance_id = openstack_compute_instance_v2.instances[each.value.instance].id - volume_id = try(each.value.volume_id, openstack_blockstorage_volume_v3.volumes[each.key].id) + volume_id = try("${var.cluster_name}-${each.value.instance}-${each.value.volume_id}", openstack_blockstorage_volume_v3.volumes[each.key].id) } locals { From fb16bbabf8215be67a1245881d96a4b5950ebd51 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 13 Jan 2025 16:26:33 -0500 Subject: [PATCH 03/17] test if the structure defines volume_id --- openstack/infrastructure.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index 4023a6f2..379b95a3 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -99,7 +99,7 @@ resource "openstack_compute_instance_v2" "instances" { resource "openstack_blockstorage_volume_v3" "volumes" { for_each = { - for x, values in module.design.volumes : x => true if values.volume_id != undef + for x, values in module.design.volumes : x => true if !contains(keys(values), "volume_id") } name = "${var.cluster_name}-${each.key}" description = "${var.cluster_name} ${each.key}" From 5ac995ec7228898886a1f2d031d3ca1d8dfb4c36 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 13 Jan 2025 16:30:11 -0500 Subject: [PATCH 04/17] use values for values --- openstack/infrastructure.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index 379b95a3..af0fc1dc 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -99,7 +99,7 @@ resource "openstack_compute_instance_v2" "instances" { resource "openstack_blockstorage_volume_v3" "volumes" { for_each = { - for x, values in module.design.volumes : x => true if !contains(keys(values), "volume_id") + for x, values in module.design.volumes : x => values if !contains(keys(values), "volume_id") } name = "${var.cluster_name}-${each.key}" description = "${var.cluster_name} ${each.key}" From 1c667648022220868f15b4f1083f471d443859c3 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 13 Jan 2025 16:33:36 -0500 Subject: [PATCH 05/17] add lookup for existing volumes --- openstack/infrastructure.tf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index af0fc1dc..048da089 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -108,6 +108,12 @@ resource "openstack_blockstorage_volume_v3" "volumes" { snapshot_id = lookup(each.value, "snapshot", null) enable_online_resize = lookup(each.value, "enable_resize", false) } +data "openstack_blockstorage_volume_v3" "volumes" { + for_each = { + for x, values in module.design.volumes : x => values if contains(keys(values), "volume_id") + } + name = "${var.cluster_name}-${each.key}" +} resource "openstack_compute_volume_attach_v2" "attachments" { for_each = module.design.volumes From b016a0ac7274990203e261bcfd42d17c0911d887 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 13 Jan 2025 16:37:28 -0500 Subject: [PATCH 06/17] rename data to existing_volumes --- openstack/infrastructure.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index 048da089..ec8f7bb8 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -108,7 +108,7 @@ resource "openstack_blockstorage_volume_v3" "volumes" { snapshot_id = lookup(each.value, "snapshot", null) enable_online_resize = lookup(each.value, "enable_resize", false) } -data "openstack_blockstorage_volume_v3" "volumes" { +data "openstack_blockstorage_volume_v3" "existing_volumes" { for_each = { for x, values in module.design.volumes : x => values if contains(keys(values), "volume_id") } @@ -143,7 +143,7 @@ locals { pv_key => { for name, specs in pv_values: name => merge( - { glob = "/dev/disk/by-id/*${substr(openstack_blockstorage_volume_v3.volumes["${x}-${pv_key}-${name}"].id, 0, 20)}" }, + { glob = try("/dev/disk/by-id/*${substr(openstack_blockstorage_volume_v3.existing_volumes["${x}-${pv_key}-${name}"].id, 0, 20)}", "/dev/disk/by-id/*${substr(openstack_blockstorage_volume_v3.volumes["${x}-${pv_key}-${name}"].id, 0, 20)}") }, specs, ) } if contains(values.tags, pv_key) From 3aa4b0e78cf40e2924f0066da4d126923903747b Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 13 Jan 2025 16:39:34 -0500 Subject: [PATCH 07/17] use data source --- openstack/infrastructure.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index ec8f7bb8..d45d92b6 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -143,7 +143,7 @@ locals { pv_key => { for name, specs in pv_values: name => merge( - { glob = try("/dev/disk/by-id/*${substr(openstack_blockstorage_volume_v3.existing_volumes["${x}-${pv_key}-${name}"].id, 0, 20)}", "/dev/disk/by-id/*${substr(openstack_blockstorage_volume_v3.volumes["${x}-${pv_key}-${name}"].id, 0, 20)}") }, + { glob = try("/dev/disk/by-id/*${substr(data.openstack_blockstorage_volume_v3.existing_volumes["${x}-${pv_key}-${name}"].id, 0, 20)}", "/dev/disk/by-id/*${substr(openstack_blockstorage_volume_v3.volumes["${x}-${pv_key}-${name}"].id, 0, 20)}") }, specs, ) } if contains(values.tags, pv_key) From 612d49e432d4d84e993de9fd82ecd0a406346b6d Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 13 Jan 2025 16:47:06 -0500 Subject: [PATCH 08/17] use managed keyword true/false instead of defining volume_id, default to managed --- openstack/infrastructure.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index d45d92b6..28a9d72a 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -99,7 +99,7 @@ resource "openstack_compute_instance_v2" "instances" { resource "openstack_blockstorage_volume_v3" "volumes" { for_each = { - for x, values in module.design.volumes : x => values if !contains(keys(values), "volume_id") + for x, values in module.design.volumes : x => values if lookup(values, 'managed', true) } name = "${var.cluster_name}-${each.key}" description = "${var.cluster_name} ${each.key}" @@ -110,7 +110,7 @@ resource "openstack_blockstorage_volume_v3" "volumes" { } data "openstack_blockstorage_volume_v3" "existing_volumes" { for_each = { - for x, values in module.design.volumes : x => values if contains(keys(values), "volume_id") + for x, values in module.design.volumes : x => values if ! lookup(values, 'managed', true) } name = "${var.cluster_name}-${each.key}" } @@ -143,7 +143,7 @@ locals { pv_key => { for name, specs in pv_values: name => merge( - { glob = try("/dev/disk/by-id/*${substr(data.openstack_blockstorage_volume_v3.existing_volumes["${x}-${pv_key}-${name}"].id, 0, 20)}", "/dev/disk/by-id/*${substr(openstack_blockstorage_volume_v3.volumes["${x}-${pv_key}-${name}"].id, 0, 20)}") }, + { glob = try("/dev/disk/by-id/*${substr(openstack_blockstorage_volume_v3.volumes["${x}-${pv_key}-${name}"].id, 0, 20)}", "/dev/disk/by-id/*${substr(data.openstack_blockstorage_volume_v3.existing_volumes["${x}-${pv_key}-${name}"].id, 0, 20)}") }, specs, ) } if contains(values.tags, pv_key) From fd153a80a84814e60c6344940ad591fcd9308d27 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 13 Jan 2025 16:48:08 -0500 Subject: [PATCH 09/17] use double quotes --- openstack/infrastructure.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index 28a9d72a..bc397c18 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -99,7 +99,7 @@ resource "openstack_compute_instance_v2" "instances" { resource "openstack_blockstorage_volume_v3" "volumes" { for_each = { - for x, values in module.design.volumes : x => values if lookup(values, 'managed', true) + for x, values in module.design.volumes : x => values if lookup(values, "managed", true) } name = "${var.cluster_name}-${each.key}" description = "${var.cluster_name} ${each.key}" @@ -110,7 +110,7 @@ resource "openstack_blockstorage_volume_v3" "volumes" { } data "openstack_blockstorage_volume_v3" "existing_volumes" { for_each = { - for x, values in module.design.volumes : x => values if ! lookup(values, 'managed', true) + for x, values in module.design.volumes : x => values if ! lookup(values, "managed", true) } name = "${var.cluster_name}-${each.key}" } From d3dab7c6769413b0d8435eee501baa4e7e4fbf1e Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 13 Jan 2025 16:52:47 -0500 Subject: [PATCH 10/17] use data structure for existing volumes --- openstack/infrastructure.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index bc397c18..048e658d 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -118,7 +118,7 @@ data "openstack_blockstorage_volume_v3" "existing_volumes" { resource "openstack_compute_volume_attach_v2" "attachments" { for_each = module.design.volumes instance_id = openstack_compute_instance_v2.instances[each.value.instance].id - volume_id = try("${var.cluster_name}-${each.value.instance}-${each.value.volume_id}", openstack_blockstorage_volume_v3.volumes[each.key].id) + volume_id = try(openstack_blockstorage_volume_v3.volumes[each.key].id, data.openstack_blockstorage_volume_v3.existing_volumes[each.key]) } locals { From 28a89a510e9ffed04e79339378edfa30626c1f7e Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 13 Jan 2025 16:54:13 -0500 Subject: [PATCH 11/17] use id for data --- openstack/infrastructure.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index 048e658d..6a2e0b49 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -118,7 +118,7 @@ data "openstack_blockstorage_volume_v3" "existing_volumes" { resource "openstack_compute_volume_attach_v2" "attachments" { for_each = module.design.volumes instance_id = openstack_compute_instance_v2.instances[each.value.instance].id - volume_id = try(openstack_blockstorage_volume_v3.volumes[each.key].id, data.openstack_blockstorage_volume_v3.existing_volumes[each.key]) + volume_id = try(openstack_blockstorage_volume_v3.volumes[each.key].id, data.openstack_blockstorage_volume_v3.existing_volumes[each.key].id) } locals { From d531f99c64734c2b9e9968868f9fd6bbac6801e1 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Tue, 14 Jan 2025 10:59:04 -0500 Subject: [PATCH 12/17] prevent destroying the volume is managed = false --- openstack/infrastructure.tf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index 6a2e0b49..7962bd58 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -107,6 +107,9 @@ resource "openstack_blockstorage_volume_v3" "volumes" { volume_type = lookup(each.value, "type", null) snapshot_id = lookup(each.value, "snapshot", null) enable_online_resize = lookup(each.value, "enable_resize", false) + lifecycle { + prevent_destroy = ! lookup(values, "managed", true) + } } data "openstack_blockstorage_volume_v3" "existing_volumes" { for_each = { From 64416302ce86db3148560f5854a9fc22766fe579 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Tue, 14 Jan 2025 13:10:44 -0500 Subject: [PATCH 13/17] lifecycle prevent_destroy can't be dynamic --- openstack/infrastructure.tf | 3 --- 1 file changed, 3 deletions(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index 7962bd58..6a2e0b49 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -107,9 +107,6 @@ resource "openstack_blockstorage_volume_v3" "volumes" { volume_type = lookup(each.value, "type", null) snapshot_id = lookup(each.value, "snapshot", null) enable_online_resize = lookup(each.value, "enable_resize", false) - lifecycle { - prevent_destroy = ! lookup(values, "managed", true) - } } data "openstack_blockstorage_volume_v3" "existing_volumes" { for_each = { From 7d90b204927ce2d1e14138451ca73cba7cb3ecb7 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Tue, 14 Jan 2025 14:48:06 -0500 Subject: [PATCH 14/17] adjust spacing --- openstack/infrastructure.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openstack/infrastructure.tf b/openstack/infrastructure.tf index 6a2e0b49..12d3b647 100644 --- a/openstack/infrastructure.tf +++ b/openstack/infrastructure.tf @@ -109,10 +109,10 @@ resource "openstack_blockstorage_volume_v3" "volumes" { enable_online_resize = lookup(each.value, "enable_resize", false) } data "openstack_blockstorage_volume_v3" "existing_volumes" { - for_each = { + for_each = { for x, values in module.design.volumes : x => values if ! lookup(values, "managed", true) } - name = "${var.cluster_name}-${each.key}" + name = "${var.cluster_name}-${each.key}" } resource "openstack_compute_volume_attach_v2" "attachments" { From 547e07bd455d432e03447f95bcb1af31c0d6ca63 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Tue, 14 Jan 2025 14:48:40 -0500 Subject: [PATCH 15/17] implement (un)managed volumes for aws, gcp and azure --- aws/infrastructure.tf | 18 +++++++++++++++--- azure/infrastructure.tf | 13 +++++++++++-- gcp/infrastructure.tf | 14 +++++++++++--- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/aws/infrastructure.tf b/aws/infrastructure.tf index 60443dd3..1616f186 100644 --- a/aws/infrastructure.tf +++ b/aws/infrastructure.tf @@ -130,7 +130,9 @@ resource "aws_instance" "instances" { } resource "aws_ebs_volume" "volumes" { - for_each = module.design.volumes + for_each = { + for x, values in module.design.volumes : x => values if lookup(values, "managed", true) + } availability_zone = local.availability_zone size = each.value.size type = lookup(each.value, "type", null) @@ -140,6 +142,16 @@ resource "aws_ebs_volume" "volumes" { Name = "${var.cluster_name}-${each.key}" } } +data "aws_ebs_volume" "existing_volumes" { + for_each = { + for x, values in module.design.volumes : x => values if ! lookup(values, "managed", true) + } + + filter { + name = "tag:Name" + values = ["${var.cluster_name}-${each.key}"] + } +} locals { device_names = [ @@ -151,7 +163,7 @@ locals { resource "aws_volume_attachment" "attachments" { for_each = module.design.volumes device_name = local.device_names[index(module.design.volume_per_instance[each.value.instance], replace(each.key, "${each.value.instance}-", ""))] - volume_id = aws_ebs_volume.volumes[each.key].id + volume_id = try(aws_ebs_volume.volumes[each.key].id, aws_ebs_volume.existing_volumes[each.key].id) instance_id = aws_instance.instances[each.value.instance].id skip_destroy = true } @@ -175,7 +187,7 @@ locals { pv_key => { for name, specs in pv_values: name => merge( - { glob = "/dev/disk/by-id/*${replace(aws_ebs_volume.volumes["${x}-${pv_key}-${name}"].id, "-", "")}" }, + { glob = try("/dev/disk/by-id/*${replace(aws_ebs_volume.volumes["${x}-${pv_key}-${name}"].id, "-", "")}", "/dev/disk/by-id/*${replace(aws_ebs_volume.existing_volumes["${x}-${pv_key}-${name}"].id, "-", "")}") }, specs, ) } if contains(values.tags, pv_key) diff --git a/azure/infrastructure.tf b/azure/infrastructure.tf index 0d1f9ff1..ee30db56 100644 --- a/azure/infrastructure.tf +++ b/azure/infrastructure.tf @@ -128,7 +128,9 @@ resource "azurerm_linux_virtual_machine" "instances" { } resource "azurerm_managed_disk" "volumes" { - for_each = module.design.volumes + for_each = { + for x, values in module.design.volumes : x => values if lookup(values, "managed", true) + } name = format("%s-%s", var.cluster_name, each.key) location = var.location resource_group_name = local.resource_group_name @@ -136,10 +138,17 @@ resource "azurerm_managed_disk" "volumes" { create_option = "Empty" disk_size_gb = each.value.size } +data "azurerm_managed_disk" "existing_volumes" { + for_each = { + for x, values in module.design.volumes : x => values if ! lookup(values, "managed", true) + } + name = format("%s-%s", var.cluster_name, each.key) + resource_group_name = local.resource_group_name +} resource "azurerm_virtual_machine_data_disk_attachment" "attachments" { for_each = module.design.volumes - managed_disk_id = azurerm_managed_disk.volumes[each.key].id + managed_disk_id = try(azurerm_managed_disk.volumes[each.key].id, azurerm_managed_disk.existing_volumes[each.key].id) virtual_machine_id = azurerm_linux_virtual_machine.instances[each.value.instance].id lun = index(module.design.volume_per_instance[each.value.instance], replace(each.key, "${each.value.instance}-", "")) caching = "ReadWrite" diff --git a/gcp/infrastructure.tf b/gcp/infrastructure.tf index 8dc7f9d5..07efbc0f 100644 --- a/gcp/infrastructure.tf +++ b/gcp/infrastructure.tf @@ -143,17 +143,25 @@ resource "google_compute_instance" "instances" { } resource "google_compute_disk" "volumes" { - for_each = module.design.volumes + for_each = { + for x, values in module.design.volumes : x => values if lookup(values, "managed", true) + } name = "${var.cluster_name}-${each.key}" type = lookup(each.value, "type", "pd-standard") zone = local.zone size = each.value.size } +data "google_compute_disk" "existing_volumes" { + for_each = { + for x, values in module.design.volumes : x => values if ! lookup(values, "managed", true) + } + name = "${var.cluster_name}-${each.key}" +} resource "google_compute_attached_disk" "attachments" { for_each = module.design.volumes - disk = google_compute_disk.volumes[each.key].self_link - device_name = google_compute_disk.volumes[each.key].name + disk = try(google_compute_disk.volumes[each.key].self_link, google_compute_disk.existing_volumes[each.key].self_link) + device_name = try(google_compute_disk.volumes[each.key].name, google_compute_disk.existing_volumes[each.key].name) mode = "READ_WRITE" instance = google_compute_instance.instances[each.value.instance].self_link } From 78b7ba8c0494942219ccc467e20f49247b424fcd Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Wed, 15 Jan 2025 09:35:39 -0500 Subject: [PATCH 16/17] fix existing_volumes to use data.aws_ebs_volume --- aws/infrastructure.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/infrastructure.tf b/aws/infrastructure.tf index 1616f186..6d631862 100644 --- a/aws/infrastructure.tf +++ b/aws/infrastructure.tf @@ -163,7 +163,7 @@ locals { resource "aws_volume_attachment" "attachments" { for_each = module.design.volumes device_name = local.device_names[index(module.design.volume_per_instance[each.value.instance], replace(each.key, "${each.value.instance}-", ""))] - volume_id = try(aws_ebs_volume.volumes[each.key].id, aws_ebs_volume.existing_volumes[each.key].id) + volume_id = try(aws_ebs_volume.volumes[each.key].id, data.aws_ebs_volume.existing_volumes[each.key].id) instance_id = aws_instance.instances[each.value.instance].id skip_destroy = true } @@ -187,7 +187,7 @@ locals { pv_key => { for name, specs in pv_values: name => merge( - { glob = try("/dev/disk/by-id/*${replace(aws_ebs_volume.volumes["${x}-${pv_key}-${name}"].id, "-", "")}", "/dev/disk/by-id/*${replace(aws_ebs_volume.existing_volumes["${x}-${pv_key}-${name}"].id, "-", "")}") }, + { glob = try("/dev/disk/by-id/*${replace(aws_ebs_volume.volumes["${x}-${pv_key}-${name}"].id, "-", "")}", "/dev/disk/by-id/*${replace(data.aws_ebs_volume.existing_volumes["${x}-${pv_key}-${name}"].id, "-", "")}") }, specs, ) } if contains(values.tags, pv_key) From 518d9789971828d6635fe756f9a86d45fd2c465b Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Wed, 15 Jan 2025 09:37:58 -0500 Subject: [PATCH 17/17] fix data for azure and gcp too --- azure/infrastructure.tf | 2 +- gcp/infrastructure.tf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/azure/infrastructure.tf b/azure/infrastructure.tf index ee30db56..1cef1c65 100644 --- a/azure/infrastructure.tf +++ b/azure/infrastructure.tf @@ -148,7 +148,7 @@ data "azurerm_managed_disk" "existing_volumes" { resource "azurerm_virtual_machine_data_disk_attachment" "attachments" { for_each = module.design.volumes - managed_disk_id = try(azurerm_managed_disk.volumes[each.key].id, azurerm_managed_disk.existing_volumes[each.key].id) + managed_disk_id = try(azurerm_managed_disk.volumes[each.key].id, data.azurerm_managed_disk.existing_volumes[each.key].id) virtual_machine_id = azurerm_linux_virtual_machine.instances[each.value.instance].id lun = index(module.design.volume_per_instance[each.value.instance], replace(each.key, "${each.value.instance}-", "")) caching = "ReadWrite" diff --git a/gcp/infrastructure.tf b/gcp/infrastructure.tf index 07efbc0f..22cf7518 100644 --- a/gcp/infrastructure.tf +++ b/gcp/infrastructure.tf @@ -160,8 +160,8 @@ data "google_compute_disk" "existing_volumes" { resource "google_compute_attached_disk" "attachments" { for_each = module.design.volumes - disk = try(google_compute_disk.volumes[each.key].self_link, google_compute_disk.existing_volumes[each.key].self_link) - device_name = try(google_compute_disk.volumes[each.key].name, google_compute_disk.existing_volumes[each.key].name) + disk = try(google_compute_disk.volumes[each.key].self_link, data.google_compute_disk.existing_volumes[each.key].self_link) + device_name = try(google_compute_disk.volumes[each.key].name, data.google_compute_disk.existing_volumes[each.key].name) mode = "READ_WRITE" instance = google_compute_instance.instances[each.value.instance].self_link }