From 94a5c2bf558c88502a42436de24e7e221357a4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E8=94=B5=E4=B8=80=E5=BC=98?= Date: Sat, 14 Nov 2026 13:42:43 +0900 Subject: [PATCH] Narrow group 1 managed resources --- envs/prod/imports.tf | 19 ++---------- envs/prod/main.tf | 27 ++-------------- .../audit_logging_encryption/cloudwatch.tf | 31 +------------------ modules/audit_logging_encryption/locals.tf | 19 +----------- modules/audit_logging_encryption/s3.tf | 1 - modules/audit_logging_encryption/sns.tf | 5 --- modules/audit_logging_encryption/variables.tf | 27 +++------------- 7 files changed, 12 insertions(+), 117 deletions(-) delete mode 100644 modules/audit_logging_encryption/sns.tf diff --git a/envs/prod/imports.tf b/envs/prod/imports.tf index 10c5a5f..4f5e0a1 100644 --- a/envs/prod/imports.tf +++ b/envs/prod/imports.tf @@ -35,12 +35,9 @@ import { } import { - for_each = { - cloudtrail = local.bucket_names.cloudtrail - flowlogs = local.bucket_names.flowlogs - } - to = module.audit_logging_encryption.aws_s3_bucket_lifecycle_configuration.this[each.key] - id = each.value + for_each = local.bucket_names + to = module.audit_logging_encryption.aws_s3_bucket_lifecycle_configuration.this[each.key] + id = each.value } import { @@ -59,16 +56,6 @@ import { id = each.value.name } -import { - to = module.audit_logging_encryption.aws_cloudwatch_dashboard.cost_check - id = "CostCheck" -} - -import { - to = module.audit_logging_encryption.aws_sns_topic.notify_me - id = "arn:aws:sns:us-east-1:${var.account_id}:NotifyMe" -} - import { to = module.audit_logging_encryption.aws_cloudwatch_metric_alarm.billing id = "awsbilling-AWS-Service-Charges-total" diff --git a/envs/prod/main.tf b/envs/prod/main.tf index eb86e08..a01c803 100644 --- a/envs/prod/main.tf +++ b/envs/prod/main.tf @@ -1,25 +1,10 @@ locals { bucket_names = { - obsidian = "${var.account_id}-obsidian-contents" cloudtrail = "aws-cloudtrail-logs-${var.account_id}-97f3dbeb" flowlogs = "kazu634-flowlogs" } log_groups = { - ecs_a49f = { - name = "/aws/ecs/default/nginx-a49f-48d8" - tags = { - AmazonECSManaged = "true" - category = "ecs-test" - } - } - ecs_d2a0 = { - name = "/aws/ecs/default/nginx-d2a0-c9dc" - tags = { - AmazonECSManaged = "true" - category = "ecs-test" - } - } vpc_flowlogs = { name = "nw-vpcflowlogs" retention_in_days = 14 @@ -40,19 +25,11 @@ module "audit_logging_encryption" { account_id = var.account_id bucket_names = local.bucket_names - bucket_tags = { - obsidian = { - Env = "Obsidian" - } - } trail_name = "management-events" kms_alias_name = "alias/vault-kms" log_groups = local.log_groups - dashboard_name = "CostCheck" - dashboard_nat_gateway_id = "nat-13131172004a3e65b" - - sns_topic_name = "NotifyMe" - billing_alarm_name = "awsbilling-AWS-Service-Charges-total" + billing_alarm_name = "awsbilling-AWS-Service-Charges-total" + billing_alarm_action_arns = ["arn:aws:sns:us-east-1:${var.account_id}:NotifyMe"] } diff --git a/modules/audit_logging_encryption/cloudwatch.tf b/modules/audit_logging_encryption/cloudwatch.tf index 456ea69..d38f77d 100644 --- a/modules/audit_logging_encryption/cloudwatch.tf +++ b/modules/audit_logging_encryption/cloudwatch.tf @@ -7,35 +7,6 @@ resource "aws_cloudwatch_log_group" "this" { tags = each.value.tags } -resource "aws_cloudwatch_dashboard" "cost_check" { - dashboard_name = var.dashboard_name - dashboard_body = jsonencode({ - widgets = [{ - type = "metric" - x = 0 - y = 0 - width = 23 - height = 7 - properties = { - view = "timeSeries" - stacked = true - metrics = [ - ["AWS/NATGateway", "BytesOutToSource", "AvailabilityZone", "ap-northeast-1a", "NatGatewayId", var.dashboard_nat_gateway_id], - [".", "BytesOutToDestination", ".", ".", ".", "."], - [".", "BytesInFromDestination", ".", ".", ".", "."], - [".", "BytesInFromSource", ".", ".", ".", "."], - [".", "BytesInFromDestination", ".", "ap-northeast-1c", ".", "."], - [".", "BytesInFromSource", ".", ".", ".", "."], - [".", "BytesOutToDestination", ".", ".", ".", "."], - [".", "BytesOutToSource", ".", ".", ".", "."], - ] - region = var.region - title = "NAT Gayeway通信量" - } - }] - }) -} - resource "aws_cloudwatch_metric_alarm" "billing" { provider = aws.us_east_1 @@ -49,7 +20,7 @@ resource "aws_cloudwatch_metric_alarm" "billing" { statistic = "Maximum" threshold = 16 actions_enabled = true - alarm_actions = [aws_sns_topic.notify_me.arn] + alarm_actions = var.billing_alarm_action_arns dimensions = { Currency = "USD" diff --git a/modules/audit_logging_encryption/locals.tf b/modules/audit_logging_encryption/locals.tf index 64eacd4..2ff805f 100644 --- a/modules/audit_logging_encryption/locals.tf +++ b/modules/audit_logging_encryption/locals.tf @@ -1,29 +1,12 @@ locals { buckets = { - obsidian = coalesce(var.bucket_names.obsidian, "${var.name_prefix}-obsidian-contents") cloudtrail = coalesce(var.bucket_names.cloudtrail, "${var.name_prefix}-cloudtrail-logs") flowlogs = coalesce(var.bucket_names.flowlogs, "${var.name_prefix}-flowlogs") } - trail_arn = "arn:aws:cloudtrail:${var.region}:${var.account_id}:trail/${var.trail_name}" - sns_topic_arn = "arn:aws:sns:us-east-1:${var.account_id}:${var.sns_topic_name}" + trail_arn = "arn:aws:cloudtrail:${var.region}:${var.account_id}:trail/${var.trail_name}" bucket_policies = { - obsidian = jsonencode({ - Version = "2012-10-17" - Statement = [{ - Effect = "Allow" - Principal = { - AWS = "arn:aws:iam::${var.account_id}:user/${var.account_id}-obsidian-contents" - } - Action = "s3:*" - Resource = [ - "arn:aws:s3:::${local.buckets.obsidian}", - "arn:aws:s3:::${local.buckets.obsidian}/*", - ] - }] - }) - cloudtrail = jsonencode({ Version = "2012-10-17" Statement = [ diff --git a/modules/audit_logging_encryption/s3.tf b/modules/audit_logging_encryption/s3.tf index 3075726..ad76e0f 100644 --- a/modules/audit_logging_encryption/s3.tf +++ b/modules/audit_logging_encryption/s3.tf @@ -3,7 +3,6 @@ resource "aws_s3_bucket" "this" { bucket = each.value force_destroy = false - tags = lookup(var.bucket_tags, each.key, {}) lifecycle { prevent_destroy = true diff --git a/modules/audit_logging_encryption/sns.tf b/modules/audit_logging_encryption/sns.tf deleted file mode 100644 index 977b7e0..0000000 --- a/modules/audit_logging_encryption/sns.tf +++ /dev/null @@ -1,5 +0,0 @@ -resource "aws_sns_topic" "notify_me" { - provider = aws.us_east_1 - - name = var.sns_topic_name -} diff --git a/modules/audit_logging_encryption/variables.tf b/modules/audit_logging_encryption/variables.tf index fa29eb3..18fb3e5 100644 --- a/modules/audit_logging_encryption/variables.tf +++ b/modules/audit_logging_encryption/variables.tf @@ -16,19 +16,12 @@ variable "account_id" { variable "bucket_names" { description = "Optional existing bucket names. Omitted values are derived from name_prefix for isolated tests." type = object({ - obsidian = optional(string) cloudtrail = optional(string) flowlogs = optional(string) }) default = {} } -variable "bucket_tags" { - description = "Existing tags keyed by the logical bucket name." - type = map(map(string)) - default = {} -} - variable "trail_name" { description = "CloudTrail trail name." type = string @@ -48,22 +41,12 @@ variable "log_groups" { })) } -variable "dashboard_name" { - description = "CloudWatch dashboard name." - type = string -} - -variable "dashboard_nat_gateway_id" { - description = "NAT Gateway ID referenced by the existing dashboard widget." - type = string -} - -variable "sns_topic_name" { - description = "SNS topic name in us-east-1." - type = string -} - variable "billing_alarm_name" { description = "CloudWatch billing alarm name in us-east-1." type = string } + +variable "billing_alarm_action_arns" { + description = "Existing notification target ARNs for the billing alarm. The targets themselves are not managed by this module." + type = list(string) +}