Cloud Posse Terraform AWS EKS Cluster Infrastructure Orchestration

The deployment of a production-grade Kubernetes environment on Amazon Web Services requires more than the simple initiation of a control plane; it demands a rigorous approach to identity management, network security, encryption, and scalable compute abstractions. The Cloud Posse Terraform AWS EKS Cluster module serves as a specialized engineering framework designed to provision a fully configured AWS EKS (Elastic Kubernetes Service) cluster. This module is not a standalone utility but a foundational element of Cloud Posse's reference architecture, specifically engineered to integrate with Karpenter for advanced node autoscaling and a variety of EKS add-ons to ensure a manageable and scalable Kubernetes footprint. By abstracting the complexities of the AWS EKS API and providing a standardized interface for cluster creation, the module enables DevOps teams to deploy clusters with minimal manual intervention while maintaining granular control over the underlying infrastructure.

The architecture of this module is designed to support a modular ecosystem. While the core module focuses on the EKS master nodes (the control plane), it is built to be paired with the terraform-aws-eks-node-group and terraform-aws-eks-fargate-profile modules. This separation of concerns allows administrators to choose the most appropriate compute model for their workloads—whether using managed node groups for consistency, Fargate for serverless Kubernetes pods, or the terraform-aws-eks-workers module for traditional Auto Scaling Group-based worker nodes. Although the latter is noted as a rarer choice in modern deployments compared to managed node groups, the module maintains compatibility to ensure flexibility across different architectural requirements.

Functional Resource Provisioning

The Cloud Posse EKS cluster module manages the lifecycle of several critical AWS resources that constitute the Kubernetes control plane and its surrounding security perimeter.

The primary resource is the aws_eks_cluster, which represents the managed Kubernetes control plane. This component is responsible for the API server, the scheduler, and the controller manager. By utilizing this module, users ensure that the control plane is provisioned according to best practices, including the integration of aws_kms_key.cluster for the encryption of Kubernetes secrets. This ensures that sensitive data stored within the cluster is encrypted at rest using a customer-managed key, reducing the risk of data exposure.

Beyond the core cluster, the module handles the OIDC Provider through the aws_iam_openid_connect_provider resource. This is a critical piece of the EKS puzzle, as it enables the cluster to assign IAM roles to Kubernetes service accounts (IRSA). This allows pods to assume specific AWS IAM roles to interact with other AWS services (such as S3 or DynamoDB) without requiring hardcoded credentials or overly permissive node-level permissions.

To ensure the cluster is observable and maintainable, the module integrates CloudWatch logging via the aws_cloudwatch_log_group resource. This allows for the centralization of cluster logs, which is vital for auditing and troubleshooting control plane events.

Structural Decomposition of the Module

The internal organization of the terraform-aws-eks-cluster module is divided into specific files to ensure maintainability and a clear separation of logic.

File Primary Resources Purpose
main.tf aws_eks_cluster.default, aws_kms_key.cluster Core EKS cluster provisioning and encryption keys
auth.tf aws_eks_access_entry.*, aws_eks_access_policy_association.* Cluster access control and IAM authentication
iam.tf aws_iam_role.default, aws_iam_role_policy_attachment.* Service roles for the cluster and policy attachments
security-group.tf aws_vpc_security_group_ingress_rule.* Network security and firewall rules for the control plane
context.tf module.label Resource naming conventions and tagging logic
variables.tf N/A Input variable definitions for cluster configuration
outputs.tf N/A Module output definitions for downstream consumption
versions.tf N/A Provider version constraints for AWS and Terraform

The use of context.tf and the module.label indicates a commitment to the shared context pattern. This ensures that every resource created—from the IAM role to the security group—carries a consistent naming convention and a set of tags, making it significantly easier to manage resources in multi-account or multi-environment (Dev/Stage/Prod) setups.

Advanced Access Control and Authentication

One of the most significant evolutions in this module is the transition in how access to the Kubernetes cluster is managed. In versions prior to v4, AWS lacked a robust API for managing access entries, which forced engineers to rely on the aws-auth ConfigMap. This often led to race conditions and synchronization issues.

