Narrow group 1 managed resources
This commit is contained in:
+3
-16
@@ -35,12 +35,9 @@ import {
|
|||||||
}
|
}
|
||||||
|
|
||||||
import {
|
import {
|
||||||
for_each = {
|
for_each = local.bucket_names
|
||||||
cloudtrail = local.bucket_names.cloudtrail
|
to = module.audit_logging_encryption.aws_s3_bucket_lifecycle_configuration.this[each.key]
|
||||||
flowlogs = local.bucket_names.flowlogs
|
id = each.value
|
||||||
}
|
|
||||||
to = module.audit_logging_encryption.aws_s3_bucket_lifecycle_configuration.this[each.key]
|
|
||||||
id = each.value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -59,16 +56,6 @@ import {
|
|||||||
id = each.value.name
|
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 {
|
import {
|
||||||
to = module.audit_logging_encryption.aws_cloudwatch_metric_alarm.billing
|
to = module.audit_logging_encryption.aws_cloudwatch_metric_alarm.billing
|
||||||
id = "awsbilling-AWS-Service-Charges-total"
|
id = "awsbilling-AWS-Service-Charges-total"
|
||||||
|
|||||||
+2
-25
@@ -1,25 +1,10 @@
|
|||||||
locals {
|
locals {
|
||||||
bucket_names = {
|
bucket_names = {
|
||||||
obsidian = "${var.account_id}-obsidian-contents"
|
|
||||||
cloudtrail = "aws-cloudtrail-logs-${var.account_id}-97f3dbeb"
|
cloudtrail = "aws-cloudtrail-logs-${var.account_id}-97f3dbeb"
|
||||||
flowlogs = "kazu634-flowlogs"
|
flowlogs = "kazu634-flowlogs"
|
||||||
}
|
}
|
||||||
|
|
||||||
log_groups = {
|
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 = {
|
vpc_flowlogs = {
|
||||||
name = "nw-vpcflowlogs"
|
name = "nw-vpcflowlogs"
|
||||||
retention_in_days = 14
|
retention_in_days = 14
|
||||||
@@ -40,19 +25,11 @@ module "audit_logging_encryption" {
|
|||||||
account_id = var.account_id
|
account_id = var.account_id
|
||||||
|
|
||||||
bucket_names = local.bucket_names
|
bucket_names = local.bucket_names
|
||||||
bucket_tags = {
|
|
||||||
obsidian = {
|
|
||||||
Env = "Obsidian"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trail_name = "management-events"
|
trail_name = "management-events"
|
||||||
kms_alias_name = "alias/vault-kms"
|
kms_alias_name = "alias/vault-kms"
|
||||||
log_groups = local.log_groups
|
log_groups = local.log_groups
|
||||||
|
|
||||||
dashboard_name = "CostCheck"
|
billing_alarm_name = "awsbilling-AWS-Service-Charges-total"
|
||||||
dashboard_nat_gateway_id = "nat-13131172004a3e65b"
|
billing_alarm_action_arns = ["arn:aws:sns:us-east-1:${var.account_id}:NotifyMe"]
|
||||||
|
|
||||||
sns_topic_name = "NotifyMe"
|
|
||||||
billing_alarm_name = "awsbilling-AWS-Service-Charges-total"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,35 +7,6 @@ resource "aws_cloudwatch_log_group" "this" {
|
|||||||
tags = each.value.tags
|
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" {
|
resource "aws_cloudwatch_metric_alarm" "billing" {
|
||||||
provider = aws.us_east_1
|
provider = aws.us_east_1
|
||||||
|
|
||||||
@@ -49,7 +20,7 @@ resource "aws_cloudwatch_metric_alarm" "billing" {
|
|||||||
statistic = "Maximum"
|
statistic = "Maximum"
|
||||||
threshold = 16
|
threshold = 16
|
||||||
actions_enabled = true
|
actions_enabled = true
|
||||||
alarm_actions = [aws_sns_topic.notify_me.arn]
|
alarm_actions = var.billing_alarm_action_arns
|
||||||
|
|
||||||
dimensions = {
|
dimensions = {
|
||||||
Currency = "USD"
|
Currency = "USD"
|
||||||
|
|||||||
@@ -1,29 +1,12 @@
|
|||||||
locals {
|
locals {
|
||||||
buckets = {
|
buckets = {
|
||||||
obsidian = coalesce(var.bucket_names.obsidian, "${var.name_prefix}-obsidian-contents")
|
|
||||||
cloudtrail = coalesce(var.bucket_names.cloudtrail, "${var.name_prefix}-cloudtrail-logs")
|
cloudtrail = coalesce(var.bucket_names.cloudtrail, "${var.name_prefix}-cloudtrail-logs")
|
||||||
flowlogs = coalesce(var.bucket_names.flowlogs, "${var.name_prefix}-flowlogs")
|
flowlogs = coalesce(var.bucket_names.flowlogs, "${var.name_prefix}-flowlogs")
|
||||||
}
|
}
|
||||||
|
|
||||||
trail_arn = "arn:aws:cloudtrail:${var.region}:${var.account_id}:trail/${var.trail_name}"
|
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}"
|
|
||||||
|
|
||||||
bucket_policies = {
|
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({
|
cloudtrail = jsonencode({
|
||||||
Version = "2012-10-17"
|
Version = "2012-10-17"
|
||||||
Statement = [
|
Statement = [
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ resource "aws_s3_bucket" "this" {
|
|||||||
|
|
||||||
bucket = each.value
|
bucket = each.value
|
||||||
force_destroy = false
|
force_destroy = false
|
||||||
tags = lookup(var.bucket_tags, each.key, {})
|
|
||||||
|
|
||||||
lifecycle {
|
lifecycle {
|
||||||
prevent_destroy = true
|
prevent_destroy = true
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
resource "aws_sns_topic" "notify_me" {
|
|
||||||
provider = aws.us_east_1
|
|
||||||
|
|
||||||
name = var.sns_topic_name
|
|
||||||
}
|
|
||||||
@@ -16,19 +16,12 @@ variable "account_id" {
|
|||||||
variable "bucket_names" {
|
variable "bucket_names" {
|
||||||
description = "Optional existing bucket names. Omitted values are derived from name_prefix for isolated tests."
|
description = "Optional existing bucket names. Omitted values are derived from name_prefix for isolated tests."
|
||||||
type = object({
|
type = object({
|
||||||
obsidian = optional(string)
|
|
||||||
cloudtrail = optional(string)
|
cloudtrail = optional(string)
|
||||||
flowlogs = optional(string)
|
flowlogs = optional(string)
|
||||||
})
|
})
|
||||||
default = {}
|
default = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "bucket_tags" {
|
|
||||||
description = "Existing tags keyed by the logical bucket name."
|
|
||||||
type = map(map(string))
|
|
||||||
default = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "trail_name" {
|
variable "trail_name" {
|
||||||
description = "CloudTrail trail name."
|
description = "CloudTrail trail name."
|
||||||
type = string
|
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" {
|
variable "billing_alarm_name" {
|
||||||
description = "CloudWatch billing alarm name in us-east-1."
|
description = "CloudWatch billing alarm name in us-east-1."
|
||||||
type = string
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user