diff --git a/main.tf b/main.tf index 7aba415..d573eef 100644 --- a/main.tf +++ b/main.tf @@ -102,6 +102,27 @@ resource "aws_iam_role_policy" "lambda_rds" { policy = data.aws_iam_policy_document.lambda_rds.json } +data "aws_iam_policy_document" "lambda_ec2" { + statement { + actions = [ + "ec2:StopInstances", + "ec2:TerminateInstances", + ] + + resources = [ + "*", + ] + } +} + +resource "aws_iam_role_policy" "lambda_ec2" { + count = var.custom_iam_lambda_role ? 0 : 1 + + name_prefix = "${local.name_prefix}_ec2" + role = aws_iam_role.lambda[0].id + policy = data.aws_iam_policy_document.lambda_ec2.json +} + data "archive_file" "lambda_zip" { type = "zip" source_dir = "${path.module}/function/"