Skip to content

Commit

Permalink
[GDB-10130] Improve tagging of resources
Browse files Browse the repository at this point in the history
  • Loading branch information
simonzhekoff committed Apr 16, 2024
1 parent be05741 commit 075a3bc
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 29 deletions.
12 changes: 3 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ locals {

module "monitoring" {
source = "./modules/monitoring"
providers = {
aws.monitoring = aws.monitoring
}

count = var.deploy_monitoring ? 1 : 0

Expand All @@ -62,20 +65,11 @@ module "monitoring" {
cloudwatch_log_group_retention_in_days = var.monitoring_log_group_retention_in_days
route53_availability_request_url = module.load_balancer.lb_dns_name
route53_availability_measure_latency = var.monitoring_route53_measure_latency

providers = {
aws.main = aws.main
aws.monitoring = aws.monitoring
}
}

module "graphdb" {
source = "./modules/graphdb"

providers = {
aws.main = aws.main
}

resource_name_prefix = var.resource_name_prefix
aws_region = data.aws_region.current.name
aws_subscription_id = data.aws_caller_identity.current.account_id
Expand Down
1 change: 0 additions & 1 deletion modules/graphdb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ data "aws_ami" "graphdb" {
}

data "aws_default_tags" "current" {
provider = aws.main
}

data "aws_subnet" "subnet" {
Expand Down
5 changes: 2 additions & 3 deletions modules/graphdb/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ terraform {

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.15"
configuration_aliases = [aws.main]
source = "hashicorp/aws"
version = "~> 5.15"
}
}
}
7 changes: 0 additions & 7 deletions modules/monitoring/alarms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Attempting to recover metric filter
resource "aws_cloudwatch_log_metric_filter" "graphdb_attempting_to_recover_metric_filter" {
provider = aws.main
name = "mf-${var.resource_name_prefix}-attempting-to-recover"
pattern = "successfully replicated registration will not retry"
log_group_name = aws_cloudwatch_log_group.graphdb_log_group.name
Expand All @@ -20,7 +19,6 @@ resource "aws_cloudwatch_log_metric_filter" "graphdb_attempting_to_recover_metri
# Attempting to recover alarm based on metric filter

resource "aws_cloudwatch_metric_alarm" "graphdb_attempting_to_recover_alarm" {
provider = aws.main
alarm_name = "al-${var.resource_name_prefix}-attempting-recover"
alarm_description = "Attempting to recover through snapshot replication"
comparison_operator = "GreaterThanThreshold"
Expand All @@ -38,7 +36,6 @@ resource "aws_cloudwatch_metric_alarm" "graphdb_attempting_to_recover_alarm" {
# Log filter for low disk space messages in the logs

resource "aws_cloudwatch_log_metric_filter" "graphdb_low_disk_space_metric_filter" {
provider = aws.main
name = "al-${var.resource_name_prefix}-low-disk-space"
pattern = "No space left on the device"
log_group_name = aws_cloudwatch_log_group.graphdb_log_group.name
Expand All @@ -56,7 +53,6 @@ resource "aws_cloudwatch_log_metric_filter" "graphdb_low_disk_space_metric_filte
# Alarm based on metric filter for Low Disk Space messages in the logs

resource "aws_cloudwatch_metric_alarm" "graphdb_low_disk_space_alarm" {
provider = aws.main
alarm_name = "al-${var.resource_name_prefix}-low-disk-space"
alarm_description = "Low Disk Space"
comparison_operator = "GreaterThanThreshold"
Expand All @@ -74,7 +70,6 @@ resource "aws_cloudwatch_metric_alarm" "graphdb_low_disk_space_alarm" {
# TODO: Currently this alarm won't work because it relies on the instance IDs which need to be parsed dynamically. The workarounds are remote state, or restructruting the current modules in order to parse the EC2 InstanceIDs from the VM module.

resource "aws_cloudwatch_metric_alarm" "graphdb_memory_utilization" {
provider = aws.main
alarm_name = "al-${var.resource_name_prefix}-memory-utilization"
alarm_description = "Alarm will trigger if Memory utilization is above 90%"
comparison_operator = "GreaterThanThreshold"
Expand All @@ -97,7 +92,6 @@ resource "aws_cloudwatch_metric_alarm" "graphdb_memory_utilization" {
# Alarm for CPU Utilization for Autoscaling Group

resource "aws_cloudwatch_metric_alarm" "graphdb_cpu_utilization" {
provider = aws.main
alarm_name = "al-${var.resource_name_prefix}-cpu-utilization"
alarm_description = "Alarm will trigger if CPU utilization is above 80%"
comparison_operator = "GreaterThanThreshold"
Expand All @@ -118,7 +112,6 @@ resource "aws_cloudwatch_metric_alarm" "graphdb_cpu_utilization" {

# Alarm for nodes disconnected
resource "aws_cloudwatch_metric_alarm" "graphdb_nodes_disconnected" {
provider = aws.main
alarm_name = "al-${var.resource_name_prefix}-nodes-disconnected"
alarm_description = "Alarm will trigger if a node has been disconnected"
actions_enabled = true
Expand Down
3 changes: 0 additions & 3 deletions modules/monitoring/main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Cloudwatch log group which hosts the logs

resource "aws_cloudwatch_log_group" "graphdb_log_group" {
provider = aws.main
name = var.resource_name_prefix
retention_in_days = var.cloudwatch_log_group_retention_in_days
}

# SSM Parameter which hosts the config for the cloudwatch agent

resource "aws_ssm_parameter" "graphdb_cloudwatch_agent_config" {
provider = aws.main
name = "/${var.resource_name_prefix}/graphdb/CWAgent/Config"
description = "Cloudwatch Agent Configuration"
type = var.ssm_parameter_store_ssm_parameter_type
Expand All @@ -23,7 +21,6 @@ resource "aws_ssm_parameter" "graphdb_cloudwatch_agent_config" {
# Cloudwatch Dashboard

resource "aws_cloudwatch_dashboard" "graphdb_dashboard" {
provider = aws.main
dashboard_name = var.resource_name_prefix
dashboard_body = templatefile("${path.module}/graphdb_dashboard.json", {
health_check_id = aws_route53_health_check.graphdb_availability_check.id
Expand Down
2 changes: 0 additions & 2 deletions modules/monitoring/sns.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# SNS Topic

resource "aws_sns_topic" "graphdb_sns_topic" {
provider = aws.main
name = "${var.resource_name_prefix}-graphdb-notifications"
kms_master_key_id = "alias/aws/sns"
}

# SNS Topic subscription

resource "aws_sns_topic_subscription" "graphdb_sns_topic_subscription" {
provider = aws.main
topic_arn = aws_sns_topic.graphdb_sns_topic.id
protocol = var.sns_protocol
endpoint = var.sns_topic_endpoint
Expand Down
2 changes: 1 addition & 1 deletion modules/monitoring/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ terraform {
aws = {
source = "hashicorp/aws"
version = "~> 5.15"
configuration_aliases = [aws.main, aws.monitoring]
configuration_aliases = [aws.monitoring]
}
}
}
1 change: 0 additions & 1 deletion provider.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
provider "aws" {
region = var.aws_region
alias = "main"
default_tags {
tags = merge(
{
Expand Down
5 changes: 3 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ terraform {

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.15"
source = "hashicorp/aws"
version = "~> 5.15"
configuration_aliases = [aws.monitoring]
}

random = {
Expand Down

0 comments on commit 075a3bc

Please sign in to comment.