Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 05d307b

Browse files
authored
Merge pull request #39 from jetstack/terraform-eks-demo
Adds eks cluster modules
2 parents d6038de + b471f5e commit 05d307b

File tree

9 files changed

+203
-1
lines changed

9 files changed

+203
-1
lines changed

demo/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright Jetstack Ltd. See LICENSE for details.
22
BINDIR ?= $(CURDIR)/bin
3-
CLOUD := google
3+
CLOUD ?= google
44

55
KUBECONFIG := $(CURDIR)/.kubeconfig-$(CLOUD)
66

demo/infrastructure/amazon/dns.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module "dns" {
2+
source = "../modules/amazon-dns"
3+
suffix = "${random_id.suffix.hex}"
4+
region = "${var.region}"
5+
}

demo/infrastructure/amazon/ouputs.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
locals {
2+
config = {
3+
cert_manager = "${module.dns.config}"
4+
externaldns = "${module.dns.config}"
5+
gangway = "${module.gangway.config}"
6+
}
7+
}
8+
9+
output "config" {
10+
value = "${jsonencode(local.config)}"
11+
}
12+
13+
#output "kubeconfig_command" {
14+
# value = "eksctl utils write-kubeconfig --name=cluster-${random_id.suffix.hex} --kubeconfig=$KUBECONFIG --set-kubeconfig-context=true --region=${var.region} && cat infrastructure/amazon/aws-auth.yaml | sed -e \"s~{{ROLE_ARN}}~${module.cluster.cluster_node_arn}~g\" | kubectl apply -f -"
15+
#}
16+
17+
output "kubeconfig" {
18+
description = "kubectl config as generated by the module."
19+
value = "${module.cluster.kubeconfig}"
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
variable "region" {
2+
default = "eu-west-1"
3+
}
4+
5+
provider "aws" {
6+
region = "${var.region}"
7+
}
8+
9+
module "cluster" {
10+
source = "../modules/amazon-cluster"
11+
suffix = "${random_id.suffix.hex}"
12+
}

demo/infrastructure/amazon/secrets.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module "gangway" {
2+
source = "../modules/gangway"
3+
length = 24
4+
}

demo/infrastructure/amazon/suffix.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resource "random_id" "suffix" {
2+
byte_length = 4
3+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
variable "suffix" {}
2+
3+
data "aws_availability_zones" "available" {}
4+
5+
locals {
6+
cluster_name = "cluster-${var.suffix}"
7+
8+
worker_groups = [
9+
{
10+
instance_type = "t2.large"
11+
subnets = "${join(",", module.vpc.private_subnets)}"
12+
asg_desired_capacity = "2"
13+
},
14+
]
15+
tags = {
16+
Workspace = "${terraform.workspace}"
17+
}
18+
worker_groups_launch_template = [
19+
{
20+
# This will launch an autoscaling group with only Spot Fleet instances
21+
instance_type = "t2.small"
22+
additional_userdata = "echo foo bar"
23+
subnets = "${join(",", module.vpc.private_subnets)}"
24+
additional_security_group_ids = "${aws_security_group.worker_group_mgmt_one.id},${aws_security_group.worker_group_mgmt_two.id}"
25+
override_instance_type = "t3.small"
26+
asg_desired_capacity = "2"
27+
spot_instance_pools = 10
28+
on_demand_percentage_above_base_capacity = "0"
29+
},
30+
]
31+
}
32+
33+
resource "aws_security_group" "worker_group_mgmt_one" {
34+
name_prefix = "worker_group_mgmt_one"
35+
description = "SG to be applied to all *nix machines"
36+
vpc_id = "${module.vpc.vpc_id}"
37+
38+
ingress {
39+
from_port = 22
40+
to_port = 22
41+
protocol = "tcp"
42+
43+
cidr_blocks = [
44+
"10.0.0.0/8",
45+
]
46+
}
47+
}
48+
49+
resource "aws_security_group" "worker_group_mgmt_two" {
50+
name_prefix = "worker_group_mgmt_two"
51+
vpc_id = "${module.vpc.vpc_id}"
52+
53+
ingress {
54+
from_port = 22
55+
to_port = 22
56+
protocol = "tcp"
57+
58+
cidr_blocks = [
59+
"192.168.0.0/16",
60+
]
61+
}
62+
}
63+
64+
resource "aws_security_group" "all_worker_mgmt" {
65+
name_prefix = "all_worker_management"
66+
vpc_id = "${module.vpc.vpc_id}"
67+
68+
ingress {
69+
from_port = 22
70+
to_port = 22
71+
protocol = "tcp"
72+
73+
cidr_blocks = [
74+
"10.0.0.0/8",
75+
"172.16.0.0/12",
76+
"192.168.0.0/16",
77+
]
78+
}
79+
}
80+
81+
module "vpc" {
82+
source = "terraform-aws-modules/vpc/aws"
83+
version = "1.60.0"
84+
name = "test-vpc"
85+
cidr = "10.0.0.0/16"
86+
azs = ["${data.aws_availability_zones.available.names[0]}", "${data.aws_availability_zones.available.names[1]}", "${data.aws_availability_zones.available.names[2]}"]
87+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
88+
public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
89+
enable_nat_gateway = true
90+
single_nat_gateway = true
91+
tags = "${merge(local.tags, map("kubernetes.io/cluster/${local.cluster_name}", "shared"))}"
92+
}
93+
94+
module "eks" {
95+
source = "terraform-aws-modules/eks/aws"
96+
cluster_name = "${local.cluster_name}"
97+
subnets = ["${module.vpc.private_subnets}"]
98+
tags = "${local.tags}"
99+
vpc_id = "${module.vpc.vpc_id}"
100+
worker_groups = "${local.worker_groups}"
101+
worker_groups_launch_template = "${local.worker_groups_launch_template}"
102+
worker_group_count = "1"
103+
worker_group_launch_template_count = "1"
104+
worker_additional_security_group_ids = ["${aws_security_group.all_worker_mgmt.id}"]
105+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "cluster_node_arn" {
2+
value = "${module.eks.worker_iam_role_arn}"
3+
}
4+
5+
output "kubeconfig" {
6+
value = "${module.eks.kubeconfig}"
7+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
variable "suffix" {}
2+
variable "region" {}
3+
4+
resource "aws_iam_user" "dns" {
5+
name = "cluster-dns-${var.suffix}"
6+
path = "/"
7+
}
8+
9+
resource "aws_iam_access_key" "dns" {
10+
user = "${aws_iam_user.dns.name}"
11+
}
12+
13+
resource "aws_iam_user_policy" "dns" {
14+
name = "cluster-dns-${var.suffix}"
15+
user = "${aws_iam_user.dns.name}"
16+
17+
policy = <<EOF
18+
{
19+
"Version": "2012-10-17",
20+
"Statement": [
21+
{
22+
"Effect": "Allow",
23+
"Action": [
24+
"route53:GetHostedZone",
25+
"route53:ListHostedZones",
26+
"route53:ListHostedZonesByName",
27+
"route53:GetHostedZoneCount",
28+
"route53:ChangeResourceRecordSets",
29+
"route53:ListResourceRecordSets",
30+
"route53:GetChange"
31+
],
32+
"Resource": "*"
33+
}
34+
]
35+
}
36+
EOF
37+
}
38+
39+
40+
output "config" {
41+
value = {
42+
service_account_credentials = "${aws_iam_access_key.dns.id}"
43+
provider = "route53"
44+
region = "${var.region}"
45+
}
46+
}

0 commit comments

Comments
 (0)