-
Notifications
You must be signed in to change notification settings - Fork 289
Sub-block targeting and validation #5405
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,36 @@ data "google_compute_reservation" "specific_reservations" { | |
| project = each.value.project | ||
| } | ||
|
|
||
| data "google_compute_reservation_sub_block" "this" { | ||
| for_each = ( | ||
| (var.enable_slice_controller && var.reservation_block != null && var.reservation_block != "" && var.reservation_sub_block != null && var.reservation_sub_block != "") ? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the newly introduced This aligns with the repository's focus on "Maintainability: Code should be easy to understand, modify, and extend." (Repository Style Guide, line 6). References
|
||
| { | ||
| for pair in flatten([ | ||
| for zone in try(var.zones, []) : [ | ||
| for i, reservation_name in try(local.input_reservation_names, []) : { | ||
| key : "${local.input_reservation_projects[i]}/${zone}/${reservation_name}" | ||
| zone : zone | ||
| reservation_name : reservation_name | ||
| project : local.input_reservation_projects[i] | ||
| } | ||
| ] | ||
| ]) : | ||
| pair.key => pair | ||
| } : | ||
| {} | ||
| ) | ||
|
|
||
| project = each.value.project | ||
| zone = each.value.zone | ||
| reservation_name = each.value.reservation_name | ||
| reservation_block = var.reservation_block | ||
| name = var.reservation_sub_block | ||
| } | ||
|
|
||
| locals { | ||
| requested_nodes = coalesce(var.static_node_count, var.initial_node_count, var.autoscaling_total_max_nodes, 0) | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve readability and reduce repetition, consider extracting the complex conditional logic for This aligns with the repository's focus on "Maintainability: Code should be easy to understand, modify, and extend." (Repository Style Guide, line 6). References
|
||
|
|
||
| locals { | ||
| generated_guest_accelerator = module.gpu.machine_type_guest_accelerator | ||
| reservation_resource_api_label = "compute.googleapis.com/reservation-name" | ||
|
|
@@ -96,12 +126,19 @@ locals { | |
| # Build the list of reservation names when var.is_reservation_active is true | ||
| active_reservation_values = [ | ||
| for i, r in local.verified_specific_reservations : | ||
| length(local.input_reservation_suffixes[i]) > 0 ? | ||
| format("%s%s", r.name, local.input_reservation_suffixes[i]) : | ||
| "projects/${r.project}/reservations/${r.name}" | ||
| (var.enable_slice_controller && var.reservation_block != null && var.reservation_block != "" && var.reservation_sub_block != null && var.reservation_sub_block != "") ? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the This aligns with the repository's focus on "Maintainability: Code should be easy to understand, modify, and extend." (Repository Style Guide, line 6). References
|
||
| "projects/${r.project}/zones/${r.zone}/reservations/${r.name}/reservationBlocks/${var.reservation_block}/reservationSubBlocks/${var.reservation_sub_block}" : | ||
| (length(local.input_reservation_suffixes[i]) > 0 ? | ||
| format("%s%s", r.name, local.input_reservation_suffixes[i]) : | ||
| "projects/${r.project}/reservations/${r.name}") | ||
| ] | ||
|
|
||
| # Define a default reservation value if no specific reservations are present | ||
| specific_reservation_name = length(local.input_reservation_names) > 0 ? local.input_reservation_names[0] : "" | ||
| default_reservation_values = ["projects/${var.project_id}/reservations/${local.specific_reservation_name}"] | ||
| specific_reservation_name = length(local.input_reservation_names) > 0 ? local.input_reservation_names[0] : "" | ||
| default_reservation_values = [ | ||
| for zone in try(var.zones, []) : | ||
| (var.enable_slice_controller && var.reservation_block != null && var.reservation_block != "" && var.reservation_sub_block != null && var.reservation_sub_block != "") ? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replacing the repeated conditional logic with the This aligns with the repository's focus on "Maintainability: Code should be easy to understand, modify, and extend." (Repository Style Guide, line 6). References
|
||
| "projects/${var.project_id}/zones/${zone}/reservations/${local.specific_reservation_name}/reservationBlocks/${var.reservation_block}/reservationSubBlocks/${var.reservation_sub_block}" : | ||
| "projects/${var.project_id}/reservations/${local.specific_reservation_name}" | ||
| ] | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leveraging the
is_sub_block_targeting_enabledlocal variable here simplifies theprecondition'sconditionexpression. This makes the validation logic more readable and consistent with other parts of the module where this complex condition is used.This aligns with the repository's focus on "Maintainability: Code should be easy to understand, modify, and extend." (Repository Style Guide, line 6).
References