Skip to content

Commit

Permalink
feat: allow to pass lambda insights layer arn
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanfreitag committed Aug 20, 2024
1 parent c0de9da commit a4c4a7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
25 changes: 16 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ EOF
tags = var.tags
}

# IAM role attachment
resource "aws_iam_role_policy_attachment" "fsx_health_lambda_insights" {
count = var.lambda_insights_layers_arn == null ? 0 : 1
role = aws_iam_role.fsx_health_lambda_role.name
policy_arn = "arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy"
}

resource "aws_iam_role_policy_attachment" "fsx_health_permissions" {
role = aws_iam_role.fsx_health_lambda_role.name
policy_arn = aws_iam_policy.fsx_health_lambda_role_policy.arn
Expand All @@ -103,14 +108,16 @@ resource "aws_iam_role_policy_attachment" "fsx_health_permissions" {

# Lambda function
resource "aws_lambda_function" "fsx_health_lambda" {
filename = data.archive_file.status_checker_code.output_path
function_name = "fsx-health-lambda-function-${random_id.id.hex}"
description = "Monitor the FSx lifecycle status"
role = aws_iam_role.fsx_health_lambda_role.arn
handler = "index.lambda_handler"
runtime = "python3.12"
memory_size = var.memory_size
timeout = var.timeout
filename = data.archive_file.status_checker_code.output_path
function_name = "fsx-health-lambda-function-${random_id.id.hex}"
description = "Monitor the FSx lifecycle status"
role = aws_iam_role.fsx_health_lambda_role.arn
handler = "index.lambda_handler"
runtime = "python3.12"
memory_size = var.memory_size
timeout = var.timeout
layers = var.lambda_insights_layers_arn == null ? [] : [var.lambda_insights_layers_arn]

reserved_concurrent_executions = 1
tracing_config {
mode = "Active"
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ variable "ignore_states" {
}
}

variable "lambda_insights_layers_arn" {
description = "The ARN of the Lambda Insights layer. Default is `null`."
type = string
default = null
}

variable "log_retion_period_in_days" {
type = number
default = 365
Expand Down

0 comments on commit a4c4a7a

Please sign in to comment.