Skip to content

Commit e29b94f

Browse files
authored
feat: Add conditional policy statement attachments for EKS IAM role module (#184)
1 parent 9575b7e commit e29b94f

File tree

47 files changed

+1467
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1467
-191
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.62.3
3+
rev: v1.64.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate

README.md

Lines changed: 92 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Features
44

55
1. **Cross-account access.** Define IAM roles using `iam_assumable_role` or `iam_assumable_roles` submodules in "resource AWS accounts (prod, staging, dev)" and IAM groups and users using `iam-group-with-assumable-roles-policy` submodule in "IAM AWS Account" to setup access controls between accounts. See [iam-group-with-assumable-roles-policy example](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-group-with-assumable-roles-policy) for more details.
6-
1. **Individual IAM resources (users, roles, policies).** See usage snippets and [examples](https://github.com/terraform-aws-modules/terraform-aws-iam#examples) listed below.
6+
2. **Individual IAM resources (users, roles, policies).** See usage snippets and [examples](https://github.com/terraform-aws-modules/terraform-aws-iam#examples) listed below.
77

88
## Usage
99

@@ -134,63 +134,31 @@ module "iam_assumable_roles_with_saml" {
134134
}
135135
```
136136

137-
`iam-user`:
137+
`iam-eks-role`:
138138

139139
```hcl
140-
module "iam_user" {
141-
source = "terraform-aws-modules/iam/aws//modules/iam-user"
142-
version = "~> 4"
143-
144-
name = "vasya.pupkin"
145-
force_destroy = true
146-
147-
pgp_key = "keybase:test"
148-
149-
password_reset_required = false
150-
}
151-
```
140+
module "iam_eks_role" {
141+
source = "terraform-aws-modules/iam/aws//modules/iam-eks-role"
142+
version = "~> 4"
152143
153-
`iam-policy`:
144+
role_name = "my-app"
154145
155-
```hcl
156-
module "iam_policy" {
157-
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
158-
version = "~> 4"
146+
cluster_service_accounts = {
147+
"cluster1" = ["default:my-app"]
148+
"cluster2" = [
149+
"default:my-app",
150+
"canary:my-app",
151+
]
152+
}
159153
160-
name = "example"
161-
path = "/"
162-
description = "My example policy"
154+
tags = {
155+
Name = "eks-role"
156+
}
163157
164-
policy = <<EOF
165-
{
166-
"Version": "2012-10-17",
167-
"Statement": [
168-
{
169-
"Action": [
170-
"ec2:Describe*"
171-
],
172-
"Effect": "Allow",
173-
"Resource": "*"
174-
}
158+
role_policy_arns = [
159+
"arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy",
175160
]
176161
}
177-
EOF
178-
}
179-
```
180-
181-
`iam-read-only-policy`:
182-
183-
```hcl
184-
module "iam_read_only_policy" {
185-
source = "terraform-aws-modules/iam/aws//modules/iam-read-only-policy"
186-
version = "~> 4"
187-
188-
name = "example"
189-
path = "/"
190-
description = "My example read-only policy"
191-
192-
allowed_services = ["rds", "dynamo", "health"]
193-
}
194162
```
195163

196164
`iam-group-with-assumable-roles-policy`:
@@ -242,30 +210,87 @@ module "iam_group_with_policies" {
242210
}
243211
```
244212

245-
`iam-eks-role`:
213+
`iam-policy`:
246214

247215
```hcl
248-
module "iam_eks_role" {
249-
source = "terraform-aws-modules/iam/aws//modules/iam-eks-role"
216+
module "iam_policy" {
217+
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
218+
version = "~> 4"
219+
220+
name = "example"
221+
path = "/"
222+
description = "My example policy"
223+
224+
policy = <<EOF
225+
{
226+
"Version": "2012-10-17",
227+
"Statement": [
228+
{
229+
"Action": [
230+
"ec2:Describe*"
231+
],
232+
"Effect": "Allow",
233+
"Resource": "*"
234+
}
235+
]
236+
}
237+
EOF
238+
}
239+
```
240+
241+
`iam-read-only-policy`:
242+
243+
```hcl
244+
module "iam_read_only_policy" {
245+
source = "terraform-aws-modules/iam/aws//modules/iam-read-only-policy"
246+
version = "~> 4"
247+
248+
name = "example"
249+
path = "/"
250+
description = "My example read-only policy"
251+
252+
allowed_services = ["rds", "dynamo", "health"]
253+
}
254+
```
255+
256+
`iam-role-for-service-accounts-eks`:
257+
258+
```hcl
259+
module "vpc_cni_irsa" {
260+
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
250261
version = "~> 4"
251262
252-
role_name = "my-app"
263+
role_name = "vpc-cni"
253264
254-
cluster_service_accounts = {
255-
"cluster1" = ["default:my-app"]
256-
"cluster2" = [
257-
"default:my-app",
258-
"canary:my-app",
259-
]
265+
attach_vpc_cni_policy = true
266+
vpc_cni_enable_ipv4 = true
267+
268+
oidc_providers = {
269+
main = {
270+
provider_arn = "arn:aws:iam::012345678901:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/5C54DDF35ER19312844C7333374CC09D"
271+
namespace_service_accounts = ["default:my-app", "canary:my-app"]
272+
}
260273
}
261274
262275
tags = {
263-
Name = "eks-role"
276+
Name = "vpc-cni-irsa"
264277
}
278+
}
279+
```
265280

266-
role_policy_arns = [
267-
"arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy",
268-
]
281+
`iam-user`:
282+
283+
```hcl
284+
module "iam_user" {
285+
source = "terraform-aws-modules/iam/aws//modules/iam-user"
286+
version = "~> 4"
287+
288+
name = "vasya.pupkin"
289+
force_destroy = true
290+
291+
pgp_key = "keybase:test"
292+
293+
password_reset_required = false
269294
}
270295
```
271296

@@ -318,12 +343,13 @@ Use [iam-read-only-policy module](https://github.com/terraform-aws-modules/terra
318343
- [iam-assumable-roles](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-assumable-roles) - Create several IAM roles which can be assumed from specified ARNs (AWS accounts, IAM users, etc)
319344
- [iam-assumable-roles-with-saml](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-assumable-roles-with-saml) - Create several IAM roles which can be assumed by users with a SAML Identity Provider
320345
- [iam-eks-role](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-eks-role) - Create an IAM role which can be assumed by one or more EKS `ServiceAccount`
346+
- [iam-group-complete](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-group-complete) - IAM group with users who are allowed to assume IAM roles in another AWS account and have access to specified IAM policies
321347
- [iam-group-with-assumable-roles-policy](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-group-with-assumable-roles-policy) - IAM group with users who are allowed to assume IAM roles in the same or in separate AWS account
322348
- [iam-group-with-policies](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-group-with-policies) - IAM group with users who are allowed specified IAM policies (eg, "manage their own IAM user")
323-
- [iam-group-complete](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-group-complete) - IAM group with users who are allowed to assume IAM roles in another AWS account and have access to specified IAM policies
324-
- [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)
325349
- [iam-policy](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-policy) - Create IAM policy
326350
- [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
351+
- [iam-role-for-service-accounts-eks](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-role-for-service-accounts-eks) - Create IAM role for service accounts (IRSA) for use within EKS clusters
352+
- [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)
327353

328354
## Authors
329355

examples/iam-account/versions.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ terraform {
22
required_version = ">= 0.12.6"
33

44
required_providers {
5-
aws = ">= 2.23"
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 2.23"
8+
}
69
}
710
}

examples/iam-assumable-role-with-oidc/versions.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ terraform {
22
required_version = ">= 0.12.6"
33

44
required_providers {
5-
aws = ">= 2.23"
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 2.23"
8+
}
69
}
710
}

examples/iam-assumable-role-with-saml/versions.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ terraform {
22
required_version = ">= 0.12.6"
33

44
required_providers {
5-
aws = ">= 2.23"
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 2.23"
8+
}
69
}
710
}

examples/iam-assumable-role/versions.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ terraform {
22
required_version = ">= 0.12.6"
33

44
required_providers {
5-
aws = ">= 2.23"
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 2.23"
8+
}
69
}
710
}

examples/iam-assumable-roles-with-saml/versions.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ terraform {
22
required_version = ">= 0.12.6"
33

44
required_providers {
5-
aws = ">= 2.23"
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 2.23"
8+
}
69
}
710
}

examples/iam-assumable-roles/versions.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ terraform {
22
required_version = ">= 0.12.6"
33

44
required_providers {
5-
aws = ">= 2.23"
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 2.23"
8+
}
69
}
710
}

examples/iam-group-complete/versions.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ terraform {
22
required_version = ">= 0.12.6"
33

44
required_providers {
5-
aws = ">= 2.23"
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 2.23"
8+
}
69
}
710
}

examples/iam-group-with-assumable-roles-policy/versions.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ terraform {
22
required_version = ">= 0.12.6"
33

44
required_providers {
5-
aws = ">= 2.23"
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 2.23"
8+
}
69
}
710
}

0 commit comments

Comments
 (0)