refs platform/board#4082: remove module dependencies#22
refs platform/board#4082: remove module dependencies#22FabrizioCafolla merged 5 commits intomainfrom
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
There was a problem hiding this comment.
Pull request overview
Updates this Terraform module to reduce/avoid implicit module dependencies by making several alert configurations optional-by-default and safer when unset.
Changes:
- Add
{}defaults to several object-typed variables to avoid forcing callers to provide full module inputs. - Make
kyverno/cert_managercluster_nameoptional and guard log filters when it’s unset. - Change defaults for some alert modules (e.g.,
enableddefaults) to reduce automatic enablement.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| variables.tf | Makes multiple module configuration inputs optional via {} defaults; adjusts enabled and cluster_name defaults. |
| kyverno.tf | Makes the Kyverno log filter conditional on cluster_name being set. |
| cert_manager.tf | Makes the cert-manager log filter conditional on cluster_name being set. |
Comments suppressed due to low confidence (2)
kyverno.tf:55
- The
countexpression for the alert policy usestrimspace(var.kyverno.cluster_name)before checkingvar.kyverno.cluster_name != null. Ifenabled = trueandcluster_name = null, Terraform will error evaluatingtrimspace(null)even though the resource should be skipped. Reorder the checks (null check first) or use a null-safe expression liketry(trimspace(var.kyverno.cluster_name), "") != "".
) : ""
}
resource "google_monitoring_alert_policy" "kyverno_logmatch_alert" {
count = (
cert_manager.tf:41
- The
countexpression for the alert policy usestrimspace(var.cert_manager.cluster_name)before checkingvar.cert_manager.cluster_name != null. Ifenabled = trueandcluster_name = null, Terraform will error evaluatingtrimspace(null)even though the resource should be skipped. Reorder the checks (null check first) or use a null-safe expression liketry(trimspace(var.cert_manager.cluster_name), "") != "".
) : ""
}
resource "google_monitoring_alert_policy" "cert_manager_logmatch_alert" {
count = (
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b41f5bf to
9034719
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
710df67 to
20d2597
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (2)
kyverno.tf:12
local.kyverno_cluster_nameis computed (trimmed) but the log filter condition/interpolation still usesvar.kyverno.cluster_namedirectly. Ifcluster_nameis whitespace-only,local.kyverno_cluster_namebecomes empty whilekyverno_log_filterstill renders with a blank/whitespace cluster name. Use the trimmed local both for the conditional and in the filter interpolation so the behavior is consistent.
kyverno_cluster_name = var.kyverno.cluster_name != null ? trimspace(var.kyverno.cluster_name) : ""
kyverno_log_filter = var.kyverno.cluster_name != null ? (<<-EOT
resource.type="k8s_container"
AND resource.labels.project_id="${local.kyverno_project_id}"
AND resource.labels.cluster_name="${var.kyverno.cluster_name}"
AND resource.labels.namespace_name="${var.kyverno.namespace}"
cert_manager.tf:19
local.cert_manager_cluster_nameis computed (trimmed) butcert_manager_log_filterstill gates onvar.cert_manager.cluster_name != nulland interpolatesvar.cert_manager.cluster_namedirectly. This can yield filters with blank/whitespace cluster names. Use the trimmed local for the condition and interpolation so whitespace-only values behave like “unset”.
cert_manager_cluster_name = var.cert_manager.cluster_name != null ? trimspace(var.cert_manager.cluster_name) : ""
cert_manager_log_filter = var.cert_manager.cluster_name != null ? (<<-EOT
(
(
resource.type="k8s_container"
AND resource.labels.project_id="${local.cert_manager_project_id}"
AND resource.labels.cluster_name="${var.cert_manager.cluster_name}"
AND resource.labels.namespace_name="${var.cert_manager.namespace}"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
20d2597 to
9198752
Compare
9198752 to
cdc0bdb
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
cert_manager.tf:24
cert_manager_cluster_nameis trimmed intolocal.cert_manager_cluster_name, but the events branch of the log filter still interpolatesvar.cert_manager.cluster_name(line 24). If callers pass whitespace (e.g., " my-cluster "), the count condition will pass (trimmed value non-empty) but the filter will use the untrimmed value and likely never match. Use the local trimmed cluster name consistently in the filter.
AND resource.labels.cluster_name="${local.cert_manager_cluster_name}"
AND resource.labels.namespace_name="${var.cert_manager.namespace}"
)
OR (
log_id("events")
AND resource.labels.project_id="${local.cert_manager_project_id}"
AND resource.labels.cluster_name="${var.cert_manager.cluster_name}"
variables.tf:128
- Same issue as
kyverno:konnectivity_agenthasdefault = {}butenableddefaults totrueand validation requirescluster_namewhen enabled, so omittingkonnectivity_agentwill fail validation. Defaultenabledtofalse(ordefault = { enabled = false }) to make this input truly optional.
default = {}
type = object({
enabled = optional(bool, true)
cluster_name = optional(string, null)
project_id = optional(string, null)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR Type
Enhancement
Description
Made monitoring module variables optional with defaults
Changed
cluster_namefrom required to optional for cert-manager and kyvernoDisabled monitoring alerts by default for kyverno, cert-manager, and konnectivity_agent
Added conditional log filter generation based on
cluster_namepresenceDiagram Walkthrough
File Walkthrough
variables.tf
Make module variables optional with disabled-by-default alertsvariables.tf
default = {}tocloud_sql,kyverno,cert_manager, andkonnectivity_agentvariablesenableddefault fromtruetofalsefor kyverno, cert-manager,and konnectivity_agent
cluster_nameoptional (nullable) for kyverno and cert-managerenabledfield tocloud_sqlconfigurationcert_manager.tf
Add conditional log filter generation for cert-managercert_manager.tf
cert_manager_log_filterbased oncluster_namepresencecluster_nameis nullkyverno.tf
Add conditional log filter generation for kyvernokyverno.tf
kyverno_log_filterbased oncluster_namepresence
cluster_nameis null