Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cloudwatch/metric/many/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# cloudwatch/metric/many

Same as [cloudwatch/metric](./..) but allows for creating many metrics using a single module

<!-- bin/docs -->

## Versions

| Provider | Requirements |
|-|-|
| terraform | `>= 0.12` |

## Inputs

* `vars` (`any`, default: `[]`)

List of [cloudwatch/metric](./..) variables

* `vars_map` (`any`, default: `{}`)

Map of [cloudwatch/metric](./..) variables



## Outputs

* `out`

List of [cloudwatch/metric](./..) outputs

* `out_map`

Map of [cloudwatch/metric](./..) outputs
48 changes: 48 additions & 0 deletions cloudwatch/metric/many/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module "default" {
source = "./.."

namespace = ""
name = ""
}

locals {
out = [for v in var.vars : {
id = "m_${v.name}_${md5(jsonencode([
v.namespace,
v.name,
try(v.dimensions, module.default.dimensions),
try(v.period, module.default.period),
try(v.stat, module.default.stat),
try(v.label, module.default.label),
try(v.color, module.default.color),
]))}"

namespace = v.namespace
name = v.name
dimensions = try(v.dimensions, module.default.dimensions)
period = try(v.period, module.default.period)
stat = try(v.stat, module.default.stat)
label = try(v.label, module.default.label)
color = try(v.color, module.default.color)
}]

out_map = { for k, v in var.vars_map : k => {
id = "m_${v.name}_${md5(jsonencode([
v.namespace,
v.name,
try(v.dimensions, module.default.dimensions),
try(v.period, module.default.period),
try(v.stat, module.default.stat),
try(v.label, module.default.label),
try(v.color, module.default.color),
]))}"

namespace = v.namespace
name = v.name
dimensions = try(v.dimensions, module.default.dimensions)
period = try(v.period, module.default.period)
stat = try(v.stat, module.default.stat)
label = try(v.label, module.default.label)
color = try(v.color, module.default.color)
} }
}
9 changes: 9 additions & 0 deletions cloudwatch/metric/many/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "out" {
description = "List of [cloudwatch/metric](./..) outputs"
value = local.out
}

output "out_map" {
description = "Map of [cloudwatch/metric](./..) outputs"
value = local.out_map
}
11 changes: 11 additions & 0 deletions cloudwatch/metric/many/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "vars" {
description = "List of [cloudwatch/metric](./..) variables"
type = any
default = []
}

variable "vars_map" {
description = "Map of [cloudwatch/metric](./..) variables"
type = any
default = {}
}
3 changes: 3 additions & 0 deletions cloudwatch/metric/many/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = ">= 0.12"
}
33 changes: 33 additions & 0 deletions cloudwatch/metric_expression/many/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# cloudwatch/metric_expression/many

Same as [cloudwatch/metric_expression](./..) but allows for creating many metrics using a single module

<!-- bin/docs -->

## Versions

| Provider | Requirements |
|-|-|
| terraform | `>= 0.12` |

## Inputs

* `vars` (`any`, default: `[]`)

List of [cloudwatch/metric_expression](./..) variables

* `vars_map` (`any`, default: `{}`)

Map of [cloudwatch/metric_expression](./..) variables



## Outputs

* `out`

List of [cloudwatch/metric_expression](./..) outputs

* `out_map`

Map of [cloudwatch/metric_expression](./..) outputs
31 changes: 31 additions & 0 deletions cloudwatch/metric_expression/many/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module "default" {
source = "./.."

expression = ""
}

locals {
out = [for v in var.vars : {
id = "e_${md5(jsonencode([
v.expression,
try(v.label, module.default.label),
try(v.color, module.default.color),
]))}"

expression = v.expression
label = try(v.label, module.default.label)
color = try(v.color, module.default.color)
}]

out_map = { for k, v in var.vars_map : k => {
id = "e_${md5(jsonencode([
v.expression,
try(v.label, module.default.label),
try(v.color, module.default.color),
]))}"

expression = v.expression
label = try(v.label, module.default.label)
color = try(v.color, module.default.color)
} }
}
9 changes: 9 additions & 0 deletions cloudwatch/metric_expression/many/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "out" {
description = "List of [cloudwatch/metric_expression](./..) outputs"
value = local.out
}

output "out_map" {
description = "Map of [cloudwatch/metric_expression](./..) outputs"
value = local.out_map
}
11 changes: 11 additions & 0 deletions cloudwatch/metric_expression/many/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "vars" {
description = "List of [cloudwatch/metric_expression](./..) variables"
type = any
default = []
}

variable "vars_map" {
description = "Map of [cloudwatch/metric_expression](./..) variables"
type = any
default = {}
}
3 changes: 3 additions & 0 deletions cloudwatch/metric_expression/many/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = ">= 0.12"
}
61 changes: 61 additions & 0 deletions cloudwatch/metric_widget/example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module "dashboard" {
module.widget_current_values,
module.widget_expressions,
module.widget_annotations,
module.widget_metric_many_module,
module.widget_expression_many_module,
]
}

Expand Down Expand Up @@ -211,3 +213,62 @@ module "widget_annotations" {
module.annotation_last_release,
]
}

# Widget using metric/many and metric_expression/many modules

locals {
cpu_utilization_stats = {
min = "Minimum"
average = "Average"
max = "Maximum"
}
}

module "metrics_cpu_utilization" {
source = "./../../metric/many"

vars_map = { for k, stat in local.cpu_utilization_stats : k => {
namespace = "AWS/EC2"
name = "CPUUtilization"
stat = stat
period = 300
label = "${stat} EC2 CPU utilization"
} }
}

module "widget_metric_many_module" {
source = "./.."

title = "metric/many module"
left_metrics = [
module.metrics_cpu_utilization.out_map.min,
module.metrics_cpu_utilization.out_map.average,
module.metrics_cpu_utilization.out_map.max,
]
left_range = [0, 100]
}

module "expressions_cpu_utilization_rate" {
source = "./../../metric_expression/many"

vars_map = { for k, stat in local.cpu_utilization_stats : k => {
expression = "RATE(${module.metrics_cpu_utilization.out_map[k].id})"
label = "${stat} EC2 CPU utilization rate"
} }
}

module "widget_expression_many_module" {
source = "./.."

title = "metric_expression/many module"
left_metrics = [
module.expressions_cpu_utilization_rate.out_map.min,
module.expressions_cpu_utilization_rate.out_map.average,
module.expressions_cpu_utilization_rate.out_map.max,
]
hidden_metrics = [
module.metrics_cpu_utilization.out_map.min,
module.metrics_cpu_utilization.out_map.average,
module.metrics_cpu_utilization.out_map.max,
]
}