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

Commit 71f0f71

Browse files
author
Patrick Baxter
authored
Merge pull request #489 from pbx0/terraform-with-scripts
hack/terraform-quickstart: initial commit
2 parents 508d4e3 + db9f40e commit 71f0f71

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Terraform-quickstart
2+
This directory provides a basic way to use terraform to setup compute resources on AWS. It was written with testing in mind.
3+
4+
Prerequisites:
5+
- terraform
6+
- bootkube binary built from the repo root
7+
8+
To start a cluster first fill out the terraform.tfvars.example with the needed secrets and rename it to terraform.tfvars. Then:
9+
10+
```
11+
terraform plan
12+
terraform apply
13+
./start-cluster.sh
14+
```
15+
16+
To destroy a cluster:
17+
18+
```
19+
terraform destroy
20+
```

hack/terraform-quickstart/main.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
provider "aws" {
2+
access_key = "${var.access_key_id}"
3+
secret_key = "${var.access_key}"
4+
region = "${var.region}"
5+
}
6+
7+
resource "aws_instance" "bootstrap_node" {
8+
ami = "${data.aws_ami.coreos_ami.image_id}"
9+
instance_type = "m3.medium"
10+
key_name = "${var.ssh_key}"
11+
12+
tags {
13+
Name = "${var.instance_tags}"
14+
}
15+
}
16+
17+
resource "aws_instance" "worker_node" {
18+
ami = "${data.aws_ami.coreos_ami.image_id}"
19+
instance_type = "m3.medium"
20+
key_name = "${var.ssh_key}"
21+
count = "${var.num_workers}"
22+
23+
tags {
24+
Name = "${var.instance_tags}"
25+
}
26+
}
27+
28+
data "aws_ami" "coreos_ami" {
29+
most_recent = true
30+
31+
filter {
32+
name = "name"
33+
values = ["CoreOS-stable-*"]
34+
}
35+
36+
filter {
37+
name = "architecture"
38+
values = ["x86_64"]
39+
}
40+
41+
filter {
42+
name = "virtualization-type"
43+
values = ["hvm"]
44+
}
45+
46+
filter {
47+
name = "owner-id"
48+
values = ["595879546273"]
49+
}
50+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
output "bootstrap_node_ip" {
2+
value = "${aws_instance.bootstrap_node.public_ip}"
3+
}
4+
5+
output "worker_ips" {
6+
value = ["${aws_instance.worker_node.*.public_ip}"]
7+
}
8+
9+
output "self_host_etcd" {
10+
value = "${var.self_host_etcd}"
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
export BOOTSTRAP_IP=`terraform output bootstrap_node_ip`
5+
export WORKER_IPS=`terraform output -json worker_ips | jq -r '.value[]'`
6+
export SELF_HOST_ETCD=`terraform output self_host_etcd`
7+
export SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
8+
9+
cd ../quickstart
10+
./init-master.sh $BOOTSTRAP_IP
11+
12+
for IP in $WORKER_IPS
13+
do
14+
./init-worker.sh $IP cluster/auth/kubeconfig
15+
done
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
access_key_id = ""
2+
access_key = ""
3+
instance_tags = "bootkube_example_terraform"
4+
ssh_key = ""
5+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
variable "access_key_id" {
2+
type = "string"
3+
}
4+
5+
variable "access_key" {
6+
type = "string"
7+
}
8+
9+
variable "ssh_key" {
10+
description = "aws ssh key"
11+
type = "string"
12+
}
13+
14+
variable "instance_tags" {
15+
description = "Name all instances behind a single tag based on who/what is running terraform"
16+
type = "string"
17+
}
18+
19+
variable "self_host_etcd" {
20+
type = "string"
21+
default = "true"
22+
}
23+
24+
variable "num_workers" {
25+
description = "number of worker nodes"
26+
type = "string"
27+
default = "1"
28+
}
29+
30+
variable "region" {
31+
description = "aws region"
32+
type = "string"
33+
default = "us-east-1"
34+
}

0 commit comments

Comments
 (0)