Skip to content

Commit b21f883

Browse files
authored
VED-446 Redis Sync S3 Bucket (#632)
* remove existing_config_bucket * bucket no count
1 parent 7123b2d commit b21f883

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

terraform/redis_sync_lambda.tf

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,8 @@ resource "aws_cloudwatch_log_group" "redis_sync_log_group" {
253253

254254
# S3 Bucket notification to trigger Lambda function for config bucket
255255
resource "aws_s3_bucket_notification" "config_lambda_notification" {
256-
# For now, only create a trigger in internal-dev and prod as those are the envs with a config bucket
257-
count = local.create_config_bucket ? 1 : 0
258256

259-
bucket = aws_s3_bucket.batch_config_bucket[0].bucket
257+
bucket = aws_s3_bucket.batch_config_bucket.bucket
260258

261259
lambda_function {
262260
lambda_function_arn = aws_lambda_function.redis_sync_lambda.arn
@@ -266,7 +264,6 @@ resource "aws_s3_bucket_notification" "config_lambda_notification" {
266264

267265
# Permission for the new S3 bucket to invoke the Lambda function
268266
resource "aws_lambda_permission" "new_s3_invoke_permission" {
269-
count = local.create_config_bucket ? 1 : 0
270267

271268
statement_id = "AllowExecutionFromNewS3"
272269
action = "lambda:InvokeFunction"

terraform/s3_config.tf

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,11 @@ resource "aws_s3_bucket_lifecycle_configuration" "data_destinations" {
192192
}
193193

194194
resource "aws_s3_bucket" "batch_config_bucket" {
195-
# For now, only create in internal-dev and prod as we only have one shared Redis instance per account.
196-
count = local.create_config_bucket ? 1 : 0
197-
198195
bucket = "imms-${local.environment}-supplier-config"
199196
}
200197

201198
resource "aws_s3_bucket_public_access_block" "batch_config_bucket_public_access_block" {
202-
count = local.create_config_bucket ? 1 : 0
203-
204-
bucket = aws_s3_bucket.batch_config_bucket[0].id
199+
bucket = aws_s3_bucket.batch_config_bucket.id
205200

206201
block_public_acls = true
207202
block_public_policy = true
@@ -210,9 +205,7 @@ resource "aws_s3_bucket_public_access_block" "batch_config_bucket_public_access_
210205
}
211206

212207
resource "aws_s3_bucket_policy" "batch_config_bucket_policy" {
213-
count = local.create_config_bucket ? 1 : 0
214-
215-
bucket = aws_s3_bucket.batch_config_bucket[0].id
208+
bucket = aws_s3_bucket.batch_config_bucket.id
216209

217210
policy = jsonencode({
218211
Version = "2012-10-17"
@@ -226,8 +219,8 @@ resource "aws_s3_bucket_policy" "batch_config_bucket_policy" {
226219
}
227220
Action = "s3:*"
228221
Resource = [
229-
aws_s3_bucket.batch_config_bucket[0].arn,
230-
"${aws_s3_bucket.batch_config_bucket[0].arn}/*",
222+
aws_s3_bucket.batch_config_bucket.arn,
223+
"${aws_s3_bucket.batch_config_bucket.arn}/*",
231224
]
232225
Condition = {
233226
Bool = {

terraform/variables.tf

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ locals {
2727
project_domain_name = data.aws_route53_zone.project_zone.name
2828
service_domain_name = "${local.env}.${local.project_domain_name}"
2929

30-
# For now, only create the config bucket in internal-dev and prod as we only have one Redis instance per account.
31-
create_config_bucket = local.environment == local.config_bucket_env
32-
config_bucket_arn = local.create_config_bucket ? aws_s3_bucket.batch_config_bucket[0].arn : data.aws_s3_bucket.existing_config_bucket[0].arn
33-
config_bucket_name = local.create_config_bucket ? aws_s3_bucket.batch_config_bucket[0].bucket : data.aws_s3_bucket.existing_config_bucket[0].bucket
30+
config_bucket_arn = aws_s3_bucket.batch_config_bucket.arn
31+
config_bucket_name = aws_s3_bucket.batch_config_bucket.bucket
32+
3433

3534
# Public subnet - The subnet has a direct route to an internet gateway. Resources in a public subnet can access the public internet.
3635
# public_subnet_ids = [for k, v in data.aws_route.internet_traffic_route_by_subnet : k if length(v.gateway_id) > 0]
@@ -88,13 +87,6 @@ data "aws_security_group" "existing_securitygroup" {
8887
}
8988
}
9089

91-
data "aws_s3_bucket" "existing_config_bucket" {
92-
# For now, look up the internal-dev bucket during int, ref and PR branch deploys.
93-
count = local.create_config_bucket ? 0 : 1
94-
95-
bucket = "imms-${local.config_bucket_env}-supplier-config"
96-
}
97-
9890
data "aws_kms_key" "existing_lambda_encryption_key" {
9991
key_id = "alias/imms-batch-lambda-env-encryption"
10092
}

0 commit comments

Comments
 (0)