Last active
August 15, 2022 16:49
-
-
Save nhammad/f283282127f4ce02f80a79e301de033d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "archive_file" "lambda_zip" { | |
type = "zip" | |
source_file = "${path.module}/src/enable_disable_alarms_tf.py" | |
output_file_mode = "0666" | |
output_path = "${path.module}/bin/enable_disable_alarms_tf.zip" | |
} | |
resource "aws_lambda_function" "processing_lambda" { | |
filename = data.archive_file.lambda_zip.output_path | |
function_name = local.processing_lambda_name | |
handler = "enable_disable_alarms_tf.lambda_handler" | |
source_code_hash = data.archive_file.lambda_zip.output_base64sha256 | |
role = aws_iam_role.processing_lambda_role.arn | |
runtime = "python3.9" | |
environment { | |
variables = { | |
action = var.action | |
alarm_arns_lst = jsonencode(var.alarm_arns_lst) | |
} | |
} | |
} | |
resource "aws_iam_role" "processing_role" { | |
name = local.role_name | |
path = "/service-role/" | |
assume_role_policy = data.aws_iam_policy_document.assume-role-document.json | |
inline_policy { | |
name = "lambda_policy" | |
policy = data.aws_iam_policy_document.alarms_policy_document.json | |
} | |
} | |
data "aws_iam_policy_document" "alarms_policy_document" { | |
statement { | |
actions = [ | |
"cloudwatch:DescribeAlarms", | |
"cloudwatch:DisableAlarmActions", | |
"cloudwatch:EnableAlarmActions", | |
] | |
resources = ["*"] | |
} | |
statement { | |
actions = [ | |
"logs:CreateLogGroup", | |
"logs:CreateLogStream", | |
"logs:PutLogEvents", | |
"logs:AssociateKmsKey" | |
] | |
resources = ["*"] | |
} | |
data "aws_iam_policy_document" "assume-role-document" { | |
statement { | |
actions = ["sts:AssumeRole"] | |
principals { | |
type = "Service" | |
identifiers = ["lambda.amazonaws.com"] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment