From d3c509f8fb8d9cd68f2f580902fa344ac0f94072 Mon Sep 17 00:00:00 2001 From: Xavier Basty Date: Fri, 31 Mar 2023 15:10:42 +0200 Subject: [PATCH] fix: environment in monitoring module (#20) --- terraform/main.tf | 3 +-- terraform/monitoring/README.md | 8 +++++++- terraform/monitoring/data_sources.tf | 26 ++++++++++++++++++++++++++ terraform/monitoring/main.tf | 23 ----------------------- terraform/monitoring/outputs.tf | 8 +++++++- 5 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 terraform/monitoring/data_sources.tf diff --git a/terraform/main.tf b/terraform/main.tf index 24d69c0..7be76f4 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -100,10 +100,9 @@ resource "aws_prometheus_workspace" "prometheus" { alias = "prometheus-${module.this.id}" } -module "o11y" { +module "monitoring" { source = "./monitoring" context = module.this.context - environment = terraform.workspace prometheus_workspace_id = aws_prometheus_workspace.prometheus.id } diff --git a/terraform/monitoring/README.md b/terraform/monitoring/README.md index 4ae8dbc..93fe71b 100644 --- a/terraform/monitoring/README.md +++ b/terraform/monitoring/README.md @@ -9,12 +9,14 @@ Configure the Grafana dashboards for the application |------|---------| | [terraform](#requirement\_terraform) | ~> 1.0 | | [grafana](#requirement\_grafana) | ~> 1.24 | +| [jsonnet](#requirement\_jsonnet) | ~> 2.2.0 | ## Providers | Name | Version | |------|---------| | [grafana](#provider\_grafana) | ~> 1.24 | +| [jsonnet](#provider\_jsonnet) | ~> 2.2.0 | ## Modules @@ -29,6 +31,7 @@ Configure the Grafana dashboards for the application | [grafana_dashboard.at_a_glance](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/dashboard) | resource | | [grafana_data_source.cloudwatch](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/data_source) | resource | | [grafana_data_source.prometheus](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/data_source) | resource | +| [jsonnet_file.dashboard](https://registry.terraform.io/providers/alxrem/jsonnet/latest/docs/data-sources/file) | data source | ## Inputs @@ -51,5 +54,8 @@ Configure the Grafana dashboards for the application ## Outputs -No outputs. +| Name | Description | +|------|-------------| +| [dashboard\_definition](#output\_dashboard\_definition) | The JSON definition of the dashboard. | +| [prometheus\_url](#output\_prometheus\_url) | The URL of the Prometheus server to use for this dashboard. | diff --git a/terraform/monitoring/data_sources.tf b/terraform/monitoring/data_sources.tf new file mode 100644 index 0000000..83c8e2f --- /dev/null +++ b/terraform/monitoring/data_sources.tf @@ -0,0 +1,26 @@ +locals { + prometheus_url = "https://aps-workspaces.${module.this.environment}.amazonaws.com/workspaces/${var.prometheus_workspace_id}/" +} + +resource "grafana_data_source" "prometheus" { + type = "prometheus" + name = "${module.this.id}-amp" + url = local.prometheus_url + + json_data_encoded = jsonencode({ + httpMethod = "GET" + manageAlerts = false + sigV4Auth = true + sigV4AuthType = "ec2_iam_role" + sigV4Region = module.this.environment + }) +} + +resource "grafana_data_source" "cloudwatch" { + type = "cloudwatch" + name = "${module.this.id}-cloudwatch" + + json_data_encoded = jsonencode({ + defaultRegion = module.this.environment + }) +} diff --git a/terraform/monitoring/main.tf b/terraform/monitoring/main.tf index d12210f..a939b3c 100644 --- a/terraform/monitoring/main.tf +++ b/terraform/monitoring/main.tf @@ -7,29 +7,6 @@ locals { # ) } -resource "grafana_data_source" "prometheus" { - type = "prometheus" - name = "${module.this.id}-amp" - url = "https://aps-workspaces.${module.this.environment}.amazonaws.com/workspaces/${var.prometheus_workspace_id}/" - - json_data_encoded = jsonencode({ - httpMethod = "GET" - manageAlerts = false - sigV4Auth = true - sigV4AuthType = "ec2_iam_role" - sigV4Region = module.this.environment - }) -} - -resource "grafana_data_source" "cloudwatch" { - type = "cloudwatch" - name = "${module.this.id}-cloudwatch" - - json_data_encoded = jsonencode({ - defaultRegion = module.this.environment - }) -} - data "jsonnet_file" "dashboard" { source = "${path.module}/dashboard.jsonnet" diff --git a/terraform/monitoring/outputs.tf b/terraform/monitoring/outputs.tf index 6bc7cdf..8219bca 100644 --- a/terraform/monitoring/outputs.tf +++ b/terraform/monitoring/outputs.tf @@ -1,3 +1,9 @@ +output "prometheus_url" { + description = "The URL of the Prometheus server to use for this dashboard." + value = local.prometheus_url +} + output "dashboard_definition" { - value = data.jsonnet_file.dashboard.rendered + description = "The JSON definition of the dashboard." + value = data.jsonnet_file.dashboard.rendered }