Skip to content

Commit dcdbae4

Browse files
committed
feat: Merge iam-role-oidc and iam-role-saml into iam-role
1 parent e528d88 commit dcdbae4

37 files changed

+474
-1441
lines changed

README.md

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Terraform module which creates AWS IAM resources.
44

5-
### ⚠️ JUST FOR TESTING - DO NOT RELY ON THIS ⚠️
6-
75
[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
86

97
## Usage
@@ -47,13 +45,12 @@ module "iam_group" {
4745
]
4846
4947
enable_self_management_permissions = true
50-
permission_statements = [
51-
{
52-
sid = "AssumeRole"
48+
permission_statements = {
49+
AssumeRole = {
5350
actions = ["sts:AssumeRole"]
5451
resources = ["arn:aws:iam::111111111111:role/admin"]
5552
}
56-
]
53+
}
5754
5855
policies = {
5956
AdministratorAccess = "arn:aws:iam::aws:policy/AdministratorAccess",
@@ -106,40 +103,52 @@ module "iam_read_only_policy" {
106103
}
107104
```
108105

109-
### IAM Role for Service Accounts (IRSA)
106+
### IAM Role
110107

111-
Creates an IAM role that is suitable for EKS IAM role for service accounts (IRSA) with a set of pre-defined policies for common EKS addons.
108+
Creates an IAM role with a trust policy and (optional) IAM instance profile. Useful for service roles such as EC2, ECS, etc., or roles assumed across AWS accounts.
112109

113110
```hcl
114-
module "vpc_cni_irsa" {
115-
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts"
116-
117-
name = "vpc-cni"
111+
module "iam_role" {
112+
source = "terraform-aws-modules/iam/aws//modules/iam-role"
118113
119-
attach_vpc_cni_policy = true
120-
vpc_cni_enable_ipv4 = true
114+
name = "example"
121115
122-
oidc_providers = {
123-
this = {
124-
provider_arn = "arn:aws:iam::012345678901:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/5C54DDF35ER19312844C7333374CC09D"
125-
namespace_service_accounts = ["kube-system:aws-node"]
116+
assume_role_policy_statements = {
117+
TrustRoleAndServiceToAssume = {
118+
principals = [{
119+
type = "AWS"
120+
identifiers = [
121+
"arn:aws:iam::835367859851:user/anton",
122+
]
123+
}]
124+
conditions = [{
125+
test = "StringEquals"
126+
variable = "sts:ExternalId"
127+
values = ["some-secret-id"]
128+
}]
126129
}
127130
}
128131
132+
policies = {
133+
AmazonCognitoReadOnly = "arn:aws:iam::aws:policy/AmazonCognitoReadOnly"
134+
AlexaForBusinessFullAccess = "arn:aws:iam::aws:policy/AlexaForBusinessFullAccess"
135+
custom = aws_iam_policy.this.arn
136+
}
137+
129138
tags = {
130139
Terraform = "true"
131140
Environment = "dev"
132141
}
133142
}
134143
```
135144

136-
### OIDC IAM Role
145+
### IAM Role - GitHub OIDC
137146

138147
Creates an IAM role that trusts an OpenID connect provider. Useful for trusting external identity providers such as GitHub, Bitbucket, etc.
139148

140149
```hcl
141-
module "iam_oidc_role" {
142-
source = "terraform-aws-modules/iam/aws//modules/iam-oidc-role"
150+
module "iam_role_github_oidc" {
151+
source = "terraform-aws-modules/iam/aws//modules/iam-role"
143152
144153
enable_github_oidc = true
145154
@@ -157,16 +166,17 @@ module "iam_oidc_role" {
157166
}
158167
```
159168

160-
### SAML IAM Role
169+
### IAM Role - SAML 2.0
161170

162171
Creates an IAM role that trusts a SAML provider. Useful for trusting external identity providers such as Okta, OneLogin, etc.
163172

164173
```hcl
165174
module "iam_role_saml" {
166-
source = "terraform-aws-modules/iam/aws//modules/iam-role-saml"
175+
source = "terraform-aws-modules/iam/aws//modules/iam-role"
167176
168177
name = "example"
169178
179+
enable_saml = true
170180
saml_provider_ids = ["arn:aws:iam::235367859851:saml-provider/idp_saml"]
171181
172182
policies = {
@@ -180,37 +190,24 @@ module "iam_role_saml" {
180190
}
181191
```
182192

183-
### IAM Role
193+
### IAM Role for EKS Service Accounts (IRSA)
184194

185-
Creates an IAM role with a trust policy and (optional) IAM instance profile. Useful for service roles such as EC2, ECS, etc., or roles assumed across AWS accounts.
195+
Creates an IAM role that is suitable for EKS IAM role for service accounts (IRSA) with a set of pre-defined policies for common EKS addons.
186196

187197
```hcl
188-
module "iam_role" {
189-
source = "terraform-aws-modules/iam/aws//modules/iam-role"
198+
module "vpc_cni_irsa" {
199+
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts"
190200
191-
name = "example"
201+
name = "vpc-cni"
192202
193-
assume_role_policy_statements = [
194-
{
195-
sid = "TrustRoleAndServiceToAssume"
196-
principals = [{
197-
type = "AWS"
198-
identifiers = [
199-
"arn:aws:iam::835367859851:user/anton",
200-
]
201-
}]
202-
conditions = [{
203-
test = "StringEquals"
204-
variable = "sts:ExternalId"
205-
values = ["some-secret-id"]
206-
}]
207-
}
208-
]
203+
attach_vpc_cni_policy = true
204+
vpc_cni_enable_ipv4 = true
209205
210-
policies = {
211-
AmazonCognitoReadOnly = "arn:aws:iam::aws:policy/AmazonCognitoReadOnly"
212-
AlexaForBusinessFullAccess = "arn:aws:iam::aws:policy/AlexaForBusinessFullAccess"
213-
custom = aws_iam_policy.this.arn
206+
oidc_providers = {
207+
this = {
208+
provider_arn = "arn:aws:iam::012345678901:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/5C54DDF35ER19312844C7333374CC09D"
209+
namespace_service_accounts = ["kube-system:aws-node"]
210+
}
214211
}
215212
216213
tags = {
@@ -249,7 +246,6 @@ module "iam_user" {
249246
- [iam-read-only-policy](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-read-only-policy) - Create IAM read-only policy
250247
- [iam-role](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-role) - Create individual IAM role which can be assumed from specified ARNs (AWS accounts, IAM users, etc)
251248
- [iam-role-for-service-accounts](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-role-for-service-accounts) - Create IAM role for service accounts (IRSA) for use within EKS clusters
252-
- [iam-role-saml](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-role-saml) - Create individual IAM role which can be assumed by users with a SAML Identity Provider
253249
- [iam-user](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-user) - Add IAM user, login profile and access keys (with PGP enabled or disabled)
254250

255251
## Authors

UPGRADE-6.0.md renamed to docs/UPGRADE-6.0.md

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ If you find a bug, please open an issue with supporting configuration to reprodu
77
## List of backwards incompatible changes
88

99
- `iam-assumable-role` has been renamed to `iam-role`
10-
- `iam-assumable-role-with-oidc` has been renamed to `iam-role-oidc`
11-
- `iam-assumable-role-with-saml` has been renamed to `iam-role-saml`
10+
- `iam-assumable-role-with-oidc` has been merged into `iam-role`
11+
- `iam-assumable-role-with-saml` has been merged into `iam-role`
1212
- `iam-assumable-roles` has been removed; `iam-role` should be used instead. See the [`iam-role` example](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-role) that shows an example replacement implementation.
13-
- `iam-assumable-roles-with-saml` has been removed; `iam-role-saml` should be used instead. See the [`iam-role-saml` example](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-role-saml) that shows an example replacement implementation.
13+
- `iam-assumable-roles-with-saml` has been removed; `iam-role` should be used instead. See the [`iam-role` example](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-role-saml) that shows an example replacement implementation.
1414
- `iam-github-oidc-provider` has been renamed to `iam-oidc-provider`
15-
- `iam-github-oidc-role` has been removed; `iam-role-oidc` should be used instead. See the [`iam-oidc-provider` example](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-oidc-provider)
15+
- `iam-github-oidc-role` has been merged into `iam-role`. See the [`iam-oidc-provider` example](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-oidc-provider)
1616
- `iam-group-with-assumable-roles-policy` has been removed; the renamed `iam-group` (was `iam-group-with-policies`) should be used instead
17-
- `iam-eks-role` has been removed; `iam-role-for-service-accounts-eks` should be used instead
17+
- `iam-eks-role` has been removed; `iam-role-for-service-accounts` should be used instead
1818
- `iam-policy` has been removed; the `aws_iam_policy` resource should be used directly instead
1919

2020
## Additional changes
@@ -26,14 +26,6 @@ If you find a bug, please open an issue with supporting configuration to reprodu
2626
- `custom_role_policy_arns` has been renamed to `policies` and now accepts a map of `name`: `policy-arn` pairs; this allows for both existing policies and policies that will get created at the same time as the role. This also replaces the admin, readonly, and poweruser policy ARN variables and their associated `attach_*_policy` variables.
2727
- Default create conditional is now `true` instead of `false`
2828
- `force_detach_policies` has been removed; this is now always `true`
29-
- `iam-role-oidc`
30-
- `custom_role_policy_arns` has been renamed to `policies` and now accepts a map of `name`: `policy-arn` pairs; this allows for both existing policies and policies that will get created at the same time as the role.
31-
- Default create conditional is now `true` instead of `false`
32-
- `force_detach_policies` has been removed; this is now always `true`
33-
- `iam-role-saml`
34-
- `custom_role_policy_arns` has been renamed to `policies` and now accepts a map of `name`: `policy-arn` pairs; this allows for both existing policies and policies that will get created at the same time as the role.
35-
- Default create conditional is now `true` instead of `false`
36-
- `force_detach_policies` has been removed; this is now always `true`
3729
- `iam-group`
3830
- Policy management has been updated to support extending the policy created by the sub-module, as well as adding additional policies that will be attached to the group
3931
- The role assumption permissions has been removed from the policy; users can extend the policy to add this if needed via `permission_statements`
@@ -56,12 +48,6 @@ If you find a bug, please open an issue with supporting configuration to reprodu
5648
- `readonly_role_policy_arn` & `attach_readonly_policy`
5749
- `force_detach_policies`
5850
- `role_sts_externalid`
59-
- `iam-role-oidc`
60-
- `force_detach_policies`
61-
- `number_of_custom_role_policy_arns`
62-
- `iam-role-saml`
63-
- `force_detach_policies`
64-
- `number_of_custom_role_policy_arns`
6551
- `iam-group`
6652
- `custom_group_policies`
6753
- `assumable_roles`
@@ -76,24 +62,6 @@ If you find a bug, please open an issue with supporting configuration to reprodu
7662
- `role_path` -> `path`
7763
- `role_permissions_boundary_arn` -> `permissions_boundary_arn`
7864
- `custom_role_policy_arns` -> `policies`
79-
- `iam-role-oidc`
80-
- `create_role` -> `create`
81-
- `role_name` -> `name`
82-
- `role_name_prefix` -> `name_prefix`
83-
- `role_description` -> `description`
84-
- `role_path` -> `path`
85-
- `role_permissions_boundary_arn` -> `permissions_boundary_arn`
86-
- `custom_role_policy_arns` -> `policies`
87-
- `iam-role-saml`
88-
- `create_role` -> `create`
89-
- `role_name` -> `name`
90-
- `role_name_prefix` -> `name_prefix`
91-
- `role_description` -> `description`
92-
- `role_path` -> `path`
93-
- `role_permissions_boundary_arn` -> `permissions_boundary_arn`
94-
- `custom_role_policy_arns` -> `policies`
95-
- `aws_saml_endpoint` -> `saml_endpoints`
96-
- `trusted_role_actions` -> `saml_trust_actions`
9765
- `iam-group`
9866
- `create_group` -> `create`
9967
- `group_users` -> `group`
@@ -106,10 +74,6 @@ If you find a bug, please open an issue with supporting configuration to reprodu
10674

10775
- `iam-role`
10876
- `assume_role_policy_statements` which allows for any number of custom statements to be added to the role's trust policy. This covers the majority of the variables that were removed
109-
- `iam-role-oidc`
110-
- `assume_role_policy_statements` which allows for any number of custom statements to be added to the role's trust policy. This covers the majority of the variables that were removed
111-
- `iam-role-saml`
112-
- `assume_role_policy_statements` which allows for any number of custom statements to be added to the role's trust policy. This covers the majority of the variables that were removed
11377
- `iam-group`
11478
- `permission_statements` which allows for any number of custom statements to be added to the role's trust policy. This covers the majority of the variables that were removed
11579
- `path`/`policy_path`
@@ -123,12 +87,6 @@ If you find a bug, please open an issue with supporting configuration to reprodu
12387
- `role_requires_mfa`
12488
- `iam_instance_profile_path`
12589
- `role_sts_externalid`
126-
- `iam-role-oidc`
127-
- `iam_role_path`
128-
- `provider_url` (use `oidc_provider_urls` instead)
129-
- `iam-role-saml`
130-
- `iam_role_path`
131-
- `provider_id` (use `saml_provider_ids` instead)
13290
- `iam-group`
13391
- `assumable_roles`
13492
- `aws_account_id`
@@ -143,18 +101,6 @@ If you find a bug, please open an issue with supporting configuration to reprodu
143101
- `iam_instance_profile_id` -> `instance_profile_id`
144102
- `iam_instance_profile_name` -> `instance_profile_name`
145103
- `iam_instance_profile_unique_id` -> `instance_profile_unique_id`
146-
- `iam-role-oidc`
147-
- `iam_role_arn` -> `arn`
148-
- `iam_role_name` -> `name`
149-
- `iam_role_unique_id` -> `unique_id`
150-
- `aws_account_id` -> `oidc_account_id`
151-
- `provider_urls` -> `oidc_provider_urls`
152-
- `iam-role-oidc`
153-
- `iam_role_arn` -> `arn`
154-
- `iam_role_name` -> `name`
155-
- `iam_role_unique_id` -> `unique_id`
156-
- `aws_account_id` -> `oidc_account_id`
157-
- `provider_ids` -> `saml_provider_ids`
158104
- `iam-group`
159105
- `group_id` -> `id`
160106
- `group_name` -> `name`

examples/iam-oidc-provider/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ No providers.
3434
| Name | Source | Version |
3535
|------|--------|---------|
3636
| <a name="module_github_oidc_iam_provider"></a> [github\_oidc\_iam\_provider](#module\_github\_oidc\_iam\_provider) | ../../modules/iam-oidc-provider | n/a |
37-
| <a name="module_github_oidc_iam_role"></a> [github\_oidc\_iam\_role](#module\_github\_oidc\_iam\_role) | ../../modules/iam-role-oidc | n/a |
37+
| <a name="module_github_oidc_iam_role"></a> [github\_oidc\_iam\_role](#module\_github\_oidc\_iam\_role) | ../../modules/iam-role | n/a |
3838
| <a name="module_oidc_iam_provider_disabled"></a> [oidc\_iam\_provider\_disabled](#module\_oidc\_iam\_provider\_disabled) | ../../modules/iam-oidc-provider | n/a |
39-
| <a name="module_oidc_iam_role_disabled"></a> [oidc\_iam\_role\_disabled](#module\_oidc\_iam\_role\_disabled) | ../../modules/iam-role-oidc | n/a |
4039

4140
## Resources
4241

examples/iam-oidc-provider/main.tf

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ module "oidc_iam_provider_disabled" {
3030
}
3131

3232
################################################################################
33-
# OIDC IAM Role
33+
# GitHub OIDC IAM Role
3434
################################################################################
3535

3636
module "github_oidc_iam_role" {
37-
source = "../../modules/iam-role-oidc"
37+
source = "../../modules/iam-role"
3838

3939
name = local.name
4040

@@ -53,9 +53,3 @@ module "github_oidc_iam_role" {
5353

5454
tags = local.tags
5555
}
56-
57-
module "oidc_iam_role_disabled" {
58-
source = "../../modules/iam-role-oidc"
59-
60-
create = false
61-
}

examples/iam-role-saml/README.md

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)