Skip to content

Commit c80c92b

Browse files
authored
Error checking for conflicting variables
lambda_role is only used if create_role is set to false. Currently, the user can set both, causing confusing behavior when the desired role is not attached and instead a new role is created.
1 parent f48be17 commit c80c92b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ locals {
2222
}
2323

2424
resource "aws_lambda_function" "this" {
25+
26+
lifecycle {
27+
precondition {
28+
condition = var.create_role && var.lambda_role != []
29+
error_message = "The 'create_role' and 'lambda_role' variables should not be used together. When creating a role, use 'role_name' to set the name."
30+
# The lambda_role variable should only be used to attach a pre-existing role, and will do nothing
31+
# if create_role is true.
32+
}
33+
}
34+
2535
count = local.create && var.create_function && !var.create_layer ? 1 : 0
2636

2737
function_name = var.function_name

0 commit comments

Comments
 (0)