modules/virtual-cluster. Source it as terraform-aws-modules/emr/aws//modules/virtual-cluster.
Prerequisites
- An existing EKS cluster with IRSA (IAM Roles for Service Accounts) enabled.
- An OIDC provider associated with the cluster.
- The AWS CLI installed locally (required for the
aws eks get-tokenauthentication helper).
IRSA is currently required for EMR on EKS. Track the upstream issue for native EKS Pod Identity support at aws/containers-roadmap#2397.
Setup
Provision the EKS cluster
Use the
terraform-aws-modules/eks/aws module to create an EKS cluster. Enable IRSA and set up the Kubernetes provider so Terraform can create the EMR namespace and RBAC resources:Create the virtual cluster
Point the virtual cluster module at the EKS cluster name and OIDC provider ARN. Set The module creates:
create_namespace = true to let the module create the Kubernetes namespace and the required RBAC role and role binding.- A Kubernetes namespace,
Role, andRoleBindingin the namespace. - An IAM execution role with the S3 bucket access policy and IRSA trust policy.
- A CloudWatch log group for job logs.
- The
aws_emr_containers_virtual_clusterresource scoped to the namespace.
Configure S3 bucket access
Pass the S3 bucket ARN (and the wildcard for objects) to If your jobs need additional permissions (for example, Glue catalog access), use
s3_bucket_arns. The module attaches an IAM policy that allows s3:GetObject, s3:PutObject, s3:DeleteObject, and s3:ListBucket against those ARNs:iam_role_additional_policies to attach extra policies to the execution role.Multiple virtual clusters
You can create multiple virtual clusters on the same EKS cluster, each in its own namespace:VPC endpoints
The full working example atexamples/virtual-cluster/main.tf creates VPC endpoints for emr-containers, ecr.api, ecr.dkr, sts, logs, and s3. These endpoints keep EKS node traffic on the AWS network and are recommended for production clusters.
Destroy considerations
If an EMR virtual cluster fails to delete and enters theARRESTED state, you can force-delete it with: