-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor.tf
More file actions
64 lines (53 loc) · 1.57 KB
/
Copy pathexecutor.tf
File metadata and controls
64 lines (53 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
locals {
resource_name = "${var.block_ref}-${var.resource_suffix}"
}
resource "aws_iam_role" "executor" {
name = local.resource_name
assume_role_policy = data.aws_iam_policy_document.executor_assume.json
tags = var.tags
}
data "aws_iam_policy_document" "executor_assume" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
}
}
resource "aws_iam_role_policy_attachment" "executor_basic" {
role = aws_iam_role.executor.name
policy_arn = "arn:${var.partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_role_policy_attachment" "executor_vpc" {
role = aws_iam_role.executor.name
policy_arn = "arn:${var.partition}:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
}
resource "aws_iam_role_policy" "executor" {
role = aws_iam_role.executor.id
policy = data.aws_iam_policy_document.executor.json
}
locals {
secret_statement_resources = length(var.secret_arns) > 0 ? [var.secret_arns] : []
}
data "aws_iam_policy_document" "executor" {
statement {
sid = "AllowBasicSecretsListing"
effect = "Allow"
actions = ["secretsmanager:ListSecrets"]
resources = ["*"]
}
dynamic "statement" {
for_each = local.secret_statement_resources
content {
sid = "AllowReadSecrets"
effect = "Allow"
resources = statement.value
actions = [
"secretsmanager:GetSecretValue",
"kms:Decrypt",
]
}
}
}