Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Commit

Permalink
fix: environment in monitoring module (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Basty authored Mar 31, 2023
1 parent 6e004f3 commit d3c509f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
3 changes: 1 addition & 2 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 7 additions & 1 deletion terraform/monitoring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ Configure the Grafana dashboards for the application
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.0 |
| <a name="requirement_grafana"></a> [grafana](#requirement\_grafana) | ~> 1.24 |
| <a name="requirement_jsonnet"></a> [jsonnet](#requirement\_jsonnet) | ~> 2.2.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_grafana"></a> [grafana](#provider\_grafana) | ~> 1.24 |
| <a name="provider_jsonnet"></a> [jsonnet](#provider\_jsonnet) | ~> 2.2.0 |

## Modules

Expand All @@ -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

Expand All @@ -51,5 +54,8 @@ Configure the Grafana dashboards for the application

## Outputs

No outputs.
| Name | Description |
|------|-------------|
| <a name="output_dashboard_definition"></a> [dashboard\_definition](#output\_dashboard\_definition) | The JSON definition of the dashboard. |
| <a name="output_prometheus_url"></a> [prometheus\_url](#output\_prometheus\_url) | The URL of the Prometheus server to use for this dashboard. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
26 changes: 26 additions & 0 deletions terraform/monitoring/data_sources.tf
Original file line number Diff line number Diff line change
@@ -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
})
}
23 changes: 0 additions & 23 deletions terraform/monitoring/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 7 additions & 1 deletion terraform/monitoring/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit d3c509f

Please sign in to comment.