eks¶
Basic, production-oriented Amazon EKS cluster:
- EKS control plane with Kubernetes secrets envelope-encrypted by a dedicated KMS key (rotation enabled).
- All control plane log types sent to a KMS-encrypted CloudWatch log group (365 days retention by default).
- Private API endpoint always on; public endpoint disabled by default (
endpoint_public_access = false). - One managed node group (IMDSv2 only with hop limit 1, encrypted gp3 root volumes) with its IAM role. Pods use IRSA, not the node role.
- IAM OIDC provider for IRSA, plus an IRSA role for cluster-autoscaler scoped to node groups tagged as owned by this cluster.
- Optional Helm add-ons, each behind a flag:
ingress-nginx(behind an NLB),cluster-autoscalerandcert-manager(with CRDs).
The module does not create the network: pass an existing vpc_id and subnet_ids (for example from the vpc module).
Usage¶
module "eks" {
source = "github.com/rafaelcarvajal05/terraform-stacks//modules/eks?ref=v0.1.0"
name = "my-app"
vpc_id = "vpc-0123456789abcdef0"
subnet_ids = ["subnet-aaaa", "subnet-bbbb", "subnet-cccc"]
node_instance_types = ["t3.large"]
node_min_size = 2
node_max_size = 5
node_desired_size = 2
tags = {
Environment = "prod"
}
}
Configuring the helm provider¶
The module installs add-ons with helm_release, but, as a reusable module, it does not configure any
provider. Configure aws and helm in the root module and point helm at the cluster using the module
outputs. Using exec avoids storing a short-lived token in the state:
provider "aws" {
region = "us-east-1"
}
provider "helm" {
kubernetes {
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
exec {
api_version = "client.authentication.k8s.io/v1beta1"
command = "aws"
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
}
}
}
With hashicorp/helm >= 3.0, kubernetes is an attribute instead of a block
(kubernetes = { host = ..., exec = { ... } }).
If you also use the kubernetes provider in the root module, configure it with the same host,
cluster_ca_certificate and exec arguments.
Notes:
- Terraform must reach the API endpoint to install the add-ons. With the default private-only endpoint, run
Terraform from inside the VPC (CI runner, bastion, VPN), or set
endpoint_public_access = truewith a restrictedendpoint_public_access_cidrs. Alternatively set allenable_*flags tofalseand install the add-ons separately. - The identity that creates the cluster gets cluster-admin access. Grant access to other principals with EKS
access entries or the
aws-authConfigMap. - Node group
desired_sizechanges are ignored after creation so cluster-autoscaler can manage it.
Requirements¶
| Name | Version |
|---|---|
| terraform | >= 1.6.0 |
| aws | >= 5.0 |
| helm | >= 2.12 |
| tls | >= 4.0 |
Providers¶
| Name | Version |
|---|---|
| aws | >= 5.0 |
| helm | >= 2.12 |
| tls | >= 4.0 |
Modules¶
No modules.
Resources¶
Inputs¶
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| name | Name of the EKS cluster. Also used as prefix for related resources (IAM roles, KMS alias, log group). | string |
n/a | yes |
| subnet_ids | Subnet IDs (ideally private, in at least two AZs) for the control plane ENIs and the managed node group. | list(string) |
n/a | yes |
| vpc_id | ID of the VPC where the cluster is created. | string |
n/a | yes |
| cert_manager_chart_version | Version of the cert-manager Helm chart. | string |
"v1.17.2" |
no |
| cluster_autoscaler_chart_version | Version of the cluster-autoscaler Helm chart. | string |
"9.46.6" |
no |
| cluster_log_retention_days | Retention (days) of the control plane CloudWatch log group. | number |
365 |
no |
| cluster_log_types | Control plane log types sent to CloudWatch Logs. | list(string) |
[ |
no |
| enable_cert_manager | Install cert-manager (including its CRDs). | bool |
true |
no |
| enable_cluster_autoscaler | Install cluster-autoscaler with an IRSA role scoped to this cluster's node groups. | bool |
true |
no |
| enable_ingress_nginx | Install the ingress-nginx controller (exposed through an AWS Network Load Balancer). | bool |
true |
no |
| endpoint_public_access | Whether the Kubernetes API endpoint is reachable from the internet. The private endpoint is always enabled. | bool |
false |
no |
| endpoint_public_access_cidrs | CIDR blocks allowed to reach the public API endpoint when endpoint_public_access is true. Restrict it; do not use 0.0.0.0/0 in production. | list(string) |
[] |
no |
| ingress_nginx_chart_version | Version of the ingress-nginx Helm chart. | string |
"4.12.1" |
no |
| kms_key_deletion_window_in_days | Waiting period (days) before the KMS key used for secrets and logs encryption is deleted. | number |
30 |
no |
| kubernetes_version | Kubernetes version of the EKS control plane (for example "1.33"). | string |
"1.33" |
no |
| node_desired_size | Initial desired number of nodes. Changes after creation are ignored so cluster-autoscaler can manage it. | number |
2 |
no |
| node_disk_size | Root EBS volume size (GiB) of each node. The volume is always encrypted. | number |
50 |
no |
| node_instance_types | EC2 instance types for the managed node group. | list(string) |
[ |
no |
| node_max_size | Maximum number of nodes in the managed node group. | number |
3 |
no |
| node_min_size | Minimum number of nodes in the managed node group. | number |
1 |
no |
| tags | Tags applied to all AWS resources created by the module. | map(string) |
{} |
no |
Outputs¶
| Name | Description |
|---|---|
| cluster_arn | ARN of the EKS cluster. |
| cluster_autoscaler_role_arn | ARN of the cluster-autoscaler IRSA role (null when enable_cluster_autoscaler is false). |
| cluster_certificate_authority_data | Base64-encoded certificate authority data of the cluster. |
| cluster_endpoint | Endpoint of the Kubernetes API server. |
| cluster_name | Name of the EKS cluster. |
| cluster_security_group_id | ID of the cluster security group created by EKS. |
| kms_key_arn | ARN of the KMS key used for secrets and log encryption. |
| node_group_role_arn | ARN of the IAM role used by the managed node group. |
| oidc_issuer_url | OIDC issuer URL of the cluster. |
| oidc_provider_arn | ARN of the IAM OIDC provider used for IRSA. |