-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiam.tf
97 lines (86 loc) · 2.05 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# AWS SSO Role Okta
resource "aws_iam_role" "sso" {
name = var.sso_role_name
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRoleWithSAML",
"Condition": {
"StringEquals": {
"SAML:aud": "https://signin.aws.amazon.com/saml"
}
},
"Principal": {
"Federated": "arn:aws:iam::${var.aws_account_id}:saml-provider/${aws_iam_saml_provider.sso.id}"
}
}
]
}
EOF
}
# sso role policy
resource "aws_iam_policy" "sso" {
name = "${var.sso_role_name}-policy"
path = "/"
description = "AWS SSO role for okta"
policy = jsonencode(
{
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Action" : [
"eks:AccessKubernetesApi",
"eks:DescribeCluster",
"eks:DescribeFargateProfile",
"eks:DescribeNodegroup",
"eks:DescribeUpdate",
"eks:ListClusters",
"eks:ListFargateProfiles",
"eks:ListNodegroups",
"eks:ListTagsForResource",
"eks:ListUpdates"
],
"Resource" : "*"
}
]
})
}
resource "aws_iam_role_policy_attachment" "sso" {
role = aws_iam_role.sso.name
policy_arn = aws_iam_policy.sso.arn
}
# service user
resource "aws_iam_user" "sso_user" {
name = var.sso_user
path = "/services/"
}
resource "aws_iam_access_key" "sso" {
user = aws_iam_user.sso_user.name
}
# service user policy
resource "aws_iam_policy" "sso_user" {
name = "sso_user_policy"
path = "/"
description = "For Okta check in account"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"iam:ListRoles",
"iam:ListAccountAliases"
]
Effect = "Allow"
Resource = "*"
},
]
})
}
resource "aws_iam_user_policy_attachment" "sso" {
user = aws_iam_user.sso_user.name
policy_arn = aws_iam_policy.sso_user.arn
}