Skip to content

Commit

Permalink
update EKS example
Browse files Browse the repository at this point in the history
  • Loading branch information
dak1n1 committed Feb 26, 2021
1 parent c09a7c1 commit c706a16
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions _examples/eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0.0"
version = ">= 2.0.2"
}
helm = {
source = "hashicorp/helm"
version = ">= 2.0.1"
version = ">= 2.0.2"
}
aws = {
source = "hashicorp/aws"
Expand All @@ -19,21 +19,37 @@ data "aws_eks_cluster" "default" {
name = module.cluster.cluster_id
}

data "aws_eks_cluster_auth" "default" {
name = module.cluster.cluster_id
}

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

# This configuration is also valid, but users may prefer not to install the full aws binary onto CI systems.
#provider "kubernetes" {
# host = data.aws_eks_cluster.default.endpoint
# cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
# exec {
# api_version = "client.authentication.k8s.io/v1alpha1"
# args = ["eks", "get-token", "--cluster-name", module.vpc.cluster_name]
# command = "aws"
# }
#}

# This configuration is also valid, but the token may expire during long-running applies.
# data "aws_eks_cluster_auth" "default" {
# name = module.cluster.cluster_id
#}
#provider "kubernetes" {
# host = data.aws_eks_cluster.default.endpoint
# cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
Expand All @@ -44,11 +60,10 @@ provider "helm" {
kubernetes {
host = data.aws_eks_cluster.default.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
token = data.aws_eks_cluster_auth.default.token
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
command = "aws"
args = ["token", "--cluster-id", module.vpc.cluster_name]
command = "aws-iam-authenticator"
}
}
}
Expand All @@ -63,7 +78,7 @@ module "vpc" {

module "cluster" {
source = "terraform-aws-modules/eks/aws"
version = "v13.2.1"
version = "14.0.0"

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

workers_group_defaults = {
root_volume_type = "gp2"
}
worker_groups = [
{
instance_type = var.workers_type
asg_desired_capacity = var.workers_count
asg_max_size = "10"
asg_max_size = 4
},
]

Expand Down

0 comments on commit c706a16

Please sign in to comment.