Skip to content

feat(iam-role-for-service-accounts-eks): Add support for EKS pod identity service #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/iam-role-for-service-accounts-eks/README.md
Original file line number Diff line number Diff line change
@@ -20,13 +20,13 @@ Run `terraform destroy` when you don't need these resources.
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.29 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.29 |

## Modules

@@ -46,6 +46,7 @@ Run `terraform destroy` when you don't need these resources.
| <a name="module_external_secrets_irsa_role"></a> [external\_secrets\_irsa\_role](#module\_external\_secrets\_irsa\_role) | ../../modules/iam-role-for-service-accounts-eks | n/a |
| <a name="module_fsx_lustre_csi_irsa_role"></a> [fsx\_lustre\_csi\_irsa\_role](#module\_fsx\_lustre\_csi\_irsa\_role) | ../../modules/iam-role-for-service-accounts-eks | n/a |
| <a name="module_iam_eks_role"></a> [iam\_eks\_role](#module\_iam\_eks\_role) | terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks | n/a |
| <a name="module_iam_pod_identity_role"></a> [iam\_pod\_identity\_role](#module\_iam\_pod\_identity\_role) | terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks | n/a |
| <a name="module_iam_policy"></a> [iam\_policy](#module\_iam\_policy) | terraform-aws-modules/iam/aws//modules/iam-policy | n/a |
| <a name="module_irsa_role"></a> [irsa\_role](#module\_irsa\_role) | ../../modules/iam-role-for-service-accounts-eks | n/a |
| <a name="module_karpenter_controller_irsa_role"></a> [karpenter\_controller\_irsa\_role](#module\_karpenter\_controller\_irsa\_role) | ../../modules/iam-role-for-service-accounts-eks | n/a |
@@ -61,6 +62,7 @@ Run `terraform destroy` when you don't need these resources.

| Name | Type |
|------|------|
| [aws_eks_pod_identity_association.my_app_staging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_pod_identity_association) | resource |
| [aws_iam_policy.additional](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |

27 changes: 27 additions & 0 deletions examples/iam-role-for-service-accounts-eks/main.tf
Original file line number Diff line number Diff line change
@@ -399,6 +399,26 @@ module "iam_eks_role" {
}
}

################################################################################
# Pod Identity Roles
################################################################################
module "iam_pod_identity_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
role_name = "my-pod-identity"

role_policy_arns = {
policy = module.iam_policy.arn
}
}

# This resource requires installed eks-pod-identity-agent to work
resource "aws_eks_pod_identity_association" "my_app_staging" {
cluster_name = module.eks.cluster_name
role_arn = module.iam_pod_identity_role.iam_role_arn
namespace = "default"
service_account = "my-app-staging"
}

################################################################################
# Supporting Resources
################################################################################
@@ -438,6 +458,13 @@ module "eks" {
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets

cluster_addons = {
# Required for Pod Identity roles
eks-pod-identity-agent = {
most_recent = true
}
}

eks_managed_node_groups = {
default = {}
}
2 changes: 1 addition & 1 deletion examples/iam-role-for-service-accounts-eks/versions.tf
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0"
version = ">= 5.29"
}
}
}
4 changes: 2 additions & 2 deletions modules/iam-role-for-service-accounts-eks/README.md
Original file line number Diff line number Diff line change
@@ -105,13 +105,13 @@ module "eks" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.29 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.29 |

## Modules

10 changes: 10 additions & 0 deletions modules/iam-role-for-service-accounts-eks/main.tf
Original file line number Diff line number Diff line change
@@ -62,6 +62,16 @@ data "aws_iam_policy_document" "this" {

}
}

statement {
effect = "Allow"
actions = ["sts:AssumeRole", "sts:TagSession"]

principals {
type = "Service"
identifiers = ["pods.eks.amazonaws.com"]
}
}
}

resource "aws_iam_role" "this" {
2 changes: 1 addition & 1 deletion modules/iam-role-for-service-accounts-eks/versions.tf
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0"
version = ">= 5.29"
}
}
}