Skip to content

Commit c706a16

Browse files
committed
update EKS example
1 parent c09a7c1 commit c706a16

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

_examples/eks/main.tf

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ terraform {
22
required_providers {
33
kubernetes = {
44
source = "hashicorp/kubernetes"
5-
version = ">= 2.0.0"
5+
version = ">= 2.0.2"
66
}
77
helm = {
88
source = "hashicorp/helm"
9-
version = ">= 2.0.1"
9+
version = ">= 2.0.2"
1010
}
1111
aws = {
1212
source = "hashicorp/aws"
@@ -19,21 +19,37 @@ data "aws_eks_cluster" "default" {
1919
name = module.cluster.cluster_id
2020
}
2121

22-
data "aws_eks_cluster_auth" "default" {
23-
name = module.cluster.cluster_id
24-
}
25-
22+
# This configuration relies on a plugin binary to fetch the token to the EKS cluster.
23+
# The main advantage is that the token will always be up-to-date, even when the `terraform apply` runs for
24+
# a longer time than the token TTL. The downside of this approach is that the binary must be present
25+
# on the system running terraform, either in $PATH as shown below, or in another location, which can be
26+
# specified in the `command`.
27+
# See the commented provider blocks below for alternative configuration options.
2628
provider "kubernetes" {
2729
host = data.aws_eks_cluster.default.endpoint
2830
cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
2931
exec {
3032
api_version = "client.authentication.k8s.io/v1alpha1"
31-
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
32-
command = "aws"
33+
args = ["token", "--cluster-id", module.vpc.cluster_name]
34+
command = "aws-iam-authenticator"
3335
}
3436
}
3537

38+
# This configuration is also valid, but users may prefer not to install the full aws binary onto CI systems.
39+
#provider "kubernetes" {
40+
# host = data.aws_eks_cluster.default.endpoint
41+
# cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
42+
# exec {
43+
# api_version = "client.authentication.k8s.io/v1alpha1"
44+
# args = ["eks", "get-token", "--cluster-name", module.vpc.cluster_name]
45+
# command = "aws"
46+
# }
47+
#}
48+
3649
# This configuration is also valid, but the token may expire during long-running applies.
50+
# data "aws_eks_cluster_auth" "default" {
51+
# name = module.cluster.cluster_id
52+
#}
3753
#provider "kubernetes" {
3854
# host = data.aws_eks_cluster.default.endpoint
3955
# cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
@@ -44,11 +60,10 @@ provider "helm" {
4460
kubernetes {
4561
host = data.aws_eks_cluster.default.endpoint
4662
cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
47-
token = data.aws_eks_cluster_auth.default.token
4863
exec {
4964
api_version = "client.authentication.k8s.io/v1alpha1"
50-
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
51-
command = "aws"
65+
args = ["token", "--cluster-id", module.vpc.cluster_name]
66+
command = "aws-iam-authenticator"
5267
}
5368
}
5469
}
@@ -63,7 +78,7 @@ module "vpc" {
6378

6479
module "cluster" {
6580
source = "terraform-aws-modules/eks/aws"
66-
version = "v13.2.1"
81+
version = "14.0.0"
6782

6883
vpc_id = module.vpc.vpc_id
6984
subnets = module.vpc.subnets
@@ -75,11 +90,14 @@ module "cluster" {
7590
# See ./kubernetes-config/main.tf provider block for details.
7691
write_kubeconfig = false
7792

93+
workers_group_defaults = {
94+
root_volume_type = "gp2"
95+
}
7896
worker_groups = [
7997
{
8098
instance_type = var.workers_type
8199
asg_desired_capacity = var.workers_count
82-
asg_max_size = "10"
100+
asg_max_size = 4
83101
},
84102
]
85103

0 commit comments

Comments
 (0)