Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 14add7e

Browse files
author
Patrick Baxter
authored
Merge pull request #604 from pbx0/vpc
hack/terraform-quickstart: remove dependancy on default network
2 parents 769b540 + 4150401 commit 14add7e

File tree

4 files changed

+117
-6
lines changed

4 files changed

+117
-6
lines changed

hack/terraform-quickstart/main.tf

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ resource "aws_instance" "bootstrap_node" {
1010
key_name = "${var.ssh_key}"
1111
iam_instance_profile = "${aws_iam_instance_profile.bk_profile.id}"
1212

13+
vpc_security_group_ids = ["${aws_security_group.allow_all.id}"]
14+
subnet_id = "${aws_subnet.main.id}"
15+
associate_public_ip_address = true
16+
depends_on = ["aws_internet_gateway.main"]
17+
1318
tags {
14-
Name = "${var.instance_tags}"
19+
Name = "${var.resource_owner}"
1520
}
1621

1722
root_block_device {
@@ -27,8 +32,13 @@ resource "aws_instance" "worker_node" {
2732
count = "${var.num_workers}"
2833
iam_instance_profile = "${aws_iam_instance_profile.bk_profile.id}"
2934

35+
vpc_security_group_ids = ["${aws_security_group.allow_all.id}"]
36+
subnet_id = "${aws_subnet.main.id}"
37+
associate_public_ip_address = true
38+
depends_on = ["aws_internet_gateway.main"]
39+
3040
tags {
31-
Name = "${var.instance_tags}"
41+
Name = "${var.resource_owner}"
3242
}
3343

3444
root_block_device {
@@ -44,8 +54,13 @@ resource "aws_instance" "master_node" {
4454
count = "${var.additional_masters}"
4555
iam_instance_profile = "${aws_iam_instance_profile.bk_profile.id}"
4656

57+
vpc_security_group_ids = ["${aws_security_group.allow_all.id}"]
58+
subnet_id = "${aws_subnet.main.id}"
59+
associate_public_ip_address = true
60+
depends_on = ["aws_internet_gateway.main"]
61+
4762
tags {
48-
Name = "${var.instance_tags}"
63+
Name = "${var.resource_owner}"
4964
}
5065

5166
root_block_device {
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
resource "aws_vpc" "main" {
2+
cidr_block = "10.8.0.0/16"
3+
4+
tags {
5+
Name = "${var.resource_owner}"
6+
}
7+
}
8+
9+
data "aws_availability_zones" "available" {}
10+
11+
resource "aws_subnet" "main" {
12+
vpc_id = "${aws_vpc.main.id}"
13+
cidr_block = "10.8.0.0/24"
14+
availability_zone = "${data.aws_availability_zones.available.names[0]}"
15+
16+
tags {
17+
Name = "${var.resource_owner}"
18+
}
19+
}
20+
21+
resource "aws_internet_gateway" "main" {
22+
vpc_id = "${aws_vpc.main.id}"
23+
24+
tags {
25+
Name = "${var.resource_owner}"
26+
}
27+
}
28+
29+
resource "aws_route_table" "public" {
30+
vpc_id = "${aws_vpc.main.id}"
31+
32+
tags {
33+
Name = "${var.resource_owner}"
34+
}
35+
36+
route {
37+
cidr_block = "0.0.0.0/0"
38+
gateway_id = "${aws_internet_gateway.main.id}"
39+
}
40+
}
41+
42+
resource "aws_route_table_association" "main_subnet" {
43+
subnet_id = "${aws_subnet.main.id}"
44+
route_table_id = "${aws_route_table.public.id}"
45+
}
46+
47+
resource "aws_security_group" "allow_all" {
48+
name_prefix = "allow_all"
49+
description = "Allow all inbound traffic"
50+
vpc_id = "${aws_vpc.main.id}"
51+
52+
ingress {
53+
from_port = 0
54+
to_port = 0
55+
protocol = "-1"
56+
cidr_blocks = ["0.0.0.0/0"]
57+
}
58+
59+
egress {
60+
from_port = 0
61+
to_port = 0
62+
protocol = "-1"
63+
cidr_blocks = ["0.0.0.0/0"]
64+
}
65+
66+
tags {
67+
Name = "${var.resource_owner}"
68+
}
69+
}
70+
71+
resource "aws_network_acl" "all" {
72+
vpc_id = "${aws_vpc.main.id}"
73+
74+
egress {
75+
protocol = "-1"
76+
rule_no = 2
77+
action = "allow"
78+
cidr_block = "0.0.0.0/0"
79+
from_port = 0
80+
to_port = 0
81+
}
82+
83+
ingress {
84+
protocol = "-1"
85+
rule_no = 1
86+
action = "allow"
87+
cidr_block = "0.0.0.0/0"
88+
from_port = 0
89+
to_port = 0
90+
}
91+
92+
tags {
93+
Name = "${var.resource_owner}"
94+
}
95+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
access_key_id = ""
22
access_key = ""
3-
instance_tags = "bootkube_example_terraform"
3+
resource_owner = "bootkube_example_terraform"
44
ssh_key = ""
55

hack/terraform-quickstart/variables.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ variable "ssh_key" {
1111
type = "string"
1212
}
1313

14-
variable "instance_tags" {
15-
description = "Name all instances behind a single tag based on who/what is running terraform"
14+
variable "resource_owner" {
15+
description = "Tag all resources behind a single tag based on who/what is running terraform"
1616
type = "string"
17+
default = "bootkube-terraform-example-deleteme"
1718
}
1819

1920
variable "instance_type" {

0 commit comments

Comments
 (0)