Skip to content

Commit

Permalink
feat(iam-eks-role): Add variable to allow change of IAM assume role c…
Browse files Browse the repository at this point in the history
…ondition test operator (#367)
  • Loading branch information
enver authored May 7, 2023
1 parent baec7b9 commit 542fc5a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/iam-eks-role/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Run `terraform destroy` when you don't need these resources.
|------|--------|---------|
| <a name="module_eks"></a> [eks](#module\_eks) | terraform-aws-modules/eks/aws | ~> 18.0 |
| <a name="module_iam_eks_role"></a> [iam\_eks\_role](#module\_iam\_eks\_role) | ../../modules/iam-eks-role | n/a |
| <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 |
| <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 |

## Resources
Expand Down
21 changes: 21 additions & 0 deletions examples/iam-eks-role/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ module "iam_eks_role_with_self_assume" {
}
}

#############################################
# IAM EKS role with wildcard assume condition
#############################################
module "iam_eks_role_with_assume_wildcard" {
source = "../../modules/iam-eks-role"
role_name = "my-app-assume-wildcard"

cluster_service_accounts = {
(random_pet.this.id) = ["default:my-app-prefix-*"]
}
assume_role_condition_test = "StringLike"

tags = {
Name = "my-app-assume-wildcard"
}

role_policy_arns = {
AmazonEKS_CNI_Policy = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
}
}

##################
# Extra resources
##################
Expand Down
1 change: 1 addition & 0 deletions modules/iam-eks-role/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <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 |
| <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 |
| <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 |
| <a name="input_create_role"></a> [create\_role](#input\_create\_role) | Whether to create a role | `bool` | `true` | no |
| <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 |
Expand Down
2 changes: 1 addition & 1 deletion modules/iam-eks-role/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ data "aws_iam_policy_document" "assume_role_with_oidc" {
}

condition {
test = "StringEquals"
test = var.assume_role_condition_test
variable = "${replace(data.aws_eks_cluster.main[statement.key].identity[0].oidc[0].issuer, "https://", "")}:sub"
values = [for s in statement.value : "system:serviceaccount:${s}"]
}
Expand Down
6 changes: 6 additions & 0 deletions modules/iam-eks-role/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ variable "allow_self_assume_role" {
type = bool
default = false
}

variable "assume_role_condition_test" {
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"
type = string
default = "StringEquals"
}

0 comments on commit 542fc5a

Please sign in to comment.