Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-empty plan after mixing CloudSQL with other mounts #2700

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions modules/cloud-run-v2/job.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ resource "google_cloud_run_v2_job" "job" {
}
}
dynamic "volume_mounts" {
for_each = coalesce(containers.value.volume_mounts, tomap({}))
for_each = { for k, v in coalesce(containers.value.volume_mounts, tomap({})) : k => v if k != "cloudsql" }
content {
name = volume_mounts.key
mount_path = volume_mounts.value
}
}
# CloudSQL is the last mount in the list returned by API
dynamic "volume_mounts" {
for_each = { for k, v in coalesce(containers.value.volume_mounts, tomap({})) : k => v if k == "cloudsql" }
content {
name = volume_mounts.key
mount_path = volume_mounts.value
Expand All @@ -96,7 +104,7 @@ resource "google_cloud_run_v2_job" "job" {
}
}
dynamic "volumes" {
for_each = var.volumes
for_each = { for k, v in var.volumes : k => v if v.cloud_sql_instances == null }
content {
name = volumes.key
dynamic "secret" {
Expand All @@ -114,12 +122,7 @@ resource "google_cloud_run_v2_job" "job" {
}
}
}
dynamic "cloud_sql_instance" {
for_each = length(coalesce(volumes.value.cloud_sql_instances, [])) == 0 ? [] : [""]
content {
instances = volumes.value.cloud_sql_instances
}
}

dynamic "empty_dir" {
for_each = volumes.value.empty_dir_size == null ? [] : [""]
content {
Expand All @@ -144,6 +147,19 @@ resource "google_cloud_run_v2_job" "job" {
}
}
}
# CloudSQL is the last volume in the list returned by API
dynamic "volumes" {
for_each = { for k, v in var.volumes : k => v if v.cloud_sql_instances != null }
content {
name = volumes.key
dynamic "cloud_sql_instance" {
for_each = length(coalesce(volumes.value.cloud_sql_instances, [])) == 0 ? [] : [""]
content {
instances = volumes.value.cloud_sql_instances
}
}
}
}
}
}

Expand All @@ -162,4 +178,3 @@ resource "google_cloud_run_v2_job_iam_binding" "binding" {
role = each.key
members = each.value
}

32 changes: 24 additions & 8 deletions modules/cloud-run-v2/service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ resource "google_cloud_run_v2_service" "service" {
}
}
dynamic "volume_mounts" {
for_each = coalesce(containers.value.volume_mounts, tomap({}))
for_each = { for k, v in coalesce(containers.value.volume_mounts, tomap({})) : k => v if k != "cloudsql" }
content {
name = volume_mounts.key
mount_path = volume_mounts.value
}
}
# CloudSQL is the last mount in the list returned by API
dynamic "volume_mounts" {
for_each = { for k, v in coalesce(containers.value.volume_mounts, tomap({})) : k => v if k == "cloudsql" }
content {
name = volume_mounts.key
mount_path = volume_mounts.value
Expand Down Expand Up @@ -174,7 +182,7 @@ resource "google_cloud_run_v2_service" "service" {
}
}
dynamic "volumes" {
for_each = var.volumes
for_each = { for k, v in var.volumes : k => v if v.cloud_sql_instances == null }
content {
name = volumes.key
dynamic "secret" {
Expand All @@ -192,12 +200,7 @@ resource "google_cloud_run_v2_service" "service" {
}
}
}
dynamic "cloud_sql_instance" {
for_each = length(coalesce(volumes.value.cloud_sql_instances, [])) == 0 ? [] : [""]
content {
instances = volumes.value.cloud_sql_instances
}
}

dynamic "empty_dir" {
for_each = volumes.value.empty_dir_size == null ? [] : [""]
content {
Expand All @@ -222,6 +225,19 @@ resource "google_cloud_run_v2_service" "service" {
}
}
}
# CloudSQL is the last volume in the list returned by API
dynamic "volumes" {
for_each = { for k, v in var.volumes : k => v if v.cloud_sql_instances != null }
content {
name = volumes.key
dynamic "cloud_sql_instance" {
for_each = length(coalesce(volumes.value.cloud_sql_instances, [])) == 0 ? [] : [""]
content {
instances = volumes.value.cloud_sql_instances
}
}
}
}
}

deletion_protection = var.deletion_protection
Expand Down