-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: use null comparators in cases where zero or false are meaningful #2513
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: main
Are you sure you want to change the base?
Changes from all commits
fcfd224
36266df
48d3d10
db16403
fcbc819
75f5038
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 |
|---|---|---|
|
|
@@ -812,7 +812,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -966,7 +966,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. This line still defaults |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
@@ -1199,7 +1199,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1353,7 +1353,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -956,7 +956,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1116,7 +1116,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
@@ -1357,7 +1357,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1517,7 +1517,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -870,7 +870,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1030,7 +1030,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
@@ -1270,7 +1270,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1430,7 +1430,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -934,7 +934,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1094,7 +1094,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
@@ -1335,7 +1335,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1495,7 +1495,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -848,7 +848,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1008,7 +1008,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
@@ -1248,7 +1248,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1408,7 +1408,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -919,7 +919,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1073,7 +1073,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
@@ -1307,7 +1307,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1461,7 +1461,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -834,7 +834,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -988,7 +988,7 @@ resource "google_container_node_pool" "pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
@@ -1221,7 +1221,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "queued_provisioning" { | ||
| for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] | ||
| for_each = lookup(each.value, "queued_provisioning", null) != null ? [true] : [] | ||
| content { | ||
| enabled = lookup(each.value, "queued_provisioning", null) | ||
| } | ||
|
|
@@ -1375,7 +1375,7 @@ resource "google_container_node_pool" "windows_pools" { | |
| } | ||
|
|
||
| dynamic "advanced_machine_features" { | ||
| for_each = lookup(each.value, "threads_per_core", 0) > 0 || lookup(each.value, "enable_nested_virtualization", false) || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| for_each = lookup(each.value, "threads_per_core", null) != null || lookup(each.value, "enable_nested_virtualization", null) != null || lookup(each.value, "performance_monitoring_unit", null) != null ? [1] : [] | ||
| content { | ||
| threads_per_core = lookup(each.value, "threads_per_core", 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. |
||
| enable_nested_virtualization = lookup(each.value, "enable_nested_virtualization", null) | ||
|
|
||
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.
While the
for_eachcondition for theadvanced_machine_featuresdynamic block has been correctly updated to distinguish between an unset value (null) and0forthreads_per_core, the value assignment within the block still defaults to0. This can lead to unintended behavior wherethreads_per_coreis set to0even when it's not specified in the input, which is the issue this PR aims to fix. To be consistent with the changes and the PR's intent, you should usenullas the default value here as well.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.
This is likely still relevant as the content will be used if any of the conditions are not null, so a null default for
threads_per_corewould be preferable.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.
This interaction is so confusing even Gemini can't follow it, but I think it's right the way it currently is. The first iteration of this PR set all fields to null. I believe we then discovered that threads_per_core is in fact required to be set if
advanced_machine_featuresis configured, so 48d3d10 followed up and changed it back to zero. In other words:The comment in #2513 (review) contains the output stating that