From 075a3bc539587bc10e6d52b3fe3bea38bb540c67 Mon Sep 17 00:00:00 2001 From: "simeon.zhekov" Date: Tue, 16 Apr 2024 15:38:29 +0300 Subject: [PATCH] [GDB-10130] Improve tagging of resources --- main.tf | 12 +++--------- modules/graphdb/main.tf | 1 - modules/graphdb/versions.tf | 5 ++--- modules/monitoring/alarms.tf | 7 ------- modules/monitoring/main.tf | 3 --- modules/monitoring/sns.tf | 2 -- modules/monitoring/versions.tf | 2 +- provider.tf | 1 - versions.tf | 5 +++-- 9 files changed, 9 insertions(+), 29 deletions(-) diff --git a/main.tf b/main.tf index 924c527..fc70b31 100644 --- a/main.tf +++ b/main.tf @@ -49,6 +49,9 @@ locals { module "monitoring" { source = "./modules/monitoring" + providers = { + aws.monitoring = aws.monitoring + } count = var.deploy_monitoring ? 1 : 0 @@ -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 diff --git a/modules/graphdb/main.tf b/modules/graphdb/main.tf index 4220362..fe0ee77 100644 --- a/modules/graphdb/main.tf +++ b/modules/graphdb/main.tf @@ -29,7 +29,6 @@ data "aws_ami" "graphdb" { } data "aws_default_tags" "current" { - provider = aws.main } data "aws_subnet" "subnet" { diff --git a/modules/graphdb/versions.tf b/modules/graphdb/versions.tf index 2337955..761245a 100644 --- a/modules/graphdb/versions.tf +++ b/modules/graphdb/versions.tf @@ -3,9 +3,8 @@ terraform { required_providers { aws = { - source = "hashicorp/aws" - version = "~> 5.15" - configuration_aliases = [aws.main] + source = "hashicorp/aws" + version = "~> 5.15" } } } diff --git a/modules/monitoring/alarms.tf b/modules/monitoring/alarms.tf index 8d111eb..74fa361 100644 --- a/modules/monitoring/alarms.tf +++ b/modules/monitoring/alarms.tf @@ -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 @@ -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" @@ -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 @@ -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" @@ -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" @@ -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" @@ -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 diff --git a/modules/monitoring/main.tf b/modules/monitoring/main.tf index 2711b6e..52eb554 100644 --- a/modules/monitoring/main.tf +++ b/modules/monitoring/main.tf @@ -1,7 +1,6 @@ # 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 } @@ -9,7 +8,6 @@ resource "aws_cloudwatch_log_group" "graphdb_log_group" { # 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 @@ -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 diff --git a/modules/monitoring/sns.tf b/modules/monitoring/sns.tf index 73f6c5d..ab03254 100644 --- a/modules/monitoring/sns.tf +++ b/modules/monitoring/sns.tf @@ -1,7 +1,6 @@ # 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" } @@ -9,7 +8,6 @@ resource "aws_sns_topic" "graphdb_sns_topic" { # 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 diff --git a/modules/monitoring/versions.tf b/modules/monitoring/versions.tf index 590c6ad..5e11fbf 100644 --- a/modules/monitoring/versions.tf +++ b/modules/monitoring/versions.tf @@ -5,7 +5,7 @@ terraform { aws = { source = "hashicorp/aws" version = "~> 5.15" - configuration_aliases = [aws.main, aws.monitoring] + configuration_aliases = [aws.monitoring] } } } diff --git a/provider.tf b/provider.tf index 74a9b0d..deddf5d 100644 --- a/provider.tf +++ b/provider.tf @@ -1,6 +1,5 @@ provider "aws" { region = var.aws_region - alias = "main" default_tags { tags = merge( { diff --git a/versions.tf b/versions.tf index a9ee1fd..7ac4e11 100644 --- a/versions.tf +++ b/versions.tf @@ -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 = {