Skip to content

Commit 805e443

Browse files
committed
WIP: build aws components, ignition not complete yet
1 parent ce526e9 commit 805e443

29 files changed

+904
-151
lines changed

aws/bastion.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
The bastion instance is used only for debugging during development.
3+
This file should be removed once the templates are stable and working correctly.
4+
*/
5+
resource "aws_security_group" "bastion_sec_group" {
6+
vpc_id = "${data.aws_vpc.cluster_vpc.id}"
7+
8+
ingress {
9+
protocol = "tcp"
10+
cidr_blocks = ["0.0.0.0/0"]
11+
from_port = 22
12+
to_port = 22
13+
}
14+
15+
egress {
16+
from_port = 0
17+
to_port = 0
18+
protocol = "-1"
19+
self = true
20+
cidr_blocks = ["0.0.0.0/0"]
21+
}
22+
}
23+
24+
resource "ignition_config" "bastion" {
25+
files = [
26+
"${ignition_file.etcd-endpoints.id}",
27+
]
28+
}
29+
30+
resource "aws_instance" "bastion_node" {
31+
ami = "${data.aws_ami.coreos_ami.image_id}"
32+
instance_type = "t2.small"
33+
subnet_id = "${aws_subnet.az_subnet_pub.0.id}"
34+
key_name = "${aws_key_pair.ssh-key.key_name}"
35+
vpc_security_group_ids = ["${aws_security_group.bastion_sec_group.id}"]
36+
user_data = "${ignition_config.bastion.rendered}"
37+
associate_public_ip_address = true
38+
39+
tags {
40+
Name = "bastion"
41+
}
42+
}

aws/dns.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resource "aws_route53_zone" "tectonic-int" {
2+
vpc_id = "${data.aws_vpc.cluster_vpc.id}"
3+
name = "${var.tectonic_domain}"
4+
}
5+
6+
resource "aws_route53_zone" "tectonic-ext" {
7+
name = "${var.tectonic_domain}"
8+
}

aws/elb.tf

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
resource "aws_elb" "api-internal" {
2+
name = "${var.cluster_name}-api-internal"
3+
subnets = ["${aws_subnet.master_subnet.*.id}"]
4+
internal = true
5+
6+
listener {
7+
instance_port = 443
8+
instance_protocol = "tcp"
9+
lb_port = 443
10+
lb_protocol = "tcp"
11+
}
12+
13+
listener {
14+
instance_port = 10255
15+
instance_protocol = "tcp"
16+
lb_port = 10255
17+
lb_protocol = "tcp"
18+
}
19+
}
20+
21+
resource "aws_elb" "api-external" {
22+
name = "${var.cluster_name}-api-external"
23+
subnets = ["${aws_subnet.az_subnet_pub.*.id}"]
24+
internal = false
25+
26+
listener {
27+
instance_port = 443
28+
instance_protocol = "tcp"
29+
lb_port = 443
30+
lb_protocol = "tcp"
31+
}
32+
}
33+
34+
resource "aws_route53_record" "api-internal" {
35+
zone_id = "${aws_route53_zone.tectonic-int.zone_id}"
36+
name = "${var.cluster_name}-k8s.${var.tectonic_domain}"
37+
type = "A"
38+
39+
alias {
40+
name = "${aws_elb.api-internal.dns_name}"
41+
zone_id = "${aws_elb.api-internal.zone_id}"
42+
evaluate_target_health = true
43+
}
44+
}
45+
46+
resource "aws_route53_record" "api-external" {
47+
zone_id = "${aws_route53_zone.tectonic-ext.zone_id}"
48+
name = "${var.cluster_name}-k8s.${var.tectonic_domain}"
49+
type = "A"
50+
51+
alias {
52+
name = "${aws_elb.api-internal.dns_name}"
53+
zone_id = "${aws_elb.api-internal.zone_id}"
54+
evaluate_target_health = true
55+
}
56+
}

aws/etcd/cloudconfig.tf

Lines changed: 0 additions & 9 deletions
This file was deleted.

