From d44340757cc16f7fbe407464ffd42c1eea93807e Mon Sep 17 00:00:00 2001 From: Hope Aitchison Date: Wed, 3 Jan 2024 16:48:26 +0000 Subject: [PATCH] more random IDs --- test/unit-test/main.tf | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/test/unit-test/main.tf b/test/unit-test/main.tf index c5bea6d..c802cfe 100644 --- a/test/unit-test/main.tf +++ b/test/unit-test/main.tf @@ -7,7 +7,7 @@ module "module_test" { role_name = format("InstanceSchedulerLambdaFunctionPolicy-%s", random_id.role.dec) policy_json_attached = true policy_json = data.aws_iam_policy_document.instance-scheduler-lambda-function-policy.json - function_name = "instance-scheduler-lambda-function" + function_name = format("instance-scheduler-lambda-function-%s", random_id.lambda.dec) create_role = true reserved_concurrent_executions = 1 environment_variables = { @@ -30,10 +30,6 @@ module "module_test" { } -resource "random_id" "role" { - byte_length = 1 -} - resource "aws_cloudwatch_event_rule" "instance_scheduler_weekly_stop_at_night" { name = "instance_scheduler_weekly_stop_at_night" description = "Call Instance Scheduler with Stop action at 8:00 pm (UTC) every Monday through Friday" @@ -173,7 +169,7 @@ module "lambda_function_in_vpc" { handler = "test.lambda_handler" runtime = "python3.8" tags = local.tags - function_name = "lambda-function-in-vpc-test" + function_name = format("lambda-function-in-vpc-test-%s", random_id.lambda_name.dec) create_role = false lambda_role = aws_iam_role.lambda-vpc-role.arn @@ -193,10 +189,6 @@ data "aws_iam_policy_document" "lambda_assume_role_policy" { } } -resource "random_id" "role_name" { - byte_length = 1 -} - resource "aws_iam_role" "lambda-vpc-role" { name = format("LambdaFunctionVPCAccess-%s", random_id.role_name.dec) tags = local.tags @@ -217,10 +209,6 @@ data "aws_subnet" "private-2a" { id = "subnet-0e2a4d5f4b346c981" } -resource "random_id" "sg_name" { - byte_length = 1 -} - resource "aws_security_group" "lambda_security_group_test" { name = format("lambda-vpc-module-test-%s", random_id.sg_name.dec) description = "lambda attached to vpc test security group" @@ -250,3 +238,25 @@ resource "aws_lambda_invocation" "test_vpc_invocation" { action = "Test" }) } + +# temporary random IDs + +resource "random_id" "lambda_name" { + byte_length = 1 +} + +resource "random_id" "role" { + byte_length = 1 +} + +resource "random_id" "lambda" { + byte_length = 1 +} + +resource "random_id" "sg_name" { + byte_length = 1 +} + +resource "random_id" "role_name" { + byte_length = 1 +}