diff --git a/modules/dashboard/sections/collapsible/main.tf b/modules/dashboard/sections/collapsible/main.tf index 874ae2d4..c5429cae 100644 --- a/modules/dashboard/sections/collapsible/main.tf +++ b/modules/dashboard/sections/collapsible/main.tf @@ -1,6 +1,6 @@ variable "title" { type = string } variable "tiles" {} -variable "collapsed" { default = false } +variable "collapsed" { type = optional(bool) } locals { start_row = length(var.tiles) == 0 ? 0 : min([for s in var.tiles : s.yPos]...) @@ -10,14 +10,14 @@ module "width" { source = "../width" } output "section" { value = concat([{ - yPos = local.start_row - xPos = 0, + yPos = local.start_row != 0 ? local.start_row : null, + xPos = null, height = length(var.tiles) == 0 ? 0 : max([for s in var.tiles : s.yPos + s.height - local.start_row]...), width = module.width.size, widget = { title = var.title collapsibleGroup = { - collapsed = var.collapsed + collapsed = var.collapsed ? true : null } }, }], var.tiles) diff --git a/modules/dashboard/sections/layout/main.tf b/modules/dashboard/sections/layout/main.tf index bc0f045e..317dc65b 100644 --- a/modules/dashboard/sections/layout/main.tf +++ b/modules/dashboard/sections/layout/main.tf @@ -14,8 +14,8 @@ locals { // the section, which starts after the topmost tile of the preceding section. rebased = [for s in var.sections : [ for t in s : { - yPos = t.yPos + local.sum_heights[index(var.sections, s)] - xPos = t.xPos + yPos = t.yPos + local.sum_heights[index(var.sections, s)] != 0 ? t.yPos + local.sum_heights[index(var.sections, s)] : null + xPos = t.xPos != 0 ? t.xPos : null height = t.height width = t.width widget = t.widget diff --git a/modules/dashboard/widgets/latency/main.tf b/modules/dashboard/widgets/latency/main.tf index aeebabce..730f2c3f 100644 --- a/modules/dashboard/widgets/latency/main.tf +++ b/modules/dashboard/widgets/latency/main.tf @@ -1,5 +1,5 @@ variable "title" { type = string } -variable "group_by_fields" { default = [] } +variable "group_by_fields" { type = list(string) } variable "filter" { type = list(string) } variable "band" { type = number diff --git a/modules/dashboard/widgets/xy-ratio/main.tf b/modules/dashboard/widgets/xy-ratio/main.tf index f6ec31d2..6580e206 100644 --- a/modules/dashboard/widgets/xy-ratio/main.tf +++ b/modules/dashboard/widgets/xy-ratio/main.tf @@ -1,16 +1,21 @@ variable "title" { type = string } variable "legend" { default = "" } -variable "numerator_group_by_fields" { default = [] } -variable "denominator_group_by_fields" { default = [] } +variable "numerator_group_by_fields" { type = list(string) } +variable "denominator_group_by_fields" { type = list(string) } variable "numerator_filter" { type = list(string) } variable "denominator_filter" { type = list(string) } variable "plot_type" { default = "LINE" } variable "alignment_period" { default = "60s" } -variable "numerator_align" { default = "ALIGN_RATE" } +variable "numerator_align" { type = optional(string) /* default: "ALIGN_RATE" */ } variable "numerator_reduce" { default = "REDUCE_SUM" } -variable "denominator_align" { default = "ALIGN_RATE" } +variable "denominator_align" { type = optional(string) /* default: "ALIGN_RATE" */ } variable "denominator_reduce" { default = "REDUCE_SUM" } -variable "thresholds" { default = [] } +variable "thresholds" { type = list(string) } + +locals { + default_align = "ALIGN_RATE" + default_reduce = "REDUCE_NONE" +} // https://cloud.google.com/monitoring/api/ref_v3/rest/v1/projects.dashboards#XyChart output "widget" { @@ -30,18 +35,18 @@ output "widget" { filter = join("\n", var.numerator_filter) aggregation = { alignmentPeriod = var.alignment_period - perSeriesAligner = var.numerator_align - crossSeriesReducer = var.numerator_reduce - groupByFields = var.numerator_group_by_fields + perSeriesAligner = var.numerator_align == local.default_align ? null : var.numerator_align + crossSeriesReducer = var.numerator_reduce == local.default_reduce ? null : var.numerator_reduce + groupByFields = length(var.numerator_group_by_fields) == 0 ? null : var.numerator_group_by_fields } } denominator = { filter = join("\n", var.denominator_filter) aggregation = { alignmentPeriod = var.alignment_period - perSeriesAligner = var.denominator_align - crossSeriesReducer = var.denominator_reduce - groupByFields = var.denominator_group_by_fields + perSeriesAligner = var.denominator_align == local.default_align ? null : var.denominator_align + crossSeriesReducer = var.denominator_reduce == local.default_reduce ? null : var.denominator_reduce + groupByFields = length(var.denominator_group_by_fields) } } } diff --git a/modules/dashboard/widgets/xy/main.tf b/modules/dashboard/widgets/xy/main.tf index 4c7a40d6..4fffcb2e 100644 --- a/modules/dashboard/widgets/xy/main.tf +++ b/modules/dashboard/widgets/xy/main.tf @@ -1,12 +1,17 @@ variable "title" { type = string } -variable "group_by_fields" { default = [] } +variable "group_by_fields" { type = list(string) } variable "filter" { type = list(string) } variable "plot_type" { default = "LINE" } variable "alignment_period" { default = "60s" } -variable "primary_align" { default = "ALIGN_RATE" } -variable "primary_reduce" { default = "REDUCE_NONE" } -variable "secondary_align" { default = "ALIGN_NONE" } -variable "secondary_reduce" { default = "REDUCE_NONE" } +variable "primary_align" { type = optional(string) /* default: "ALIGN_RATE" */ } +variable "primary_reduce" { type = optional(string) /* default: "REDUCE_NONE" */ } +variable "secondary_align" { type = optional(string) /* default: "ALIGN_NONE" */ } +variable "secondary_reduce" { type = optional(string) /* default: "REDUCE_NONE" */ } + +locals { + default_align = "ALIGN_RATE" + default_reduce = "REDUCE_NONE" +} // https://cloud.google.com/monitoring/api/ref_v3/rest/v1/projects.dashboards#XyChart output "widget" { @@ -22,16 +27,16 @@ output "widget" { timeSeriesFilter = { aggregation = { alignmentPeriod = var.alignment_period - perSeriesAligner = var.primary_align - crossSeriesReducer = var.primary_reduce - groupByFields = var.group_by_fields + perSeriesAligner = var.primary_align == local.default_align ? null : var.primary_align + crossSeriesReducer = var.primary_reduce == local.default_reduce ? null : var.primary_reduce + groupByFields = length(var.group_by_fields) == 0 ? null : var.group_by_fields } filter = join("\n", var.filter) secondaryAggregation = { alignmentPeriod = var.alignment_period - perSeriesAligner = var.secondary_align - crossSeriesReducer = var.secondary_reduce - groupByFields = var.group_by_fields + perSeriesAligner = var.secondary_align == local.default_align ? null : var.secondary_align + crossSeriesReducer = var.secondary_reduce == local.default_reduce ? null : var.secondary_reduce + groupByFields = length(var.group_by_fields) == 0 ? null : var.group_by_fields } } }