With the release of v4, the module exclusively utilizes the AWS EKS Access Entry API. This provides a native AWS mechanism to map IAM principals to Kubernetes permissions. The module implements this through three primary configuration paths:

  • access_entry_map: This allows for a static mapping where specific IAM principals are explicitly tied to specific access policies. This is ideal for known administrative roles.
  • access_entries: A dynamic, list-based configuration that allows for the addition of multiple entities to the cluster's access list.
  • access_entries_for_nodes: This automates the necessary access configuration for worker nodes, ensuring that the compute layer can communicate with the control plane immediately upon joining.

This shift to the AWS API for authentication removes the fragility associated with editing the aws-auth ConfigMap and provides a more audit-able and secure method of granting cluster access.

EKS Auto Mode Integration

Starting with the General Availability of EKS Auto Mode in December 2024, the Cloud Posse module has integrated support for this paradigm. EKS Auto Mode is a managed experience where AWS takes over the responsibility for compute, networking, and storage management, effectively turning EKS into a more "serverless" experience for the cluster administrator.

To enable EKS Auto Mode, users must configure specific variables within the module:

  • auto_mode_compute_config: This variable enables the compute management. It allows the user to define node_pools (such as "general-purpose" and "system") and specify the node_role_arn (e.g., aws_iam_role.auto_mode_node.arn) that the auto-managed nodes will assume.
  • auto_mode_storage_config: This enables managed block storage, allowing AWS to handle the provisioning of EBS volumes for Kubernetes PersistentVolumeClaims.
  • auto_mode_elastic_load_balancing: This integrates the AWS Load Balancer Controller functionality directly into the EKS control plane, simplifying the exposure of services to the internet or internal VPCs.

Example configuration for EKS Auto Mode:

```hcl
module "eks_cluster" {
source = "cloudposse/eks-cluster/aws"

automodecomputeconfig = {
enabled = true
node
pools = ["general-purpose", "system"]
noderolearn = awsiamrole.automodenode.arn
}

automodestorageconfig = {
block
storage = {
enabled = true
}
}

automodeelasticloadbalancing = {
enabled = true
}
}
```

Network Security and Observability

Network isolation is managed through the security-group.tf file, which provisions aws_vpc_security_group_ingress_rule resources. This ensures that only authorized traffic can reach the EKS API server. The module provides flexibility in how the cluster endpoint is exposed:

  • endpoint_private_access: When enabled, this allows communication between the worker nodes and the EKS API server to remain within the AWS network, never traversing the public internet.
  • endpoint_public_access: This controls whether the EKS API server is accessible from the public internet, which can be restricted further using CIDR blocks for increased security.

For observability, the module exposes configurations for CloudWatch logging through enabled_cluster_log_types and cluster_log_retention_period. This ensures that logs are not only captured but retained for a duration that meets corporate compliance or troubleshooting requirements.

Module Integration and the Ecosystem

The terraform-aws-eks-cluster module is designed to be the "brain" of a larger infrastructure web. It provides essential outputs, such as the eks_cluster_role_arn and the Kubernetes server version (eks_cluster_version), which are consumed by other modules to ensure alignment.

The following related projects and modules form the complete EKS ecosystem:

  • terraform-aws-components eks/clusters: A root module that orchestrates the deployment of the entire EKS stack.
  • terraform-aws-components eks/karpenter and eks/karpenter-provisioner: Root modules used to deploy Karpenter, which optimizes node scaling by launching the right-sized instances based on pending pod requirements.
  • terraform-aws-eks-node-group: The recommended way to provision worker nodes for the cluster.
  • terraform-aws-eks-workers: An alternative for provisioning Auto Scaling Groups and Security Groups for workers.
  • terraform-aws-ec2-autoscale-group: A general-purpose module for ASG and Launch Template creation.

For those utilizing the module in a broader AWS environment, the following ECS-related modules are often used in tandem for hybrid container strategies:

  • terraform-aws-ecs-container-definition: Generates JSON container definitions for aws_ecs_task_definition.
  • terraform-aws-ecs-alb-service-task: Implements an ECS service exposed via an Application Load Balancer (ALB).
  • terraform-aws-ecs-web-app: A high-level module for web apps supporting CI/CD and monitoring.
  • terraform-aws-ecs-codepipeline: Implements CI/CD using AWS CodePipeline and CodeBuild.
  • terraform-aws-ecs-cloudwatch-autoscaling: Scales ECS services based on CloudWatch metrics.
  • terraform-aws-ecs-cloudwatch-sns-alarms: Creates alarms for ECS health monitoring.

Deployment Implementation and Tagging

When implementing the module, particular attention must be paid to the tagging of networking resources. To ensure that the AWS Load Balancer Controller and EKS can discover subnets, specific tags are required on the VPC subnets.

In a typical deployment, the following tags are applied:

  • kubernetes.io/cluster/${module.label.id} = "shared": This tag is mandatory for EKS and Kubernetes to discover and manage networking resources, specifically for the AWS Load Balancer Controller to identify which subnets are suitable for ALB or NLB ingress.

A basic implementation for the provider and identity context is as follows:

```hcl
provider "aws" {
region = var.region
}

data "awscalleridentity" "current" {}

data "awsiamsessioncontext" "current" {
arn = data.aws
caller_identity.current.arn
}
```

Versioning and Migration Path

The evolution of the terraform-aws-eks-cluster module has involved significant architectural shifts to keep pace with AWS API changes. Users must be cautious when upgrading versions to avoid catastrophic resource replacement.

Release 2.0.0 (which was previously released as version 0.45.0) introduced changes that could trigger the destruction and recreation of an existing EKS cluster if applied blindly. To mitigate this, users are directed to the v1 to v2 migration path.

Furthermore, the move to v4 represents a paradigm shift in authentication. Prior to v4, the lack of an AWS API for access management created operational hurdles. Version 4 resolves these issues by exclusively using the AWS API for access entries, rendering the workarounds used in v2 and v3 obsolete. Users moving from v3 to v4 should consult the "Migrating from v3 to v4" documentation to ensure a seamless transition without cluster downtime.

Technical Specifications and Dependencies

The module relies on a set of underlying utilities and version constraints to ensure stability.

Component Source/Provider Version/Constraint
utils cloudposse/utils/aws 1.4.0
vpc cloudposse/stack-config/yaml//modules/remote-state 2.0.0
vpccnieksiamrole cloudposse/eks-iam-role/aws 2.2.1
vpc_ingress cloudposse/stack-config/yaml//modules/remote-state 2.0.0

The module also handles complex dependencies through the addons_depends_on variable, ensuring that EKS add-ons are only provisioned after the cluster and its necessary IAM roles are fully active and stable.

Conclusion

The Cloud Posse Terraform AWS EKS Cluster module is an enterprise-grade abstraction that transforms the complex process of EKS provisioning into a repeatable, version-controlled workflow. By integrating the latest AWS features, such as EKS Auto Mode and the Access Entry API, it eliminates the operational friction historically associated with Kubernetes on AWS. The module's strength lies in its architectural alignment with the broader Cloud Posse ecosystem, specifically its synergy with Karpenter for efficient compute scaling and the use of a shared context for resource labeling. For organizations seeking to move away from the manual management of aws-auth ConfigMaps and toward a native AWS IAM-integrated access model, this module provides the necessary framework to ensure security, scalability, and stability. The transition from v1 through v4 demonstrates a clear trajectory toward adopting AWS-native APIs, reducing the reliance on custom workarounds and increasing the overall reliability of the Kubernetes control plane.

Sources

  1. Cloud Posse EKS Cluster Documentation
  2. Cloud Posse Terraform AWS EKS Cluster GitHub
  3. DeepWiki Cloud Posse EKS Cluster Guide
  4. Cloud Posse Terraform AWS EKS Cluster Components

Related Posts