Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Testing Terraform configuration #973

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions Core/Testing/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ variable "environment" {
type = string
}

variable "test_data_bucket" {
type = string
}

variable "viz_initialize_pipeline_arn" {
type = string
}

variable "lambda_role" {
type = string
}

variable "s3_module" {
type = any
}
Expand All @@ -26,6 +14,11 @@ variable "step_function_module" {
type = any
}

locals {
test_bucket = var.s3_module.buckets["deployment"].bucket
init_pipeline_lambda = var.lambda_module.initialize_pipeline
}

resource "aws_cloudwatch_event_rule" "detect_test_files" {
name = "hv-vpp-${var.environment}-detect-test-files"
description = "Detects when a new test file has been created"
Expand All @@ -35,7 +28,7 @@ resource "aws_cloudwatch_event_rule" "detect_test_files" {
"detail-type": ["Object Created"],
"detail": {
"bucket": {
"name": ["${var.test_data_bucket}"]
"name": ["${local.test_bucket}"]
},
"object": {
"key": [{
Expand All @@ -47,11 +40,18 @@ resource "aws_cloudwatch_event_rule" "detect_test_files" {
EOF
}

resource "aws_lambda_permission" "allow_cloudwatch_to_call_initialize_pipeline" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = local.init_pipeline_lambda.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.detect_test_files.arn
}

resource "aws_cloudwatch_event_target" "trigger_pipeline_test_run" {
rule = aws_cloudwatch_event_rule.detect_test_files.name
target_id = "initialize_pipeline"
arn = var.viz_initialize_pipeline_arn
role_arn = var.lambda_role
target_id = local.init_pipeline_lambda.function_name
arn = local.init_pipeline_lambda.arn
input_transformer {
input_paths = {
"s3_bucket": "$.detail.bucket.name",
Expand All @@ -75,15 +75,15 @@ resource "aws_cloudwatch_event_target" "trigger_pipeline_test_run" {
###### KICK OFF TESTS IN TI ######
##################################
data "aws_s3_objects" "test_nwm_outputs" {
bucket = var.test_data_bucket
bucket = local.test_bucket
prefix = "test_nwm_outputs/"
max_keys = 2000
}

resource "aws_s3_object_copy" "test" {
depends_on = [var.s3_module, var.lambda_module, var.step_function_module, aws_cloudwatch_event_target.trigger_pipeline_test_run]
count = length(data.aws_s3_objects.test_nwm_outputs.keys)
bucket = var.test_data_bucket
source = join("/", [var.test_data_bucket, element(data.aws_s3_objects.test_nwm_outputs.keys, count.index)])
bucket = local.test_bucket
source = join("/", [local.test_bucket, element(data.aws_s3_objects.test_nwm_outputs.keys, count.index)])
key = replace(element(data.aws_s3_objects.test_nwm_outputs.keys, count.index), "test_nwm_outputs", formatdate("'common/data/model/com/nwm/prod/nwm.'YYYYMMDD", timestamp()))
}
3 changes: 0 additions & 3 deletions Core/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,6 @@ module "testing" {
source = "./Testing"

environment = local.env.environment
test_data_bucket = module.s3.buckets["deployment"].bucket
viz_initialize_pipeline_arn = module.viz-lambda-functions.initialize_pipeline.arn
lambda_role = module.iam-roles.role_viz_pipeline.arn
s3_module = module.s3
lambda_module = module.viz-lambda-functions
step_function_module = module.step-functions
Expand Down
Loading