aws/etcd/dns.tf

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
resource "aws_route53_zone" etcd_zone {
2-
vpc_id = "${data.aws_vpc.etcd_vpc.id}"
3-
name = "${var.etcd_domain}"
4-
}
5-
61
resource "aws_route53_record" "etcd_srv_discover" {
72
name = "_etcd-server._tcp"
83
type = "SRV"
9-
zone_id = "${aws_route53_zone.etcd_zone.id}"
4+
zone_id = "${var.dns_zone}"
105
records = ["${formatlist("0 0 2380 %s", aws_route53_record.etc_a_nodes.*.fqdn)}"]
116
ttl = "300"
127
}
138

149
resource "aws_route53_record" "etcd_srv_client" {
1510
name = "_etcd-client._tcp"
1611
type = "SRV"
17-
zone_id = "${aws_route53_zone.etcd_zone.id}"
12+
zone_id = "${var.dns_zone}"
1813
records = ["${formatlist("0 0 2379 %s", aws_route53_record.etc_a_nodes.*.fqdn)}"]
1914
ttl = "60"
2015
}
@@ -23,7 +18,7 @@ resource "aws_route53_record" "etc_a_nodes" {
2318
count = "${var.node_count}"
2419
type = "A"
2520
ttl = "60"
26-
zone_id = "${aws_route53_zone.etcd_zone.id}"
27-
name = "node-${count.index}"
21+
zone_id = "${var.dns_zone}"
22+
name = "etcd-${count.index}"
2823
records = ["${aws_instance.etcd_node.*.private_ip[count.index]}"]
2924
}

