Skip to content

Instantly share code, notes, and snippets.

@ahamez
Created March 8, 2021 11:04
Show Gist options
  • Save ahamez/0d5b2d75a471a81fa6003c4822fa302c to your computer and use it in GitHub Desktop.
Save ahamez/0d5b2d75a471a81fa6003c4822fa302c to your computer and use it in GitHub Desktop.
# ---------------------------------------------------------------------------------------------------
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.31.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0.1"
}
}
required_version = "~> 0.14"
}
# ---------------------------------------------------------------------------------------------------
provider "aws" {
region = "eu-west-3"
assume_role {
role_arn = "arn:aws:iam::BBBBBBBB:role/terraform-deployer.role"
}
}
data "aws_availability_zones" "available" {}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.77.0"
name = "foo-vpc"
cidr = "10.0.0.0/16"
azs = data.aws_availability_zones.available.names
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
tags = {
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
}
public_subnet_tags = {
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
"kubernetes.io/role/elb" = "1"
}
private_subnet_tags = {
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
"kubernetes.io/role/internal-elb" = "1"
}
}
# ---------------------------------------------------------------------------------------------------
locals {
cluster_name = "foo"
}
# ---------------------------------------------------------------------------------------------------
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "14.0.0"
cluster_name = local.cluster_name
cluster_version = "1.19"
subnets = module.vpc.private_subnets
vpc_id = module.vpc.vpc_id
workers_group_defaults = {
root_volume_type = "gp2"
}
worker_groups = [
]
}
# ---------------------------------------------------------------------------------------------------
data "aws_eks_cluster" "cluster" {
name = module.eks.cluster_id
}
data "aws_eks_cluster_auth" "cluster" {
name = module.eks.cluster_id
}
provider "kubernetes" {
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
command = "aws"
args = [
"eks",
"get-token",
"--cluster-name",
data.aws_eks_cluster.cluster.name
]
}
}
output "kubeconfig" {
value = module.eks.kubeconfig
}
output "kubeconfig_filename" {
value = module.eks.kubeconfig_filename
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment