Skip to content

Commit 12f3552

Browse files
authored
Separate Terraform plan and apply roles for incubator (#147)
* Separate Terraform plan and apply roles for incubator * Applying recommended role detail changes for plan and apply * Removed Pull Request condition from incubator_tf_apply * Removed Supervisors group reference in terraform/aws-groups.tf * Removed iam-services-supervisor group from Chelseyb account
1 parent 8a80577 commit 12f3552

File tree

3 files changed

+68
-13
lines changed

3 files changed

+68
-13
lines changed

terraform/aws-gha-oidc-providers.tf

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,70 @@ module "iam_oidc_gha_incubator" {
99
policy_arns = [
1010
"arn:aws:iam::aws:policy/AdministratorAccess"
1111
]
12+
13+
}
14+
resource "aws_iam_role" "incubator_tf_plan" {
15+
name = "incubator-tf-plan"
16+
17+
assume_role_policy = jsonencode({
18+
Version = "2012-10-17"
19+
Statement = [
20+
{
21+
Effect = "Allow"
22+
Action = "sts:AssumeRoleWithWebIdentity"
23+
Principal = {
24+
Federated = module.iam_oidc_gha_incubator.provider_arn
25+
}
26+
Condition = {
27+
StringEquals = {
28+
"token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
29+
}
30+
StringLike = {
31+
"token.actions.githubusercontent.com:sub" = [
32+
"repo:hackforla/incubator:ref:refs/heads/*",
33+
"repo:hackforla/incubator:pull_request"
34+
]
35+
}
36+
}
37+
}
38+
]
39+
})
1240
}
41+
42+
resource "aws_iam_role_policy_attachment" "incubator_tf_plan_readonly" {
43+
role = aws_iam_role.incubator_tf_plan.name
44+
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
45+
}
46+
47+
resource "aws_iam_role" "incubator_tf_apply" {
48+
name = "incubator-tf-apply"
49+
50+
assume_role_policy = jsonencode({
51+
Version = "2012-10-17"
52+
Statement = [
53+
{
54+
Effect = "Allow"
55+
Action = "sts:AssumeRoleWithWebIdentity"
56+
Principal = {
57+
Federated = module.iam_oidc_gha_incubator.provider_arn
58+
}
59+
Condition = {
60+
StringEquals = {
61+
"token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
62+
}
63+
StringLike = {
64+
"token.actions.githubusercontent.com:sub" = [
65+
"repo:hackforla/incubator:ref:refs/heads/main"
66+
]
67+
}
68+
}
69+
}
70+
]
71+
})
72+
}
73+
74+
resource "aws_iam_role_policy_attachment" "incubator_tf_apply_admin" {
75+
role = aws_iam_role.incubator_tf_apply.name
76+
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
77+
}
78+

terraform/aws-groups.tf

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,3 @@ module "iam_read_only_group" {
1010
}
1111
}
1212

13-
// Create iam services admin group
14-
module "iam_services_supervisor_group" {
15-
source = "./modules/aws-groups"
16-
17-
group_name = "iam-services-supervisor-group"
18-
policy_arn = {
19-
"IAMServicesSupervisor" = module.aws_custom_policies.policy_arns["IAMServicesSupervisor"],
20-
"EnforceMFAForUsers" = module.aws_custom_policies.policy_arns["EnforceMFAForUsers"]
21-
}
22-
}
23-

terraform/aws-users.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module "iam_user_chelseyb" {
2929
"Project" = "devops-security"
3030
"Access Level" = "1"
3131
}
32-
user_groups = ["read-only-group", "iam-services-supervisor-group"]
32+
user_groups = ["read-only-group"]
3333
}
3434

3535

@@ -135,7 +135,7 @@ module "iam_user_raibarra" {
135135
module "iam_user_ezesalvatore4" {
136136
source = "./modules/aws-users"
137137

138-
user_name = "ezesalvatore"
138+
user_name = "ezesalvatore"
139139
user_tags = {
140140
"Project" = "devops-security"
141141
"Access Level" = "1"

0 commit comments

Comments
 (0)