aws/etcd/network.tf

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
data "aws_vpc" "etcd_vpc" {
2-
id = "${var.vpc_id}"
3-
}
4-
5-
data "aws_subnet" "az_subnet" {
6-
count = "${var.node_count}"
7-
vpc_id = "${data.aws_vpc.etcd_vpc.id}"
8-
9-
filter = {
10-
name = "availabilityZone"
11-
values = ["${data.aws_availability_zones.zones.names[count.index]}"]
12-
}
13-
}
14-
15-
resource "aws_default_security_group" "default_sec_group" {
16-
vpc_id = "${data.aws_vpc.etcd_vpc.id}"
1+
resource "aws_security_group" "etcd_sec_group" {
2+
vpc_id = "${var.vpc_id}"
173

184
ingress {
195
protocol = -1
@@ -29,6 +15,13 @@ resource "aws_default_security_group" "default_sec_group" {
2915
to_port = 22
3016
}
3117

18+
ingress {
19+
protocol = "tcp"
20+
cidr_blocks = ["0.0.0.0/0"]
21+
from_port = 2379
22+
to_port = 2379
23+
}
24+
3225
egress {
3326
from_port = 0
3427
to_port = 0

aws/etcd/nodes.tf

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,23 @@
1-
data "aws_availability_zones" "zones" {}
1+
data "template_file" "userdata" {
2+
count = "${var.node_count}"
3+
template = "${file("${path.module}/userdata.yml")}"
24

3-
data "aws_ami" "coreos_ami" {
4-
most_recent = true
5-
6-
filter {
7-
name = "name"
8-
values = ["CoreOS-stable-*"]
9-
}
10-
11-
filter {
12-
name = "architecture"
13-
values = ["x86_64"]
14-
}
15-
16-
filter {
17-
name = "virtualization-type"
18-
values = ["hvm"]
19-
}
20-
21-
filter {
22-
name = "owner-id"
23-
values = ["595879546273"]
5+
vars {
6+
node_name = "etcd-${count.index}.${var.tectonic_domain}"
7+
etcd_domain = "${var.tectonic_domain}"
248
}
259
}
2610

2711
resource "aws_instance" "etcd_node" {
28-
count = "${var.node_count}"
29-
ami = "${data.aws_ami.coreos_ami.id}"
30-
instance_type = "t2.medium"
31-
subnet_id = "${data.aws_subnet.az_subnet.*.id[count.index]}"
32-
key_name = "${aws_key_pair.ssh-key.id}"
33-
user_data = "${data.template_file.userdata.*.rendered[count.index]}"
12+
count = "${var.node_count}"
13+
ami = "${var.coreos_ami}"
14+
instance_type = "t2.medium"
15+
subnet_id = "${var.etcd_subnets[count.index]}"
16+
key_name = "${var.ssh_key}"
17+
user_data = "${data.template_file.userdata.*.rendered[count.index]}"
18+
vpc_security_group_ids = ["${aws_security_group.etcd_sec_group.id}"]
3419

3520
tags {
36-
Name = "node-${count.index}"
21+
Name = "etcd-${count.index}"
3722
}
3823
}

aws/etcd/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
output "endpoints" {
2-
value = "${join(",",formatlist("http://%s:2379",aws_route53_record.etc_a_nodes.*.fqdn))}"
2+
value = "${formatlist("http://%s:2379",aws_route53_record.etc_a_nodes.*.fqdn)}"
33
}

aws/etcd/userdata.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.

aws/etcd/userdata.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#cloud-config
2+
3+
hostname: ${node_name}
4+
5+
coreos:
6+
update:
7+
reboot-strategy: "etcd-lock"
8+
units:
9+
- name: "etcd2.service"
10+
enable: false
11+
- name: "etcd.service"
12+
enable: false
13+
- name: "etcd-member.service"
14+
enable: true
15+
command: "start"
16+
drop-ins:
17+
- name: "40-etcd-cluster.conf"
18+
content: |
19+
[Service]
20+
Environment="ETCD_IMAGE_TAG=v3.1.1"
21+
ExecStart=
22+
ExecStart=/usr/lib/coreos/etcd-wrapper \
23+
--name=etcd \
24+
--discovery-srv=${etcd_domain} \
25+
--advertise-client-urls=http://${node_name}:2379 \
26+
--initial-advertise-peer-urls=http://${node_name}:2380 \
27+
--listen-client-urls=http://0.0.0.0:2379 \
28+
--listen-peer-urls=http://$private_ipv4:2380

aws/etcd/variables.tf

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
variable "etcd_domain" {
1+
variable "tectonic_domain" {
2+
type = "string"
3+
}
4+
5+
variable "dns_zone" {
26
type = "string"
37
}
48

@@ -9,3 +13,15 @@ variable "node_count" {
913
variable "vpc_id" {
1014
type = "string"
1115
}
16+
17+
variable "ssh_key" {
18+
type = "string"
19+
}
20+
21+
variable "coreos_ami" {
22+
type = "string"
23+
}
24+
25+
variable "etcd_subnets" {
26+
type = "list"
27+
}

aws/main.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
data "aws_availability_zones" "azs" {}
2+
3+
data "aws_ami" "coreos_ami" {
4+
most_recent = true
5+
6+
filter {
7+
name = "name"
8+
values = ["CoreOS-stable-*"]
9+
}
10+
11+
filter {
12+
name = "architecture"
13+
values = ["x86_64"]
14+
}
15+
16+
filter {
17+
name = "virtualization-type"
18+
values = ["hvm"]
19+
}
20+
21+
filter {
22+
name = "owner-id"
23+
values = ["595879546273"]
24+
}
25+
}
26+
27+
module "vpc" {
28+
source = "./vpc"
29+
external_vpc_id = "${var.external_vpc_id}"
30+
vpc_cid_block = "${var.vpc_cid_block}"
31+
}
32+
33+
data "aws_vpc" "cluster_vpc" {
34+
id = "${module.vpc.vpc_id}"
35+
}
36+
37+
module "etcd" {
38+
source = "./etcd"
39+
40+
vpc_id = "${data.aws_vpc.cluster_vpc.id}"
41+
node_count = "${var.az_count}"
42+
ssh_key = "${aws_key_pair.ssh-key.id}"
43+
dns_zone = "${aws_route53_zone.tectonic-int.zone_id}"
44+
coreos_ami = "${data.aws_ami.coreos_ami.id}"
45+
etcd_subnets = ["${aws_subnet.etcd_subnet.*.id}"]
46+
tectonic_domain = "${var.tectonic_domain}"
47+
}

0 commit comments

Comments
 (0)