Skip to content

Commit 542fc5a

Browse files
authored
feat(iam-eks-role): Add variable to allow change of IAM assume role condition test operator (#367)
1 parent baec7b9 commit 542fc5a

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

examples/iam-eks-role/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Run `terraform destroy` when you don't need these resources.
3636
|------|--------|---------|
3737
| <a name="module_eks"></a> [eks](#module\_eks) | terraform-aws-modules/eks/aws | ~> 18.0 |
3838
| <a name="module_iam_eks_role"></a> [iam\_eks\_role](#module\_iam\_eks\_role) | ../../modules/iam-eks-role | n/a |
39+
| <a name="module_iam_eks_role_with_assume_wildcard"></a> [iam\_eks\_role\_with\_assume\_wildcard](#module\_iam\_eks\_role\_with\_assume\_wildcard) | ../../modules/iam-eks-role | n/a |
3940
| <a name="module_iam_eks_role_with_self_assume"></a> [iam\_eks\_role\_with\_self\_assume](#module\_iam\_eks\_role\_with\_self\_assume) | ../../modules/iam-eks-role | n/a |
4041

4142
## Resources

examples/iam-eks-role/main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ module "iam_eks_role_with_self_assume" {
4040
}
4141
}
4242

43+
#############################################
44+
# IAM EKS role with wildcard assume condition
45+
#############################################
46+
module "iam_eks_role_with_assume_wildcard" {
47+
source = "../../modules/iam-eks-role"
48+
role_name = "my-app-assume-wildcard"
49+
50+
cluster_service_accounts = {
51+
(random_pet.this.id) = ["default:my-app-prefix-*"]
52+
}
53+
assume_role_condition_test = "StringLike"
54+
55+
tags = {
56+
Name = "my-app-assume-wildcard"
57+
}
58+
59+
role_policy_arns = {
60+
AmazonEKS_CNI_Policy = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
61+
}
62+
}
63+
4364
##################
4465
# Extra resources
4566
##################

modules/iam-eks-role/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ No modules.
108108
| Name | Description | Type | Default | Required |
109109
|------|-------------|------|---------|:--------:|
110110
| <a name="input_allow_self_assume_role"></a> [allow\_self\_assume\_role](#input\_allow\_self\_assume\_role) | Determines whether to allow the role to be [assume itself](https://aws.amazon.com/blogs/security/announcing-an-update-to-iam-role-trust-policy-behavior/) | `bool` | `false` | no |
111+
| <a name="input_assume_role_condition_test"></a> [assume\_role\_condition\_test](#input\_assume\_role\_condition\_test) | Name of the [IAM condition operator](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html) to evaluate when assuming the role | `string` | `"StringEquals"` | no |
111112
| <a name="input_cluster_service_accounts"></a> [cluster\_service\_accounts](#input\_cluster\_service\_accounts) | EKS cluster and k8s ServiceAccount pairs. Each EKS cluster can have multiple k8s ServiceAccount. See README for details | `map(list(string))` | `{}` | no |
112113
| <a name="input_create_role"></a> [create\_role](#input\_create\_role) | Whether to create a role | `bool` | `true` | no |
113114
| <a name="input_force_detach_policies"></a> [force\_detach\_policies](#input\_force\_detach\_policies) | Whether policies should be detached from this role when destroying | `bool` | `false` | no |

modules/iam-eks-role/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ data "aws_iam_policy_document" "assume_role_with_oidc" {
5252
}
5353

5454
condition {
55-
test = "StringEquals"
55+
test = var.assume_role_condition_test
5656
variable = "${replace(data.aws_eks_cluster.main[statement.key].identity[0].oidc[0].issuer, "https://", "")}:sub"
5757
values = [for s in statement.value : "system:serviceaccount:${s}"]
5858
}

modules/iam-eks-role/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ variable "allow_self_assume_role" {
6969
type = bool
7070
default = false
7171
}
72+
73+
variable "assume_role_condition_test" {
74+
description = "Name of the [IAM condition operator](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html) to evaluate when assuming the role"
75+
type = string
76+
default = "StringEquals"
77+
}

0 commit comments

Comments
 (0)