fix reference to boot disk in snapshots when using independent disks

This commit is contained in:
Wiktor Niesiobędzki
2025-05-03 11:53:17 +00:00
committed by Wiktor Niesiobędzki
parent 623f2b0113
commit 1366e57329
2 changed files with 8 additions and 5 deletions

View File

@@ -69,10 +69,12 @@ resource "google_compute_disk" "boot" {
count = !var.create_template && var.boot_disk.use_independent_disk ? 1 : 0
project = var.project_id
zone = var.zone
name = "${var.name}-boot"
type = var.boot_disk.initialize_params.type
size = var.boot_disk.initialize_params.size
image = var.boot_disk.initialize_params.image
# by default, GCP creates boot disks with the same name as instance, the deviation here is kept for backwards
# compatibility
name = "${var.name}-boot"
type = var.boot_disk.initialize_params.type
size = var.boot_disk.initialize_params.size
image = var.boot_disk.initialize_params.image
labels = merge(var.labels, {
disk_name = "boot"
disk_type = var.boot_disk.initialize_params.type

View File

@@ -148,7 +148,8 @@ resource "google_compute_disk_resource_policy_attachment" "boot" {
google_compute_resource_policy.snapshot[each.value].name,
each.value
)
disk = var.name
# if independent disk is used for boot disk it will have a different name compared to when created implicitly
disk = !var.create_template && var.boot_disk.use_independent_disk ? google_compute_disk.boot[0].name : var.name
depends_on = [google_compute_instance.default]
}