This repository was archived by the owner on Jul 30, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +135
-0
lines changed
hack/terraform-quickstart Expand file tree Collapse file tree 6 files changed +135
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1+ access_key_id = ""
2+ access_key = ""
3+ instance_tags = "bootkube_example_terraform"
4+ ssh_key = ""
5+
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments