resource "aws_cloudwatch_log_group" "this" { for_each = var.log_groups name = each.value.name retention_in_days = each.value.retention_in_days log_group_class = "STANDARD" 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 alarm_name = var.billing_alarm_name alarm_description = "Created from CloudWatch console" comparison_operator = "GreaterThanThreshold" evaluation_periods = 1 metric_name = "EstimatedCharges" namespace = "AWS/Billing" period = 21600 statistic = "Maximum" threshold = 16 actions_enabled = true alarm_actions = [aws_sns_topic.notify_me.arn] dimensions = { Currency = "USD" } }