From 2542790ffef2f35ecb40eeea5703a7b767628b66 Mon Sep 17 00:00:00 2001 From: Shawn Crawley Date: Thu, 19 Dec 2024 15:52:00 -0700 Subject: [PATCH] Implements apocalyptic-test step func in terraform Refs #938 --- Core/Testing/main.tf | 30 +++----- .../trigger_apocalyptic_tests.json.tftpl | 77 +++++++++++++++++++ Core/main.tf | 3 +- 3 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 Core/Testing/trigger_apocalyptic_tests.json.tftpl diff --git a/Core/Testing/main.tf b/Core/Testing/main.tf index ad3c184e..9214b3a6 100644 --- a/Core/Testing/main.tf +++ b/Core/Testing/main.tf @@ -19,8 +19,11 @@ variable "lambda_module" { type = any } -variable "step_function_module" { - type = any +variable "role" { + type = string +} +variable "deployment_bucket" { + type = string } locals { @@ -81,20 +84,11 @@ resource "aws_cloudwatch_event_target" "trigger_pipeline_test_run" { } } -################################## -###### KICK OFF TESTS IN TI ###### -################################## -data "aws_s3_objects" "test_nwm_outputs" { - bucket = local.test_bucket - prefix = "test_nwm_outputs/" - max_keys = 2000 -} +resource "aws_sfn_state_machine" "trigger_apocalyptic_tests_step_function" { + name = "hv-vpp-${var.environment}-trigger-apocalyptic-tests" + role_arn = var.role -resource "aws_s3_object_copy" "test" { - provider = aws.no_tags - 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 = 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())) -} + definition = templatefile("${path.module}/trigger_apocalyptic_tests.json.tftpl", { + deployment_bucket = var.deployment_bucket + }) +} \ No newline at end of file diff --git a/Core/Testing/trigger_apocalyptic_tests.json.tftpl b/Core/Testing/trigger_apocalyptic_tests.json.tftpl new file mode 100644 index 00000000..238946d6 --- /dev/null +++ b/Core/Testing/trigger_apocalyptic_tests.json.tftpl @@ -0,0 +1,77 @@ +{ + "QueryLanguage": "JSONata", + "Comment": "A description of my state machine", + "StartAt": "S3 object keys", + "States": { + "Remove Stale Run": { + "Type": "Map", + "ItemProcessor": { + "ProcessorConfig": { + "Mode": "DISTRIBUTED", + "ExecutionType": "EXPRESS" + }, + "StartAt": "DeleteObject", + "States": { + "DeleteObject": { + "Type": "Task", + "Arguments": { + "Bucket": "${deployment_bucket}", + "Key": "{% $states.input.Key %}" + }, + "Resource": "arn:aws:states:::aws-sdk:s3:deleteObject", + "End": true + } + } + }, + "ItemReader": { + "Resource": "arn:aws:states:::s3:listObjectsV2", + "Arguments": { + "Bucket": "${deployment_bucket}", + "Prefix": "common/data/model/com/nwm/prod/" + }, + "ReaderConfig": {} + }, + "Label": "S3objectkeys", + "Output": { + "success": true + }, + "Next": "Move Apocalyptic Files" + }, + "Move Apocalyptic Files": { + "Type": "Map", + "ItemProcessor": { + "ProcessorConfig": { + "Mode": "DISTRIBUTED", + "ExecutionType": "EXPRESS" + }, + "StartAt": "CopyObject", + "States": { + "CopyObject": { + "Type": "Task", + "Arguments": { + "Bucket": "${deployment_bucket}", + "CopySource": "{% $join(['${deployment_bucket}', $states.input.Key], '/') %}", + "Key": "{% $replace($states.input.Key, 'test_nwm_outputs', $now('common/data/model/com/nwm/prod/nwm.[Y0001][M01][D01]')) %}" + }, + "Resource": "arn:aws:states:::aws-sdk:s3:copyObject", + "End": true, + "Output": {} + } + } + }, + "ItemReader": { + "Resource": "arn:aws:states:::s3:listObjectsV2", + "Arguments": { + "Bucket": "${deployment_bucket}", + "Prefix": "test_nwm_outputs/" + }, + "ReaderConfig": {} + }, + "Label": "S3objectkeys", + "End": true, + "Output": { + "success": true + } + } + } +} \ No newline at end of file diff --git a/Core/main.tf b/Core/main.tf index c1fa66c7..a2f19252 100644 --- a/Core/main.tf +++ b/Core/main.tf @@ -751,5 +751,6 @@ module "testing" { environment = local.env.environment s3_module = module.s3 lambda_module = module.viz-lambda-functions - step_function_module = module.viz-step-functions + role = module.iam-roles.role_viz_pipeline.arn + deployment_bucket = module.s3.buckets["deployment"].bucket }