-
Notifications
You must be signed in to change notification settings - Fork 6
/
iam.tf
executable file
·70 lines (64 loc) · 1.94 KB
/
iam.tf
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
65
66
67
68
69
70
############################
# IAM Resources for Lambda #
############################
resource "aws_iam_role" "lambda_role" {
name = "sso-assignment-lambda-role"
description = "Role assigned to sso-assignment-lambda for interacting with IAM Identity Center and Organizations"
assume_role_policy = data.aws_iam_policy_document.lambda_role_trust_policy.json
}
resource "aws_iam_role_policy_attachment" "lambda_permissions_attachment" {
role = aws_iam_role.lambda_role.name
policy_arn = aws_iam_policy.lambda_policy.arn
}
resource "aws_iam_role_policy_attachment" "lambda_managed_policy_attachment" {
role = aws_iam_role.lambda_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_policy" "lambda_policy" {
name = "sso-assignment-lambda-policy"
description = "Policy assigned to sso-assignment-lambda-role to give permissions for interacting with IAM Identity center and Organizations"
policy = data.aws_iam_policy_document.lambda_permissions.json
}
data "aws_iam_policy_document" "lambda_role_trust_policy" {
statement {
effect = "Allow"
actions = [
"sts:AssumeRole",
]
principals {
type = "Service"
identifiers = [
"lambda.amazonaws.com",
]
}
}
}
data "aws_iam_policy_document" "lambda_permissions" {
statement {
sid = "IdentityReadpermissions"
effect = "Allow"
actions = [
"sso:ListPermissionSets",
"sso:DescribeAccountAssignmentCreationStatus",
"sso:DescribePermissionSet",
"sso:ListInstances",
"iam:GetSAMLProvider",
"organizations:ListTagsForResource",
"organizations:ListAccounts",
"identitystore:ListGroups"
]
resources = [
"*",
]
}
statement {
sid = "IdentityCenterWritepermissions"
effect = "Allow"
actions = [
"sso:CreateAccountAssignment"
]
resources = [
"*",
]
}
}