From b258d416308b7608cc5e9436465b6a0c6554b10d Mon Sep 17 00:00:00 2001 From: Abdelhak Marouane Date: Wed, 13 Nov 2024 13:59:18 -0600 Subject: [PATCH] Adding condition on s3 event bridge --- sm2a/infrastructure/main.tf | 2 +- sm2a/infrastructure/s3_event_bridge_lambda.tf | 15 ++++++++++----- sm2a/infrastructure/variables.tf | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/sm2a/infrastructure/main.tf b/sm2a/infrastructure/main.tf index 9089222b..5f76aac1 100644 --- a/sm2a/infrastructure/main.tf +++ b/sm2a/infrastructure/main.tf @@ -19,7 +19,7 @@ resource "random_password" "password" { module "sma-base" { - source = "https://github.com/NASA-IMPACT/self-managed-apache-airflow/releases/download/v1.1.4/self-managed-apache-airflow.zip" + source = "https://github.com/NASA-IMPACT/self-managed-apache-airflow/releases/download/v1.1.5/self-managed-apache-airflow.zip" project = var.project_name airflow_db = var.airflow_db fernet_key = var.fernet_key diff --git a/sm2a/infrastructure/s3_event_bridge_lambda.tf b/sm2a/infrastructure/s3_event_bridge_lambda.tf index a4ca3550..f60a8901 100644 --- a/sm2a/infrastructure/s3_event_bridge_lambda.tf +++ b/sm2a/infrastructure/s3_event_bridge_lambda.tf @@ -113,6 +113,7 @@ data "archive_file" "python_lambda_package" { resource "aws_lambda_function" "lambda" { + count = var.eis_storage_bucket_name != null ? 1 : 0 provider = aws.aws_current filename = "/tmp/s3_event_bridge_to_sfn_execute.zip" @@ -127,14 +128,16 @@ resource "aws_lambda_function" "lambda" { variables = { TARGET_DAG_ID = var.target_dag_id SM2A_SECRET_MANAGER_NAME = var.sm2a_secret_manager_name - STORAGE_BUCKET = var.storage_bucket_name - S3_FILTER_PREFIX = var.s3_invoke_filter_prefix + STORAGE_BUCKET = var.eis_storage_bucket_name + S3_FILTER_PREFIX = var.eis_s3_invoke_filter_prefix } } } resource "aws_cloudwatch_log_group" "group" { + count = var.eis_storage_bucket_name != null ? 1 : 0 + provider = aws.aws_current name = "/aws/lambda/${aws_lambda_function.lambda.function_name}" @@ -146,25 +149,27 @@ resource "aws_cloudwatch_log_group" "group" { ##################################################### resource "aws_lambda_permission" "s3_invoke" { + count = var.eis_storage_bucket_name != null ? 1 : 0 provider = aws.aws_current action = "lambda:InvokeFunction" function_name = aws_lambda_function.lambda.function_name principal = "s3.amazonaws.com" statement_id = "AllowInvocationFromS3Bucket-veda-${var.stage}" - source_arn = "arn:aws:s3:::${var.storage_bucket_name}" + source_arn = "arn:aws:s3:::${var.eis_storage_bucket_name}" } resource "aws_s3_bucket_notification" "bucket_notification" { - bucket = var.storage_bucket_name + count = var.eis_storage_bucket_name != null ? 1 : 0 + bucket = var.eis_storage_bucket_name lambda_function { lambda_function_arn = aws_lambda_function.lambda.arn events = ["s3:ObjectCreated:*"] - filter_prefix = var.s3_invoke_filter_prefix + filter_prefix = var.eis_s3_invoke_filter_prefix filter_suffix = ".gpkg" } diff --git a/sm2a/infrastructure/variables.tf b/sm2a/infrastructure/variables.tf index 8056c3d8..db7112d1 100644 --- a/sm2a/infrastructure/variables.tf +++ b/sm2a/infrastructure/variables.tf @@ -216,10 +216,10 @@ variable "stac_url" { variable "vector_secret_name" { } -variable "storage_bucket_name" { +variable "eis_storage_bucket_name" { } -variable "s3_invoke_filter_prefix" { +variable "eis_s3_invoke_filter_prefix" { } variable "sm2a_secret_manager_name" { }