From 1feb938dc5e30aedac978b3bd83f459c7f339776 Mon Sep 17 00:00:00 2001 From: Ed Robinson Date: Thu, 19 Mar 2020 13:53:14 +0000 Subject: [PATCH] Cleanup the cluster example --- README.md | 2 ++ examples/cluster/environment.tf | 44 ++++++++++++++++++++++++++++ examples/cluster/main.tf | 51 ++------------------------------- 3 files changed, 48 insertions(+), 49 deletions(-) create mode 100644 examples/cluster/environment.tf diff --git a/README.md b/README.md index 3090ab7e..db81054a 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ module "eks" { For more advanced uses, we recommend that you construct and configure your clusters using the modules contained within the [`modules`](./modules) folder. +[see example](./examples/cluster) + This allows for much more flexibility, in order to for example: * Provision a cluster in an existing VPC. diff --git a/examples/cluster/environment.tf b/examples/cluster/environment.tf new file mode 100644 index 00000000..d5b95532 --- /dev/null +++ b/examples/cluster/environment.tf @@ -0,0 +1,44 @@ +# In the test we provision the network and IAM resources using the environment +# module, we then lookup the relevant config here! +# This is in order to simulate launching a cluster in an existing VPC! + +locals { + availability_zones = toset(["us-east-1a", "us-east-1b", "us-east-1c"]) + vpc_config = { + vpc_id = data.aws_vpc.network.id + public_subnet_ids = { for subnet in data.aws_subnet.public : subnet.availability_zone => subnet.id } + private_subnet_ids = { for subnet in data.aws_subnet.private : subnet.availability_zone => subnet.id } + } + + iam_config = { + service_role = "eksServiceRole-${var.cluster_name}" + node_role = "EKSNode-${var.cluster_name}" + admin_role = "EKSAdmin-${var.cluster_name}" + } +} + +data "aws_vpc" "network" { + tags = { + Name = var.cluster_name + } +} + +data "aws_subnet" "public" { + for_each = local.availability_zones + + availability_zone = each.value + vpc_id = data.aws_vpc.network.id + tags = { + Name = "${var.cluster_name}-public-${each.value}" + } +} + +data "aws_subnet" "private" { + for_each = local.availability_zones + + availability_zone = each.value + vpc_id = data.aws_vpc.network.id + tags = { + Name = "${var.cluster_name}-private-${each.value}" + } +} diff --git a/examples/cluster/main.tf b/examples/cluster/main.tf index f93ee690..d6672102 100644 --- a/examples/cluster/main.tf +++ b/examples/cluster/main.tf @@ -3,60 +3,13 @@ provider "aws" { version = "2.52.0" } -data "aws_vpc" "network" { - tags = { - Name = var.cluster_name - } -} - -locals { - availability_zones = toset(["us-east-1a", "us-east-1b", "us-east-1c"]) -} - -data "aws_subnet" "public" { - for_each = local.availability_zones - - availability_zone = each.value - vpc_id = data.aws_vpc.network.id - tags = { - Name = "${var.cluster_name}-public-${each.value}" - } -} - -data "aws_subnet" "private" { - for_each = local.availability_zones - - availability_zone = each.value - vpc_id = data.aws_vpc.network.id - tags = { - Name = "${var.cluster_name}-private-${each.value}" - } -} - module "cluster" { source = "../../modules/cluster" name = var.cluster_name - vpc_config = { - vpc_id = data.aws_vpc.network.id - public_subnet_ids = { - us-east-1a = data.aws_subnet.public["us-east-1a"].id - us-east-1b = data.aws_subnet.public["us-east-1b"].id - us-east-1c = data.aws_subnet.public["us-east-1c"].id - } - private_subnet_ids = { - us-east-1a = data.aws_subnet.private["us-east-1a"].id - us-east-1b = data.aws_subnet.private["us-east-1b"].id - us-east-1c = data.aws_subnet.private["us-east-1c"].id - } - } - - iam_config = { - service_role = "eksServiceRole-${var.cluster_name}" - node_role = "EKSNode-${var.cluster_name}" - admin_role = "EKSAdmin-${var.cluster_name}" - } + vpc_config = local.vpc_config + iam_config = local.iam_config aws_auth_role_map = [ {