Skip to content

Commit

Permalink
Revert "Merge pull request GoogleCloudPlatform#3776 from mr0re1/image…
Browse files Browse the repository at this point in the history
…_of_void"

This reverts commit a088db8, reversing
changes made to 97cd448.
  • Loading branch information
rohitramu committed Mar 11, 2025
1 parent a088db8 commit 53a91f4
Show file tree
Hide file tree
Showing 24 changed files with 415 additions and 296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,26 @@ modules. For support with the underlying modules, see the instructions in the
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_google"></a> [google](#requirement\_google) | >= 5.11 |
## Providers
No providers.
| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | >= 5.11 |
## Modules
| Name | Source | Version |
|------|--------|---------|
| <a name="module_gpu"></a> [gpu](#module\_gpu) | ../../../../modules/internal/gpu-definition | n/a |
| <a name="module_image"></a> [image](#module\_image) | ../../internal/slurm-gcp/image_logic | n/a |
| <a name="module_slurm_nodeset_template"></a> [slurm\_nodeset\_template](#module\_slurm\_nodeset\_template) | ../../internal/slurm-gcp/instance_template | n/a |
## Resources
No resources.
| Name | Type |
|------|------|
| [google_compute_image.slurm](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_image) | data source |
## Inputs
Expand All @@ -102,7 +106,7 @@ No resources.
| <a name="input_enable_spot_vm"></a> [enable\_spot\_vm](#input\_enable\_spot\_vm) | Enable the partition to use spot VMs (https://cloud.google.com/spot-vms). | `bool` | `false` | no |
| <a name="input_feature"></a> [feature](#input\_feature) | The node feature, used to bind nodes to the nodeset. If not set, the nodeset name will be used. | `string` | `null` | no |
| <a name="input_guest_accelerator"></a> [guest\_accelerator](#input\_guest\_accelerator) | List of the type and count of accelerator cards attached to the instance. | <pre>list(object({<br/> type = string,<br/> count = number<br/> }))</pre> | `[]` | no |
| <a name="input_instance_image"></a> [instance\_image](#input\_instance\_image) | Defines the image that will be used in the Slurm node group VM instances.<br/><br/>Expected Fields:<br/>name: The name of the image. Mutually exclusive with family.<br/>family: The image family to use. Mutually exclusive with name.<br/>project: The project where the image is hosted.<br/><br/>For more information on creating custom images that comply with Slurm on GCP<br/>see the "Slurm on GCP Custom Images" section in docs/vm-images.md. | `map(string)` | `null` | no |
| <a name="input_instance_image"></a> [instance\_image](#input\_instance\_image) | Defines the image that will be used in the Slurm node group VM instances.<br/><br/>Expected Fields:<br/>name: The name of the image. Mutually exclusive with family.<br/>family: The image family to use. Mutually exclusive with name.<br/>project: The project where the image is hosted.<br/><br/>For more information on creating custom images that comply with Slurm on GCP<br/>see the "Slurm on GCP Custom Images" section in docs/vm-images.md. | `map(string)` | <pre>{<br/> "family": "slurm-gcp-6-8-hpc-rocky-linux-8",<br/> "project": "schedmd-slurm-public"<br/>}</pre> | no |
| <a name="input_instance_image_custom"></a> [instance\_image\_custom](#input\_instance\_image\_custom) | A flag that designates that the user is aware that they are requesting<br/>to use a custom and potentially incompatible image for this Slurm on<br/>GCP module.<br/><br/>If the field is set to false, only the compatible families and project<br/>names will be accepted. The deployment will fail with any other image<br/>family or name. If set to true, no checks will be done.<br/><br/>See: https://goo.gle/hpc-slurm-images | `bool` | `false` | no |
| <a name="input_labels"></a> [labels](#input\_labels) | Labels to add to partition compute instances. Key-value pairs. | `map(string)` | `{}` | no |
| <a name="input_machine_type"></a> [machine\_type](#input\_machine\_type) | Compute Platform machine type to use for this partition compute nodes. | `string` | `"c2-standard-60"` | no |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ module "gpu" {
guest_accelerator = var.guest_accelerator
}

module "image" {
source = "../../internal/slurm-gcp/image_logic"

instance_image = var.instance_image
instance_image_custom = var.instance_image_custom
}

locals {
guest_accelerator = module.gpu.guest_accelerator

Expand Down Expand Up @@ -106,10 +99,10 @@ module "slurm_nodeset_template" {
preemptible = var.preemptible
spot = var.enable_spot_vm
service_account = local.service_account
gpu = one(local.guest_accelerator)
source_image_family = module.image.source_image_family
source_image_project = module.image.source_image_project_normalized
source_image = module.image.source_image
gpu = one(local.guest_accelerator) # requires gpu_definition.tf
source_image_family = local.source_image_family # requires source_image_logic.tf
source_image_project = local.source_image_project_normalized # requires source_image_logic.tf
source_image = local.source_image # requires source_image_logic.tf

subnetwork = var.subnetwork_self_link
additional_networks = var.additional_networks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

locals {
# Currently supported images and projects
known_project_families = {
schedmd-slurm-public = [
"slurm-gcp-6-8-debian-11",
"slurm-gcp-6-8-hpc-rocky-linux-8",
"slurm-gcp-6-8-ubuntu-2004-lts",
"slurm-gcp-6-8-ubuntu-2204-lts-arm64"
]
}

# This approach to "hacking" the project name allows a chain of Terraform
# calls to set the instance source_image (boot disk) with a "relative
# resource name" that passes muster with VPC Service Control rules
#
# https://github.com/terraform-google-modules/terraform-google-vm/blob/735bd415fc5f034d46aa0de7922e8fada2327c0c/modules/instance_template/main.tf#L28
# https://cloud.google.com/apis/design/resource_names#relative_resource_name
source_image_project_normalized = (can(var.instance_image.family) ?
"projects/${data.google_compute_image.slurm.project}/global/images/family" :
"projects/${data.google_compute_image.slurm.project}/global/images"
)
source_image_family = can(var.instance_image.family) ? data.google_compute_image.slurm.family : ""
source_image = can(var.instance_image.name) ? data.google_compute_image.slurm.name : ""
}

data "google_compute_image" "slurm" {
family = try(var.instance_image.family, null)
name = try(var.instance_image.name, null)
project = var.instance_image.project

lifecycle {
precondition {
condition = length(regexall("^projects/.+?/global/images/family$", var.instance_image.project)) == 0
error_message = "The \"project\" field in var.instance_image no longer supports a long-form ending in \"family\". Specify only the project ID."
}

postcondition {
condition = var.instance_image_custom || contains(keys(local.known_project_families), self.project)
error_message = <<-EOD
Images in project ${self.project} are not published by SchedMD. Images must be created by compatible releases of the Terraform and Packer modules following the guidance at https://goo.gle/hpc-slurm-images. Set var.instance_image_custom to true to silence this error and acknowledge that you are using a compatible image.
EOD
}
postcondition {
condition = !contains(keys(local.known_project_families), self.project) || try(contains(local.known_project_families[self.project], self.family), false)
error_message = <<-EOD
Image family ${self.family} published by SchedMD in project ${self.project} is not compatible with this release of the Terraform Slurm modules. Select from known compatible releases:
${join("\n", [for p in try(local.known_project_families[self.project], []) : "\t\"${p}\""])}
EOD
}
postcondition {
condition = var.disk_size_gb >= self.disk_size_gb
error_message = "'disk_size_gb: ${var.disk_size_gb}' is smaller than the image size (${self.disk_size_gb}GB), please increase the blueprint disk size"
}
postcondition {
# Condition needs to check the suffix of the license, as prefix contains an API version which can change.
# Example license value: https://www.googleapis.com/compute/v1/projects/cloud-hpc-image-public/global/licenses/hpc-vm-image-feature-disable-auto-updates
condition = var.allow_automatic_updates || anytrue([for license in self.licenses : endswith(license, "/projects/cloud-hpc-image-public/global/licenses/hpc-vm-image-feature-disable-auto-updates")])
error_message = "Disabling automatic updates is not supported with the selected VM image. More information: https://cloud.google.com/compute/docs/instances/create-hpc-vm#disable_automatic_updates"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,20 @@ variable "instance_image" {
see the "Slurm on GCP Custom Images" section in docs/vm-images.md.
EOD
type = map(string)
default = null
default = {
family = "slurm-gcp-6-8-hpc-rocky-linux-8"
project = "schedmd-slurm-public"
}

validation {
condition = can(coalesce(var.instance_image.project))
error_message = "In var.instance_image, the \"project\" field must be a string set to the Cloud project ID."
}

validation {
condition = can(coalesce(var.instance_image.name)) != can(coalesce(var.instance_image.family))
error_message = "In var.instance_image, exactly one of \"family\" or \"name\" fields must be set to desired image family or name."
}
}

variable "instance_image_custom" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
terraform {
required_version = ">= 1.3"

required_providers {
google = {
source = "hashicorp/google"
version = ">= 5.11"
}
}
provider_meta "google" {
module_name = "blueprints/terraform/hpc-toolkit:schedmd-slurm-gcp-v6-nodeset-dynamic/v1.47.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ modules. For support with the underlying modules, see the instructions in the
| Name | Source | Version |
|------|--------|---------|
| <a name="module_gpu"></a> [gpu](#module\_gpu) | ../../../../modules/internal/gpu-definition | n/a |
| <a name="module_image"></a> [image](#module\_image) | ../../internal/slurm-gcp/image_logic | n/a |

## Resources

| Name | Type |
|------|------|
| [terraform_data.machine_type_zone_validation](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
| [google_compute_image.slurm](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_image) | data source |
| [google_compute_machine_types.machine_types_by_zone](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_machine_types) | data source |
| [google_compute_reservation.reservation](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_reservation) | data source |
| [google_compute_zones.available](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_zones) | data source |
Expand Down Expand Up @@ -184,7 +184,7 @@ modules. For support with the underlying modules, see the instructions in the
| <a name="input_enable_spot_vm"></a> [enable\_spot\_vm](#input\_enable\_spot\_vm) | Enable the partition to use spot VMs (https://cloud.google.com/spot-vms). | `bool` | `false` | no |
| <a name="input_future_reservation"></a> [future\_reservation](#input\_future\_reservation) | If set, will make use of the future reservation for the nodeset. Input can be either the future reservation name or its selfLink in the format 'projects/PROJECT\_ID/zones/ZONE/futureReservations/FUTURE\_RESERVATION\_NAME'.<br/>See https://cloud.google.com/compute/docs/instances/future-reservations-overview | `string` | `""` | no |
| <a name="input_guest_accelerator"></a> [guest\_accelerator](#input\_guest\_accelerator) | List of the type and count of accelerator cards attached to the instance. | <pre>list(object({<br/> type = string,<br/> count = number<br/> }))</pre> | `[]` | no |
| <a name="input_instance_image"></a> [instance\_image](#input\_instance\_image) | Defines the image that will be used in the Slurm node group VM instances.<br/><br/>Expected Fields:<br/>name: The name of the image. Mutually exclusive with family.<br/>family: The image family to use. Mutually exclusive with name.<br/>project: The project where the image is hosted.<br/><br/>For more information on creating custom images that comply with Slurm on GCP<br/>see the "Slurm on GCP Custom Images" section in docs/vm-images.md. | `map(string)` | `null` | no |
| <a name="input_instance_image"></a> [instance\_image](#input\_instance\_image) | Defines the image that will be used in the Slurm node group VM instances.<br/><br/>Expected Fields:<br/>name: The name of the image. Mutually exclusive with family.<br/>family: The image family to use. Mutually exclusive with name.<br/>project: The project where the image is hosted.<br/><br/>For more information on creating custom images that comply with Slurm on GCP<br/>see the "Slurm on GCP Custom Images" section in docs/vm-images.md. | `map(string)` | <pre>{<br/> "family": "slurm-gcp-6-8-hpc-rocky-linux-8",<br/> "project": "schedmd-slurm-public"<br/>}</pre> | no |
| <a name="input_instance_image_custom"></a> [instance\_image\_custom](#input\_instance\_image\_custom) | A flag that designates that the user is aware that they are requesting<br/>to use a custom and potentially incompatible image for this Slurm on<br/>GCP module.<br/><br/>If the field is set to false, only the compatible families and project<br/>names will be accepted. The deployment will fail with any other image<br/>family or name. If set to true, no checks will be done.<br/><br/>See: https://goo.gle/hpc-slurm-images | `bool` | `false` | no |
| <a name="input_instance_properties"></a> [instance\_properties](#input\_instance\_properties) | Override the instance properties. Used to test features not supported by Slurm GCP,<br/>recommended for advanced usage only.<br/>See https://cloud.google.com/compute/docs/reference/rest/v1/regionInstances/bulkInsert<br/>If any sub-field (e.g. scheduling) is set, it will override the values computed by<br/>SlurmGCP and ignoring values of provided vars. | `any` | `null` | no |
| <a name="input_instance_template"></a> [instance\_template](#input\_instance\_template) | DEPRECATED: Instance template can not be specified for compute nodes. | `string` | `null` | no |
Expand Down
13 changes: 3 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 @@ -24,13 +24,6 @@ module "gpu" {
guest_accelerator = var.guest_accelerator
}

module "image" {
source = "../../internal/slurm-gcp/image_logic"

instance_image = var.instance_image
instance_image_custom = var.instance_image_custom
}

locals {
guest_accelerator = module.gpu.guest_accelerator

Expand Down Expand Up @@ -102,9 +95,9 @@ locals {
region = var.region
service_account = local.service_account
shielded_instance_config = var.shielded_instance_config
source_image_family = module.image.source_image_family
source_image_project = module.image.source_image_project_normalized
source_image = module.image.source_image
source_image_family = local.source_image_family # requires source_image_logic.tf
source_image_project = local.source_image_project_normalized # requires source_image_logic.tf
source_image = local.source_image # requires source_image_logic.tf
subnetwork_self_link = var.subnetwork_self_link
additional_networks = var.additional_networks
access_config = local.access_config
Expand Down
Loading

0 comments on commit 53a91f4

Please sign in to comment.