Skip to content

Commit

Permalink
Merge pull request #3178 from GoogleCloudPlatform/revert-3170-res_nam…
Browse files Browse the repository at this point in the history
…e_suf

Revert "SlurmGCP. Relax `reservation_name` match, allow for suffix"
  • Loading branch information
mr0re1 authored Oct 28, 2024
2 parents 19fa5ca + 6b0c26a commit 7fd2042
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ No modules.
| <a name="input_preemptible"></a> [preemptible](#input\_preemptible) | Should use preemptibles to burst. | `bool` | `false` | no |
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | Project ID to create resources in. | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | The default region for Cloud resources. | `string` | n/a | yes |
| <a name="input_reservation_name"></a> [reservation\_name](#input\_reservation\_name) | Name of the reservation to use for VM resources, should be in one of the following formats:<br/>- projects/PROJECT\_ID/reservations/RESERVATION\_NAME[/SUFF/IX]<br/>- RESERVATION\_NAME[/SUFF/IX]<br/><br/>Must be a "SPECIFIC" reservation<br/>Set to empty string if using no reservation or automatically-consumed reservations | `string` | `""` | no |
| <a name="input_reservation_name"></a> [reservation\_name](#input\_reservation\_name) | Name of the reservation to use for VM resources, should be in one of the following formats:<br/>- projects/PROJECT\_ID/reservations/RESERVATION\_NAME<br/>- RESERVATION\_NAME<br/><br/>Must be a "SPECIFIC" reservation<br/>Set to empty string if using no reservation or automatically-consumed reservations | `string` | `""` | no |
| <a name="input_service_account"></a> [service\_account](#input\_service\_account) | DEPRECATED: Use `service_account_email` and `service_account_scopes` instead. | <pre>object({<br/> email = string<br/> scopes = set(string)<br/> })</pre> | `null` | no |
| <a name="input_service_account_email"></a> [service\_account\_email](#input\_service\_account\_email) | Service account e-mail address to attach to the compute instances. | `string` | `null` | no |
| <a name="input_service_account_scopes"></a> [service\_account\_scopes](#input\_service\_account\_scopes) | Scopes to attach to the compute instances. | `set(string)` | <pre>[<br/> "https://www.googleapis.com/auth/cloud-platform"<br/>]</pre> | no |
Expand Down
24 changes: 14 additions & 10 deletions community/modules/compute/schedmd-slurm-gcp-v6-nodeset/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,26 @@ data "google_compute_zones" "available" {
}

locals {
res_match = regex("^(?P<whole>(?P<prefix>projects/(?P<project>[a-z0-9-]+)/reservations/)?(?<name>[a-z0-9-]+)(?P<suffix>/[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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'."
}
}

Expand Down

0 comments on commit 7fd2042

Please sign in to comment.