From 6b0c26acb3e6f0d5936fbb32104367896408cc09 Mon Sep 17 00:00:00 2001 From: Ivan Orlov Date: Mon, 28 Oct 2024 15:43:03 -0700 Subject: [PATCH] Revert "SlurmGCP. Relax `reservation_name` match, allow for suffix" --- .../schedmd-slurm-gcp-v6-nodeset/README.md | 2 +- .../schedmd-slurm-gcp-v6-nodeset/main.tf | 24 +++++++++++-------- .../schedmd-slurm-gcp-v6-nodeset/variables.tf | 8 +++---- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/README.md b/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/README.md index bd339c262e..8dcffd8fda 100644 --- a/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/README.md +++ b/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/README.md @@ -197,7 +197,7 @@ No modules. | [preemptible](#input\_preemptible) | Should use preemptibles to burst. | `bool` | `false` | no | | [project\_id](#input\_project\_id) | Project ID to create resources in. | `string` | n/a | yes | | [region](#input\_region) | The default region for Cloud resources. | `string` | n/a | yes | -| [reservation\_name](#input\_reservation\_name) | Name of the reservation to use for VM resources, should be in one of the following formats:
- projects/PROJECT\_ID/reservations/RESERVATION\_NAME[/SUFF/IX]
- RESERVATION\_NAME[/SUFF/IX]

Must be a "SPECIFIC" reservation
Set to empty string if using no reservation or automatically-consumed reservations | `string` | `""` | no | +| [reservation\_name](#input\_reservation\_name) | Name of the reservation to use for VM resources, should be in one of the following formats:
- projects/PROJECT\_ID/reservations/RESERVATION\_NAME
- RESERVATION\_NAME

Must be a "SPECIFIC" reservation
Set to empty string if using no reservation or automatically-consumed reservations | `string` | `""` | no | | [service\_account](#input\_service\_account) | DEPRECATED: Use `service_account_email` and `service_account_scopes` instead. |
object({
email = string
scopes = set(string)
})
| `null` | no | | [service\_account\_email](#input\_service\_account\_email) | Service account e-mail address to attach to the compute instances. | `string` | `null` | no | | [service\_account\_scopes](#input\_service\_account\_scopes) | Scopes to attach to the compute instances. | `set(string)` |
[
"https://www.googleapis.com/auth/cloud-platform"
]
| no | diff --git a/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/main.tf b/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/main.tf index 6e680f002b..217328277b 100644 --- a/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/main.tf +++ b/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/main.tf @@ -130,22 +130,26 @@ data "google_compute_zones" "available" { } locals { - res_match = regex("^(?P(?Pprojects/(?P[a-z0-9-]+)/reservations/)?(?[a-z0-9-]+)(?P/[a-z0-9-]+/[a-z0-9-]+)?)?$", var.reservation_name) - - res_short_name = local.res_match.name - res_project = coalesce(local.res_match.project, var.project_id) - res_prefix = coalesce(local.res_match.prefix, "projects/${local.res_project}/reservations/") - res_suffix = local.res_match.suffix == null ? "" : local.res_match.suffix + res_name_split = split("/", var.reservation_name) + reservation = var.reservation_name == "" ? null : ( + length(local.res_name_split) == 4 ? { + project : local.res_name_split[1], + name : local.res_name_split[3] + } : { + project : var.project_id, + name : var.reservation_name + } + ) - reservation_name = local.res_match.whole == null ? "" : "${local.res_prefix}${local.res_short_name}${local.res_suffix}" + reservation_name = local.reservation == null ? "" : "projects/${local.reservation.project}/reservations/${local.reservation.name}" } # tflint-ignore: terraform_unused_declarations data "google_compute_reservation" "reservation" { - count = length(local.reservation_name) > 0 ? 1 : 0 + count = local.reservation != null ? 1 : 0 - name = local.res_short_name - project = local.res_project + name = local.reservation.name + project = local.reservation.project zone = var.zone lifecycle { diff --git a/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/variables.tf b/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/variables.tf index 3bd8fc74fb..ad0409ad11 100644 --- a/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/variables.tf +++ b/community/modules/compute/schedmd-slurm-gcp-v6-nodeset/variables.tf @@ -447,8 +447,8 @@ variable "access_config" { variable "reservation_name" { description = <<-EOD Name of the reservation to use for VM resources, should be in one of the following formats: - - projects/PROJECT_ID/reservations/RESERVATION_NAME[/SUFF/IX] - - RESERVATION_NAME[/SUFF/IX] + - projects/PROJECT_ID/reservations/RESERVATION_NAME + - RESERVATION_NAME Must be a "SPECIFIC" reservation Set to empty string if using no reservation or automatically-consumed reservations @@ -458,8 +458,8 @@ variable "reservation_name" { nullable = false validation { - condition = length(regexall("^((projects/([a-z0-9-]+)/reservations/)?([a-z0-9-]+)(/[a-z0-9-]+/[a-z0-9-]+)?)?$", var.reservation_name)) > 0 - error_message = "Reservation name must be either empty or in the format '[projects/PROJECT_ID/reservations/]RESERVATION_NAME[/SUFF/IX]', [...] are optional parts." + condition = var.reservation_name == "" || length(regexall("^projects/[a-z0-9-]+/reservations/[a-z0-9-]+$", var.reservation_name)) > 0 || length(regexall("^[a-z0-9-]+$", var.reservation_name)) > 0 + error_message = "Reservation name must be in the format 'projects/PROJECT_ID/reservations/RESERVATION_NAME' or 'RESERVATION_NAME'." } }