Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update eks module v18 #65

Merged
merged 10 commits into from
Jul 29, 2022
20 changes: 9 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
# .tfstate files
*.tfstate
*.tfstate.*
*.tfplan

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
Expand All @@ -21,9 +22,6 @@ override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
# Ignore CLI configuration files
.terraformrc
terraform.rc
133 changes: 48 additions & 85 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Learn Terraform - Provision an EKS Cluster

This repo is a companion repo to the [Provision an EKS Cluster learn guide](https://learn.hashicorp.com/terraform/kubernetes/provision-eks-cluster), containing
Terraform configuration files to provision an EKS cluster on AWS.
Terraform configuration files to provision an EKS cluster on AWS.
77 changes: 48 additions & 29 deletions eks-cluster.tf
Original file line number Diff line number Diff line change
@@ -1,38 +1,57 @@
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "17.24.0"
source = "terraform-aws-modules/eks/aws"
version = "18.26.6"

cluster_name = local.cluster_name
cluster_version = "1.20"
subnets = module.vpc.private_subnets
cluster_version = "1.22"

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets

vpc_id = module.vpc.vpc_id
eks_managed_node_group_defaults = {
ami_type = "AL2_x86_64"

workers_group_defaults = {
root_volume_type = "gp2"
attach_cluster_primary_security_group = true

# Disabling and using externally provided security groups
create_security_group = false
}

worker_groups = [
{
name = "worker-group-1"
instance_type = "t2.small"
additional_userdata = "echo foo bar"
additional_security_group_ids = [aws_security_group.worker_group_mgmt_one.id]
asg_desired_capacity = 2
},
{
name = "worker-group-2"
instance_type = "t2.medium"
additional_userdata = "echo foo bar"
additional_security_group_ids = [aws_security_group.worker_group_mgmt_two.id]
asg_desired_capacity = 1
},
]
}
eks_managed_node_groups = {
one = {
name = "node-group-1"

data "aws_eks_cluster" "cluster" {
name = module.eks.cluster_id
}
instance_types = ["t3.small"]

min_size = 1
max_size = 3
desired_size = 2

pre_bootstrap_user_data = <<-EOT
echo 'foo bar'
EOT

data "aws_eks_cluster_auth" "cluster" {
name = module.eks.cluster_id
vpc_security_group_ids = [
aws_security_group.node_group_one.id
]
}

two = {
name = "node-group-2"

instance_types = ["t3.medium"]

min_size = 1
max_size = 2
desired_size = 1

pre_bootstrap_user_data = <<-EOT
echo 'foo bar'
EOT

vpc_security_group_ids = [
aws_security_group.node_group_two.id
]
}
}
}
19 changes: 0 additions & 19 deletions kubernetes-dashboard-admin.rbac.yaml

This file was deleted.

22 changes: 17 additions & 5 deletions kubernetes.tf → main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# Kubernetes provider
# https://learn.hashicorp.com/terraform/kubernetes/provision-eks-cluster#optional-configure-terraform-kubernetes-provider
# To learn how to schedule deployments and services using the provider, go here: https://learn.hashicorp.com/terraform/kubernetes/deploy-nginx-kubernetes

# The Kubernetes provider is included in this file so the EKS module can complete successfully. Otherwise, it throws an error when creating `kubernetes_config_map.aws_auth`.
# You should **not** schedule deployments and services in this workspace. This keeps workspaces modular (one for provision EKS, another for scheduling Kubernetes resources) as per best practices.

provider "kubernetes" {
host = data.aws_eks_cluster.cluster.endpoint
token = data.aws_eks_cluster_auth.cluster.token
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
}

provider "aws" {
region = var.region
}

data "aws_availability_zones" "available" {}

locals {
cluster_name = "education-eks-${random_string.suffix.result}"
}

resource "random_string" "suffix" {
length = 8
special = false
}
16 changes: 3 additions & 13 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
output "cluster_id" {
description = "EKS cluster ID."
description = "EKS cluster ID"
value = module.eks.cluster_id
}

output "cluster_endpoint" {
description = "Endpoint for EKS control plane."
description = "Endpoint for EKS control plane"
value = module.eks.cluster_endpoint
}

output "cluster_security_group_id" {
description = "Security group ids attached to the cluster control plane."
description = "Security group ids attached to the cluster control plane"
value = module.eks.cluster_security_group_id
}

output "kubectl_config" {
description = "kubectl config as generated by the module."
value = module.eks.kubeconfig
}

output "config_map_aws_auth" {
description = "A kubernetes configuration to authenticate to this EKS cluster."
value = module.eks.config_map_aws_auth
}

output "region" {
description = "AWS region"
value = var.region
Expand Down
Loading