diff --git a/infrastructure/cloudtrail.tf b/infrastructure/cloudtrail.tf index c3bb7183..d8e5b73c 100644 --- a/infrastructure/cloudtrail.tf +++ b/infrastructure/cloudtrail.tf @@ -4,7 +4,7 @@ resource "aws_cloudtrail" "all-events" { s3_bucket_name = var.cloudtrail_bucket_name kms_key_id = aws_kms_key.key.arn cloud_watch_logs_group_arn = "${aws_cloudwatch_log_group.cloudtrail.arn}:*" - cloud_watch_logs_role_arn = "arn:aws-us-gov:iam::${data.aws_caller_identity.current.account_id}:role/${var.cloudtrail_role_name}" + cloud_watch_logs_role_arn = "arn:${var.aws_partition}:iam::${data.aws_caller_identity.current.account_id}:role/${var.cloudtrail_role_name}" tags = { Project = var.project Stage = var.stage @@ -14,11 +14,11 @@ resource "aws_cloudtrail" "all-events" { include_management_events = true data_resource { type = "AWS::S3::Object" - values = ["arn:aws-us-gov:s3"] + values = ["arn:${var.aws_partition}:s3"] } data_resource { type = "AWS::Lambda::Function" - values = ["arn:aws-us-gov:lambda"] + values = ["arn:${var.aws_partition}:lambda"] } } enable_log_file_validation = true @@ -100,8 +100,9 @@ resource "aws_iam_role" "cloudtrail_role" { data "template_file" "cloudtrail_bucket_policy" { template = file("cloudtrail_bucket_policy.tpl") vars = { - bucketName = var.cloudtrail_bucket_name - accountId = data.aws_caller_identity.current.account_id + bucketName = var.cloudtrail_bucket_name + accountId = data.aws_caller_identity.current.account_id + awsPartition = var.aws_partition } } @@ -138,7 +139,7 @@ resource "aws_iam_role_policy" "cloudtrail_cloudwatch_policy" { "logs:PutLogEvents" ], Effect = "Allow", - Resource = "arn:aws-us-gov:logs:*" + Resource = "arn:${var.aws_partition}:logs:*" }] }) } diff --git a/infrastructure/cloudtrail_bucket_policy.tpl b/infrastructure/cloudtrail_bucket_policy.tpl index 0ba644de..955a71fd 100644 --- a/infrastructure/cloudtrail_bucket_policy.tpl +++ b/infrastructure/cloudtrail_bucket_policy.tpl @@ -8,7 +8,7 @@ "Service": "cloudtrail.amazonaws.com" }, "Action": ["s3:GetBucketAcl"], - "Resource": ["arn:aws-us-gov:s3:::${bucketName}"] + "Resource": ["arn:${awsPartition}:s3:::${bucketName}"] }, { "Sid": "AWSCloudTrailWrite20121017", @@ -18,8 +18,8 @@ }, "Action": ["s3:PutObject"], "Resource": [ - "arn:aws-us-gov:s3:::${bucketName}/AWSLogs/${accountId}", - "arn:aws-us-gov:s3:::${bucketName}/AWSLogs/${accountId}/*" + "arn:${awsPartition}:s3:::${bucketName}/AWSLogs/${accountId}", + "arn:${awsPartition}:s3:::${bucketName}/AWSLogs/${accountId}/*" ], "Condition": { "StringEquals": { @@ -33,8 +33,8 @@ "Effect": "Deny", "Principal": "*", "Resource": [ - "arn:aws-us-gov:s3:::${bucketName}", - "arn:aws-us-gov:s3:::${bucketName}/*" + "arn:${awsPartition}:s3:::${bucketName}", + "arn:${awsPartition}:s3:::${bucketName}/*" ], "Condition": { "Bool": { @@ -43,4 +43,4 @@ } } ] -} \ No newline at end of file +} diff --git a/infrastructure/database.tf b/infrastructure/database.tf index a76dddf1..5bca2b85 100644 --- a/infrastructure/database.tf +++ b/infrastructure/database.tf @@ -3,7 +3,7 @@ data "aws_ssm_parameter" "db_username" { name = var.ssm_db_username } resource "aws_db_subnet_group" "default" { name = var.db_group_name - subnet_ids = [data.aws_ssm_parameter.subnet_db_1_id.value, data.aws_ssm_parameter.subnet_db_2_id.value] + subnet_ids = var.is_dmz ? [aws_subnet.db_1[0].id, aws_subnet.db_2[0].id] : [data.aws_ssm_parameter.subnet_db_1_id[0].value, data.aws_ssm_parameter.subnet_db_2_id[0].value] tags = { Project = var.project @@ -52,7 +52,7 @@ resource "aws_db_instance" "db" { db_subnet_group_name = aws_db_subnet_group.default.name parameter_group_name = aws_db_parameter_group.default.name - vpc_security_group_ids = [aws_security_group.allow_internal.id] + vpc_security_group_ids = [var.is_dmz ? aws_security_group.allow_internal[0].id : aws_security_group.allow_internal_lz[0].id] tags = { Project = "Crossfeed" @@ -60,7 +60,26 @@ resource "aws_db_instance" "db" { } } +data "aws_ami" "ubuntu" { + count = var.is_dmz ? 1 : 0 + most_recent = true + + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + # Canonical + owners = ["099720109477"] +} + resource "aws_iam_role" "db_accessor" { + count = var.create_db_accessor_instance ? 1 : 0 name = "crossfeed-db-accessor-${var.stage}" assume_role_policy = <