diff --git a/README.md b/README.md index ad09b20b..799dbad6 100644 --- a/README.md +++ b/README.md @@ -14,31 +14,38 @@ Read the [AWS docs on EKS to get connected to the k8s dashboard](https://docs.aw * You want to create an EKS cluster and an autoscaling group of workers for the cluster. * You want these resources to exist within security groups that allow communication and coordination. These can be user provided or created within the module. * You've created a Virtual Private Cloud (VPC) and subnets where you intend to put the EKS resources. The VPC satisfies [EKS requirements](https://docs.aws.amazon.com/eks/latest/userguide/network_reqs.html). -* If `manage_aws_auth = true`, it's required that both [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl) (>=1.10) and [`aws-iam-authenticator`](https://github.com/kubernetes-sigs/aws-iam-authenticator#4-set-up-kubectl-to-use-authentication-tokens-provided-by-aws-iam-authenticator-for-kubernetes) are installed and on your shell's PATH. ## Usage example A full example leveraging other community modules is contained in the [examples/basic directory](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/basic). ```hcl +variable "create_eks" { + default = true + description = "Set to false to skip creating EKS cluster (Useful for multi-workspace, .tfvars based project layouts)." +} + data "aws_eks_cluster" "cluster" { - name = module.eks.cluster_id + count = var.create_eks ? 1 : 0 + name = module.eks.cluster_id } data "aws_eks_cluster_auth" "cluster" { - name = module.eks.cluster_id + count = var.create_eks ? 1 : 0 + 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) - token = data.aws_eks_cluster_auth.cluster.token + host = element(concat(data.aws_eks_cluster.cluster[*].endpoint, list("")), 0) + cluster_ca_certificate = base64decode(element(concat(data.aws_eks_cluster.cluster[*].certificate_authority.0.data, list("")), 0)) + token = element(concat(data.aws_eks_cluster_auth.cluster[*].token, list("")), 0) load_config_file = false - version = "~> 1.9" + version = "~> 1.10" } module "my-cluster" { source = "terraform-aws-modules/eks/aws" + create_eks = var.create_eks cluster_name = "my-cluster" cluster_version = "1.14" subnets = ["subnet-abcde012", "subnet-bcde012a", "subnet-fghi345a"] diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 05b36f6a..966e7fae 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -24,17 +24,19 @@ provider "template" { } data "aws_eks_cluster" "cluster" { - name = module.eks.cluster_id + count = var.create_eks ? 1 : 0 + name = module.eks.cluster_id } data "aws_eks_cluster_auth" "cluster" { - name = module.eks.cluster_id + count = var.create_eks ? 1 : 0 + 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) - token = data.aws_eks_cluster_auth.cluster.token + host = element(concat(data.aws_eks_cluster.cluster[*].endpoint, list("")), 0) + cluster_ca_certificate = base64decode(element(concat(data.aws_eks_cluster.cluster[*].certificate_authority.0.data, list("")), 0)) + token = element(concat(data.aws_eks_cluster_auth.cluster[*].token, list("")), 0) load_config_file = false version = "~> 1.10" } @@ -128,6 +130,7 @@ module "vpc" { module "eks" { source = "../.." + create_eks = var.create_eks cluster_name = local.cluster_name subnets = module.vpc.private_subnets diff --git a/examples/basic/variables.tf b/examples/basic/variables.tf index 7085aeab..77d74b06 100644 --- a/examples/basic/variables.tf +++ b/examples/basic/variables.tf @@ -2,6 +2,11 @@ variable "region" { default = "us-west-2" } +variable "create_eks" { + default = true + description = "Set to false to skip creating EKS cluster." +} + variable "map_accounts" { description = "Additional AWS account numbers to add to the aws-auth configmap." type = list(string) diff --git a/examples/launch_templates/main.tf b/examples/launch_templates/main.tf index 1c95a9fd..12bf7cd8 100644 --- a/examples/launch_templates/main.tf +++ b/examples/launch_templates/main.tf @@ -24,17 +24,19 @@ provider "template" { } data "aws_eks_cluster" "cluster" { - name = module.eks.cluster_id + count = var.create_eks ? 1 : 0 + name = module.eks.cluster_id } data "aws_eks_cluster_auth" "cluster" { - name = module.eks.cluster_id + count = var.create_eks ? 1 : 0 + 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) - token = data.aws_eks_cluster_auth.cluster.token + host = element(concat(data.aws_eks_cluster.cluster[*].endpoint, list("")), 0) + cluster_ca_certificate = base64decode(element(concat(data.aws_eks_cluster.cluster[*].certificate_authority.0.data, list("")), 0)) + token = element(concat(data.aws_eks_cluster_auth.cluster[*].token, list("")), 0) load_config_file = false version = "~> 1.10" } @@ -68,6 +70,7 @@ module "vpc" { module "eks" { source = "../.." + create_eks = var.create_eks cluster_name = local.cluster_name subnets = module.vpc.public_subnets vpc_id = module.vpc.vpc_id diff --git a/examples/launch_templates/variables.tf b/examples/launch_templates/variables.tf index f69e5002..b0454a66 100644 --- a/examples/launch_templates/variables.tf +++ b/examples/launch_templates/variables.tf @@ -2,3 +2,7 @@ variable "region" { default = "us-west-2" } +variable "create_eks" { + default = true + description = "Set to false to skip creating EKS cluster." +} diff --git a/examples/spot_instances/main.tf b/examples/spot_instances/main.tf index 8382d14c..2ef207f9 100644 --- a/examples/spot_instances/main.tf +++ b/examples/spot_instances/main.tf @@ -24,17 +24,19 @@ provider "template" { } data "aws_eks_cluster" "cluster" { - name = module.eks.cluster_id + count = var.create_eks ? 1 : 0 + name = module.eks.cluster_id } data "aws_eks_cluster_auth" "cluster" { - name = module.eks.cluster_id + count = var.create_eks ? 1 : 0 + 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) - token = data.aws_eks_cluster_auth.cluster.token + host = element(concat(data.aws_eks_cluster.cluster[*].endpoint, list("")), 0) + cluster_ca_certificate = base64decode(element(concat(data.aws_eks_cluster.cluster[*].certificate_authority.0.data, list("")), 0)) + token = element(concat(data.aws_eks_cluster_auth.cluster[*].token, list("")), 0) load_config_file = false version = "~> 1.10" } @@ -68,6 +70,7 @@ module "vpc" { module "eks" { source = "../.." + create_eks = var.create_eks cluster_name = local.cluster_name subnets = module.vpc.public_subnets vpc_id = module.vpc.vpc_id diff --git a/examples/spot_instances/variables.tf b/examples/spot_instances/variables.tf index f69e5002..b0454a66 100644 --- a/examples/spot_instances/variables.tf +++ b/examples/spot_instances/variables.tf @@ -2,3 +2,7 @@ variable "region" { default = "us-west-2" } +variable "create_eks" { + default = true + description = "Set to false to skip creating EKS cluster." +}