Prepare group 1 Osaka Terraform tests

This commit is contained in:
2026-11-14 16:33:14 +09:00
parent a1453034c3
commit d52e65383d
7 changed files with 180 additions and 2 deletions
+26
View File
@@ -0,0 +1,26 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "6.73.0"
constraints = "~> 6.73"
hashes = [
"h1:87t8o/A0y2RE3PtCLx/BiASSrDrKSETYTF9jRvKc7aw=",
"zh:0f7403264fbfbcad526a5ddb9553be6ab12dba14e5901d0c2ccabc38d9ccf9a0",
"zh:26be4e8afc94ef29c98b8219dc49b19ce21a04d3f2b4e5be6116e9526ece0355",
"zh:2ba661a4a782fba053c411ce4d828dc148d7ed3998d073a28370a559400b1578",
"zh:2c422d0edd37bf7470c84f1d1f76487f30948768878204a65a18189bf878467a",
"zh:49f9d1486d48033d298977f7c288f8bbb22bb246f00926d1cb8b0bb98985451c",
"zh:4f946cf11667e1f3bce53fd5ad92eccf47fafaa1bbaa68c742173db61773a1da",
"zh:70beb5e13ddcdbeecb2a78be2b75d09a0fc6ce7e69b574c84a90924fd4262406",
"zh:8c5b974104ff9a887b29fdb2700cdbb5e6fd2eceef1cc3b28f523beda4fd8dfb",
"zh:9252068667bc6528ee6e83e837f3c2f901756136a33442455d61c6fa34e1160a",
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
"zh:9d086b792598b43e87502d47c4a3f388465b3a21a6a6b2783e48c89dee1f0543",
"zh:b5e6e77a43c1655285d99145b2cf0cc2da7a6c6ea3531d000cf8cca2c717693b",
"zh:b7ebe893e5ec76b362b61ffb28c67b40d890e0f59f5f2f8829765b16ee3e53b0",
"zh:c8c1e186839ad3cba37b427181af1e62eaf06c6daa5dca29105e1981dfaeb4c2",
"zh:e988377e7aea51e1fefe0b52c78bc725a11327051e20a71f81069191ee077d2d",
"zh:ee9188027919459a48bf9bac8f8f1dd172f5be198b88c2c47789b6daa8bb8bcb",
]
}
@@ -0,0 +1,65 @@
# This file is intentionally outside the default tests/ directory.
# Run it only after per-run human approval with -test-directory=apply-tests.
provider "aws" {
alias = "osaka"
region = "ap-northeast-3"
}
provider "aws" {
alias = "billing"
region = "us-east-1"
}
variables {
region = "ap-northeast-3"
name_prefix = "tftest-g1-7f3a"
protect_from_destroy = false
force_destroy_unprotected_buckets = true
trail_name = "tftest-g1-7f3a-management-events"
cloudtrail_is_multi_region = false
kms_alias_name = "alias/tftest-g1-7f3a-vault"
kms_deletion_window_in_days = 7
log_groups = {
vpc_flowlogs = {
name = "/tftest/g1/7f3a/flowlogs"
retention_in_days = 1
}
}
billing_alarm_name = "tftest-g1-7f3a-billing"
billing_alarm_action_arns = []
}
run "apply_group1_osaka" {
command = apply
providers = {
aws = aws.osaka
aws.us_east_1 = aws.billing
}
assert {
condition = length(aws_s3_bucket.unprotected) == 2 && alltrue([for bucket in aws_s3_bucket.unprotected : bucket.force_destroy])
error_message = "The Osaka test must create two unprotected, force-destroyable S3 buckets."
}
assert {
condition = !aws_cloudtrail.management_events.is_multi_region_trail
error_message = "The Osaka test CloudTrail trail must be single-Region."
}
assert {
condition = aws_kms_key.vault_unprotected[0].deletion_window_in_days == 7
error_message = "The Osaka test KMS key must use the minimum seven-day deletion window."
}
assert {
condition = try(length(aws_cloudwatch_metric_alarm.billing.alarm_actions), 0) == 0
error_message = "The Osaka test billing alarm must not notify production targets."
}
}
@@ -2,7 +2,7 @@ resource "aws_cloudtrail" "management_events" {
name = var.trail_name name = var.trail_name
s3_bucket_name = local.bucket_ids["cloudtrail"] s3_bucket_name = local.bucket_ids["cloudtrail"]
include_global_service_events = true include_global_service_events = true
is_multi_region_trail = true is_multi_region_trail = var.cloudtrail_is_multi_region
is_organization_trail = false is_organization_trail = false
enable_log_file_validation = false enable_log_file_validation = false
enable_logging = true enable_logging = true
+2
View File
@@ -6,6 +6,7 @@ resource "aws_kms_key" "vault_protected" {
customer_master_key_spec = "SYMMETRIC_DEFAULT" customer_master_key_spec = "SYMMETRIC_DEFAULT"
enable_key_rotation = false enable_key_rotation = false
multi_region = false multi_region = false
deletion_window_in_days = var.kms_deletion_window_in_days
policy = local.kms_policy policy = local.kms_policy
lifecycle { lifecycle {
@@ -25,6 +26,7 @@ resource "aws_kms_key" "vault_unprotected" {
customer_master_key_spec = "SYMMETRIC_DEFAULT" customer_master_key_spec = "SYMMETRIC_DEFAULT"
enable_key_rotation = false enable_key_rotation = false
multi_region = false multi_region = false
deletion_window_in_days = var.kms_deletion_window_in_days
policy = local.kms_policy policy = local.kms_policy
lifecycle { lifecycle {
+1 -1
View File
@@ -13,7 +13,7 @@ resource "aws_s3_bucket" "unprotected" {
for_each = var.protect_from_destroy ? {} : local.buckets for_each = var.protect_from_destroy ? {} : local.buckets
bucket = each.value bucket = each.value
force_destroy = false force_destroy = var.force_destroy_unprotected_buckets
} }
resource "aws_s3_bucket_versioning" "this" { resource "aws_s3_bucket_versioning" "this" {
@@ -0,0 +1,62 @@
provider "aws" {
alias = "osaka"
region = "ap-northeast-3"
}
provider "aws" {
alias = "billing"
region = "us-east-1"
}
variables {
region = "ap-northeast-3"
name_prefix = "tftest-g1-7f3a"
protect_from_destroy = false
force_destroy_unprotected_buckets = true
trail_name = "tftest-g1-7f3a-management-events"
cloudtrail_is_multi_region = false
kms_alias_name = "alias/tftest-g1-7f3a-vault"
kms_deletion_window_in_days = 7
log_groups = {
vpc_flowlogs = {
name = "/tftest/g1/7f3a/flowlogs"
retention_in_days = 1
}
}
billing_alarm_name = "tftest-g1-7f3a-billing"
billing_alarm_action_arns = []
}
run "plan_group1_osaka" {
command = plan
providers = {
aws = aws.osaka
aws.us_east_1 = aws.billing
}
assert {
condition = length(aws_s3_bucket.unprotected) == 2 && alltrue([for bucket in aws_s3_bucket.unprotected : bucket.force_destroy])
error_message = "The Osaka test must create two unprotected, force-destroyable S3 buckets."
}
assert {
condition = !aws_cloudtrail.management_events.is_multi_region_trail
error_message = "The Osaka test CloudTrail trail must be single-Region."
}
assert {
condition = aws_kms_key.vault_unprotected[0].deletion_window_in_days == 7
error_message = "The Osaka test KMS key must use the minimum seven-day deletion window."
}
assert {
condition = try(length(aws_cloudwatch_metric_alarm.billing.alarm_actions), 0) == 0
error_message = "The Osaka test billing alarm must not notify production targets."
}
}
@@ -19,6 +19,12 @@ variable "protect_from_destroy" {
default = true default = true
} }
variable "force_destroy_unprotected_buckets" {
description = "Allow Terraform to delete objects while destroying unprotected test buckets. Protected production buckets always keep force_destroy=false."
type = bool
default = false
}
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({
@@ -33,11 +39,28 @@ variable "trail_name" {
type = string type = string
} }
variable "cloudtrail_is_multi_region" {
description = "Whether CloudTrail records events from all AWS Regions. Production keeps this true; isolated regional tests set it false."
type = bool
default = true
}
variable "kms_alias_name" { variable "kms_alias_name" {
description = "Alias of the customer managed Vault key." description = "Alias of the customer managed Vault key."
type = string type = string
} }
variable "kms_deletion_window_in_days" {
description = "Waiting period before permanent KMS key deletion. Isolated tests use the minimum seven days."
type = number
default = 30
validation {
condition = var.kms_deletion_window_in_days >= 7 && var.kms_deletion_window_in_days <= 30
error_message = "kms_deletion_window_in_days must be between 7 and 30."
}
}
variable "log_groups" { variable "log_groups" {
description = "CloudWatch log groups and their retention in days. Null means never expire." description = "CloudWatch log groups and their retention in days. Null means never expire."
type = map(object({ type = map(object({