-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from mcapuccini/feature/aws_bootstrap
add AWS support. Thanks @andersla !
- Loading branch information
Showing
10 changed files
with
532 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
variable name_prefix {} | ||
variable kubenow_image_id {} | ||
variable instance_type {} | ||
variable kubeadm_token {} | ||
variable disk_size {} | ||
variable availability_zone {} | ||
variable ssh_user {} | ||
variable ssh_keypair_name {} | ||
variable master_ip {} | ||
variable subnet_id {} | ||
variable count {} | ||
variable security_group_id {} | ||
|
||
# create bootstrap script file from template | ||
resource "template_file" "edge_bootstrap" { | ||
template = "${file("${path.root}/../bootstrap/node.sh")}" | ||
vars { | ||
kubeadm_token = "${var.kubeadm_token}" | ||
master_ip = "${var.master_ip}" | ||
} | ||
} | ||
|
||
resource "aws_instance" "edge" { | ||
count = "${var.count}" | ||
ami = "${var.kubenow_image_id}" | ||
availability_zone = "${var.availability_zone}" | ||
instance_type = "${var.instance_type}" | ||
associate_public_ip_address = true | ||
key_name = "${var.ssh_keypair_name}" | ||
vpc_security_group_ids = ["${var.security_group_id}"] | ||
subnet_id = "${var.subnet_id}" | ||
user_data = "${template_file.edge_bootstrap.rendered}" | ||
|
||
root_block_device { | ||
delete_on_termination = true | ||
volume_size = "${var.disk_size}" | ||
} | ||
|
||
tags { | ||
Name = "${var.name_prefix}-edge-${format("%03d", count.index)}" | ||
sshUser = "${var.ssh_user}" | ||
} | ||
} | ||
|
||
# Generate ansible inventory | ||
resource "null_resource" "generate-inventory" { | ||
|
||
provisioner "local-exec" { | ||
command = "echo \"[edge]\" >> inventory" | ||
} | ||
|
||
provisioner "local-exec" { | ||
command = "echo \"${join("\n",formatlist("%s ansible_ssh_host=%s ansible_ssh_user=ubuntu", aws_instance.edge.*.tags.Name, aws_instance.edge.*.public_ip))}\" >> inventory" | ||
} | ||
|
||
provisioner "local-exec" { | ||
command = "echo \"[master:vars]\" >> inventory" | ||
} | ||
|
||
provisioner "local-exec" { | ||
# generates aws hostnames (ip-000-111-222-333) from ip-numbers | ||
command = "echo 'edge_names=\"${replace(join(" ",formatlist("ip-%s", aws_instance.edge.*.private_ip)),".","-")}\"' >> inventory" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Cluster settings | ||
variable cluster_prefix {} | ||
variable kubenow_image_id {} | ||
variable kubeadm_token {} | ||
|
||
variable aws_access_key_id {} | ||
variable aws_secret_access_key {} | ||
variable aws_region {} | ||
variable availability_zone {} | ||
|
||
variable ssh_user { default = "ubuntu" } | ||
variable ssh_keypair_name {} | ||
|
||
# Master settings | ||
variable master_instance_type {} | ||
variable master_disk_size {} | ||
|
||
# Nodes settings | ||
variable node_count {} | ||
variable node_instance_type {} | ||
variable node_disk_size {} | ||
|
||
# Edges settings | ||
variable edge_count {} | ||
variable edge_instance_type {} | ||
variable edge_disk_size {} | ||
|
||
# Provider | ||
provider "aws" { | ||
access_key = "${var.aws_access_key_id}" | ||
secret_key = "${var.aws_secret_access_key}" | ||
region = "${var.aws_region}" | ||
} | ||
|
||
# VPC Virtual Private Cloud - Networking | ||
module "vpc" { | ||
source = "./vpc" | ||
name_prefix = "${var.cluster_prefix}" | ||
availability_zone = "${var.availability_zone}" | ||
} | ||
|
||
module "master" { | ||
source = "./master" | ||
name_prefix = "${var.cluster_prefix}" | ||
kubenow_image_id = "${var.kubenow_image_id}" | ||
instance_type = "${var.master_instance_type}" | ||
subnet_id = "${module.vpc.subnet_id}" | ||
security_group_id = "${module.vpc.security_group_id}" | ||
kubeadm_token = "${var.kubeadm_token}" | ||
availability_zone = "${var.availability_zone}" | ||
ssh_user = "${var.ssh_user}" | ||
ssh_keypair_name = "${var.ssh_keypair_name}" | ||
disk_size = "${var.master_disk_size}" | ||
} | ||
|
||
module "node" { | ||
source = "./node" | ||
name_prefix = "${var.cluster_prefix}" | ||
kubenow_image_id = "${var.kubenow_image_id}" | ||
instance_type = "${var.node_instance_type}" | ||
subnet_id = "${module.vpc.subnet_id}" | ||
security_group_id = "${module.vpc.security_group_id}" | ||
kubeadm_token = "${var.kubeadm_token}" | ||
master_ip = "${module.master.ip_address_internal}" | ||
count = "${var.node_count}" | ||
availability_zone = "${var.availability_zone}" | ||
ssh_user = "${var.ssh_user}" | ||
ssh_keypair_name = "${var.ssh_keypair_name}" | ||
disk_size = "${var.node_disk_size}" | ||
} | ||
|
||
module "edge" { | ||
source = "./edge" | ||
name_prefix = "${var.cluster_prefix}" | ||
kubenow_image_id = "${var.kubenow_image_id}" | ||
instance_type = "${var.edge_instance_type}" | ||
subnet_id = "${module.vpc.subnet_id}" | ||
security_group_id = "${module.vpc.security_group_id}" | ||
kubeadm_token = "${var.kubeadm_token}" | ||
master_ip = "${module.master.ip_address_internal}" | ||
count = "${var.edge_count}" | ||
availability_zone = "${var.availability_zone}" | ||
ssh_user = "${var.ssh_user}" | ||
ssh_keypair_name = "${var.ssh_keypair_name}" | ||
disk_size = "${var.edge_disk_size}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
variable name_prefix {} | ||
variable kubenow_image_id {} | ||
variable instance_type {} | ||
variable kubeadm_token {} | ||
variable disk_size {} | ||
variable availability_zone {} | ||
variable ssh_user {} | ||
variable ssh_keypair_name {} | ||
variable subnet_id {} | ||
variable security_group_id {} | ||
|
||
|
||
# create bootstrap script file from template | ||
resource "template_file" "master_bootstrap" { | ||
template = "${file("${path.root}/../bootstrap/master.sh")}" | ||
vars { | ||
kubeadm_token = "${var.kubeadm_token}" | ||
} | ||
} | ||
|
||
resource "aws_instance" "master" { | ||
ami = "${var.kubenow_image_id}" | ||
availability_zone = "${var.availability_zone}" | ||
instance_type = "${var.instance_type}" | ||
associate_public_ip_address = true | ||
key_name = "${var.ssh_keypair_name}" | ||
vpc_security_group_ids = ["${var.security_group_id}"] | ||
subnet_id = "${var.subnet_id}" | ||
user_data = "${template_file.master_bootstrap.rendered}" | ||
|
||
root_block_device { | ||
delete_on_termination = true | ||
volume_size = "${var.disk_size}" | ||
} | ||
|
||
tags { | ||
Name = "${var.name_prefix}-master" | ||
sshUser = "${var.ssh_user}" | ||
} | ||
} | ||
|
||
# Generate ansible inventory | ||
resource "null_resource" "generate-inventory" { | ||
|
||
provisioner "local-exec" { | ||
command = "echo \"[master]\" > inventory" | ||
} | ||
|
||
provisioner "local-exec" { | ||
command = "echo \"${aws_instance.master.0.tags.Name} ansible_ssh_host=${aws_instance.master.0.public_ip} ansible_ssh_user=ubuntu\" >> inventory" | ||
} | ||
|
||
} | ||
|
||
output "ip_address" { | ||
value = "${aws_instance.master.0.public_ip}" | ||
} | ||
|
||
output "ip_address_internal" { | ||
value = "${aws_instance.master.0.private_ip}" | ||
} | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
variable name_prefix {} | ||
variable kubenow_image_id {} | ||
variable instance_type {} | ||
variable kubeadm_token {} | ||
variable disk_size {} | ||
variable availability_zone {} | ||
variable ssh_user {} | ||
variable ssh_keypair_name {} | ||
variable master_ip {} | ||
variable subnet_id {} | ||
variable count {} | ||
variable security_group_id {} | ||
|
||
|
||
# create bootstrap script file from template | ||
resource "template_file" "node_bootstrap" { | ||
template = "${file("${path.root}/../bootstrap/node.sh")}" | ||
vars { | ||
kubeadm_token = "${var.kubeadm_token}" | ||
master_ip = "${var.master_ip}" | ||
} | ||
} | ||
|
||
resource "aws_instance" "node" { | ||
count = "${var.count}" | ||
ami = "${var.kubenow_image_id}" | ||
availability_zone = "${var.availability_zone}" | ||
instance_type = "${var.instance_type}" | ||
associate_public_ip_address = true | ||
key_name = "${var.ssh_keypair_name}" | ||
vpc_security_group_ids = ["${var.security_group_id}"] | ||
subnet_id = "${var.subnet_id}" | ||
user_data = "${template_file.node_bootstrap.rendered}" | ||
|
||
root_block_device { | ||
delete_on_termination = true | ||
volume_size = "${var.disk_size}" | ||
} | ||
|
||
tags { | ||
Name = "${var.name_prefix}-node-${format("%03d", count.index)}" | ||
sshUser = "${var.ssh_user}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
variable name_prefix {} | ||
variable availability_zone {} | ||
|
||
|
||
resource "aws_vpc" "main" { | ||
cidr_block = "10.0.0.0/16" | ||
enable_dns_support = true | ||
enable_dns_hostnames = true | ||
tags { | ||
Name = "${var.name_prefix}" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "main" { | ||
vpc_id = "${aws_vpc.main.id}" | ||
cidr_block = "${aws_vpc.main.cidr_block}" | ||
availability_zone = "${var.availability_zone}" | ||
tags { | ||
Name = "${var.name_prefix}" | ||
} | ||
} | ||
|
||
resource "aws_internet_gateway" "main" { | ||
vpc_id = "${aws_vpc.main.id}" | ||
tags { | ||
Name = "${var.name_prefix}" | ||
} | ||
} | ||
|
||
resource "aws_route_table" "main" { | ||
vpc_id = "${aws_vpc.main.id}" | ||
|
||
route { | ||
cidr_block = "0.0.0.0/0" | ||
gateway_id = "${aws_internet_gateway.main.id}" | ||
} | ||
|
||
tags { | ||
Name = "${name_prefix}" | ||
} | ||
} | ||
|
||
resource "aws_main_route_table_association" "main" { | ||
vpc_id = "${aws_vpc.main.id}" | ||
route_table_id = "${aws_route_table.main.id}" | ||
} | ||
|
||
resource "aws_route_table_association" "main" { | ||
subnet_id = "${aws_subnet.main.id}" | ||
route_table_id = "${aws_route_table.main.id}" | ||
} | ||
|
||
resource "aws_security_group" "main" { | ||
name = "${var.name_prefix}" | ||
description = "kubenow default security group" | ||
vpc_id = "${aws_vpc.main.id}" | ||
|
||
|
||
ingress { # SSH | ||
from_port = 22 | ||
to_port = 22 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
ingress { # HTTP | ||
from_port = 80 | ||
to_port = 80 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
ingress { # HTTPS | ||
from_port = 443 | ||
to_port = 443 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
ingress { # Allow ALL internal (self) | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = -1 | ||
self = true | ||
} | ||
|
||
egress { # Allow ALL outbound | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
} | ||
|
||
output "subnet_id" { | ||
value = "${aws_subnet.main.id}" | ||
} | ||
|
||
output "security_group_id" { | ||
value = "${aws_security_group.main.id}" | ||
} |
Oops, something went wrong.