Created
October 31, 2022 10:53
-
-
Save apr-1985/ff71d24c971429331e582bc773812d44 to your computer and use it in GitHub Desktop.
AWS-Parameters-and-Secrets-Lambda-Extension-iam
This file contains 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
resource "aws_iam_role" "ssm_lambda_exec" { | |
name = "parameter_layer_test-lambda-exec" | |
assume_role_policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { | |
"Service": "lambda.amazonaws.com" | |
}, | |
"Effect": "Allow", | |
"Sid": "" | |
} | |
] | |
} | |
EOF | |
} | |
resource "aws_iam_role_policy_attachment" "lambda_basic_exec_attachment" { | |
role = aws_iam_role.ssm_lambda_exec.name | |
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | |
} | |
resource "aws_iam_policy" "lambda_ssm_access" { | |
name = "parameter_layer_test-ssm-access-policy" | |
description = "Allow lambda to access SSM" | |
policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": "ssm:GetParameter*", | |
"Resource": ["arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter/lambda/*"] | |
} | |
] | |
} | |
EOF | |
} | |
resource "aws_iam_role_policy_attachment" "ssm_attachment" { | |
role = aws_iam_role.ssm_lambda_exec.name | |
policy_arn = aws_iam_policy.lambda_ssm_access.arn | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment