Write an EKS cluster with a managed node group using the community module.
AdvancedHands-onWrite-Terraform tasks
Answer
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 20.0"
cluster_name = "devopsshack-prod"
cluster_version = "1.31"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
cluster_endpoint_public_access = true
enable_cluster_creator_admin_permissions = true
eks_managed_node_groups = {
general = {
instance_types = ["m6i.large"]
min_size = 2
max_size = 6
desired_size = 3
capacity_type = "ON_DEMAND"
}
}
tags = { Environment = "prod" }
}
Key trick → Pin the module's major version, because v19 to v20 changed authentication to EKS access entries. Put nodes in private subnets, and enable_cluster_creator_admin_permissions keeps you from locking yourself out.
More on Write-Terraform tasks
Write Terraform for an S3 bucket with versioning, encryption and public access blocked.BeginnerWrite the remote backend configuration with S3 and state locking.BeginnerWrite a VPC with public and private subnets across 3 AZs using `count` or `for_each`.IntermediateWrite a reusable module for an EC2 instance with inputs, outputs and validation.AdvancedWrite a security group that allows HTTPS from anywhere and SSH only from an office CIDR.BeginnerCreate multiple IAM users from a list with `for_each`, and output their ARNs as a map.Beginner