Skip to content

Commit

Permalink
UML-1959 Create Cloudwatch dashboard in Terraform (#2542)
Browse files Browse the repository at this point in the history
* UML-1959 Create Cloudwatch dashboard in Terraform
  • Loading branch information
Sam Ainsworth authored Mar 13, 2024
1 parent 6a51e04 commit a9115c3
Show file tree
Hide file tree
Showing 10 changed files with 469 additions and 11 deletions.
2 changes: 2 additions & 0 deletions terraform/environment/region.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module "eu_west_1" {
container_version = var.container_version
cookie_expires_use = local.environment.cookie_expires_use
cookie_expires_view = local.environment.cookie_expires_view
create_dashboard = local.environment.create_dashboard
dns_namespace_env = local.dns_namespace_env
ecs_execution_role = module.iam.ecs_execution_role
ecs_task_roles = module.iam.ecs_task_roles
Expand Down Expand Up @@ -89,6 +90,7 @@ module "eu_west_2" {
container_version = var.container_version
cookie_expires_use = local.environment.cookie_expires_use
cookie_expires_view = local.environment.cookie_expires_view
create_dashboard = local.environment.create_dashboard
dns_namespace_env = local.dns_namespace_env
ecs_execution_role = module.iam.ecs_execution_role
ecs_task_roles = module.iam.ecs_task_roles
Expand Down
17 changes: 17 additions & 0 deletions terraform/environment/region/cloudwatch_dashboard.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "aws_cloudwatch_dashboard" "main" {
count = var.create_dashboard ? 1 : 0
dashboard_name = "${var.environment_name}-${data.aws_region.current.name}-dashboard"
dashboard_body = templatefile("${path.module}/templates/cw_dashboard_watching.tftpl", {
region = data.aws_region.current.name,
environment = var.environment_name,
viewer_alb_arn = local.viewer_alb_arn,
use_alb_arn = local.use_alb_arn
})

provider = aws.region
}

locals {
viewer_alb_arn = trimprefix(aws_lb.viewer.arn, "arn:aws:elasticloadbalancing:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:loadbalancer/")
use_alb_arn = trimprefix(aws_lb.use.arn, "arn:aws:elasticloadbalancing:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:loadbalancer/")
}
14 changes: 14 additions & 0 deletions terraform/environment/region/data_sources.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
data "aws_vpc" "default" {
default = "true"

provider = aws.region
}

data "aws_region" "current" {
provider = aws.region
}

data "aws_caller_identity" "current" {
provider = aws.region
}

data "aws_subnets" "private" {
filter {
name = "vpc-id"
Expand Down
Loading

0 comments on commit a9115c3

Please sign in to comment.