Skip to content

Commit

Permalink
Cleanup the cluster example
Browse files Browse the repository at this point in the history
  • Loading branch information
errm committed Mar 19, 2020
1 parent 1258657 commit 1feb938
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 49 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
44 changes: 44 additions & 0 deletions examples/cluster/environment.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
}
51 changes: 2 additions & 49 deletions examples/cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down

0 comments on commit 1feb938

Please sign in to comment.