From eb21bec874ab12de70b7cf7e259b9e29ba269bc1 Mon Sep 17 00:00:00 2001 From: Nathan Souza Date: Tue, 8 Oct 2024 12:20:29 -0300 Subject: [PATCH] fix: ajusta terraform --- deployment/infrastructure/terraform-lambda/iam.tf | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/deployment/infrastructure/terraform-lambda/iam.tf b/deployment/infrastructure/terraform-lambda/iam.tf index 050e2e5..ca5a196 100644 --- a/deployment/infrastructure/terraform-lambda/iam.tf +++ b/deployment/infrastructure/terraform-lambda/iam.tf @@ -1,4 +1,9 @@ +data "aws_iam_role" "existing_role" { + name = "prediction_eml_role" +} + resource "aws_iam_role" "prediction_eml_role" { + count = length(data.aws_iam_role.existing_role.*.name) == 0 ? 1 : 0 name = "prediction_eml_role" assume_role_policy = jsonencode({ @@ -17,7 +22,8 @@ resource "aws_iam_role" "prediction_eml_role" { } resource "aws_iam_policy_attachment" "prediction_eml_policy_attachment" { + count = length(data.aws_iam_role.existing_role.*.name) == 0 ? 1 : 0 name = "prediction_eml_policy_attachment" - roles = [aws_iam_role.prediction_eml_role.name] + roles = [aws_iam_role.prediction_eml_role[0].name] policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" }