Skip to content

Commit

Permalink
Error checking for conflicting variables
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nsimmonds authored Jul 31, 2024
1 parent f48be17 commit c80c92b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ locals {
}

resource "aws_lambda_function" "this" {

lifecycle {
precondition {
condition = var.create_role && var.lambda_role != []
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."
# The lambda_role variable should only be used to attach a pre-existing role, and will do nothing
# if create_role is true.
}
}

count = local.create && var.create_function && !var.create_layer ? 1 : 0

function_name = var.function_name
Expand Down

0 comments on commit c80c92b

Please sign in to comment.