Skip to content

Commit

Permalink
feat(ec2): add iam permission to stop instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Freebios committed Mar 20, 2023
1 parent 681a0f2 commit 357fbc6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down

0 comments on commit 357fbc6

Please sign in to comment.