Compare commits
56
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a01c09928 | ||
|
|
cf0da0d659 | ||
|
|
a324e68287 | ||
|
|
043ee3b342 | ||
|
|
40613e08b6 | ||
|
|
4d39461101 | ||
|
|
15edee3b60 | ||
|
|
dff900e53a | ||
|
|
5107ec9a5c | ||
|
|
073ace2732 | ||
|
|
dda60c0b63 | ||
|
|
86acf7736d | ||
|
|
7ca4db8737 | ||
|
|
98bb54726d | ||
|
|
c229e1e0bb | ||
|
|
3fd6b034d7 | ||
|
|
f5fb896b9a | ||
|
|
5499a0e9da | ||
|
|
e57963641b | ||
|
|
7de2ba1728 | ||
|
|
6c2d3e3837 | ||
|
|
fee62e0385 | ||
|
|
482e8d1027 | ||
|
|
5ea36d8626 | ||
|
|
10a88425ed | ||
|
|
10d01ff839 | ||
|
|
ce3a5b39f5 | ||
|
|
ad0212a29d | ||
|
|
1787590da2 | ||
|
|
17c60e41bb | ||
|
|
ec6bb824d0 | ||
|
|
852d8cfcf2 | ||
|
|
c9ea3d4489 | ||
|
|
9aa0a68be8 | ||
|
|
3088e2295f | ||
|
|
091b459046 | ||
|
|
b4ac04fbd8 | ||
|
|
8724cede19 | ||
|
|
31a70766ec | ||
|
|
e9df4cd1d6 | ||
|
|
25794c641a | ||
|
|
b0b959f28b | ||
|
|
f357d3dd5b | ||
|
|
cb59a5b2f3 | ||
|
|
f8b894739f | ||
|
|
e3b15f952c | ||
|
|
833352fda8 | ||
|
|
a232bbfd71 | ||
|
|
b2ae84be72 | ||
|
|
4a62875b8e | ||
|
|
3d7bd95f78 | ||
|
|
474f6c746a | ||
|
|
af17823d68 | ||
|
|
b126da8acf | ||
|
|
483c44b695 | ||
|
|
2c0f1ff60e |
@@ -44,6 +44,7 @@ terraform.rc
|
||||
################################################################################
|
||||
|
||||
k8s-key*
|
||||
*admin-key*
|
||||
STARTHERE
|
||||
inventory
|
||||
|
||||
+5
-1
@@ -22,6 +22,10 @@ VM_NAME_PREFIX="$(
|
||||
tail -n 1 | \
|
||||
sed 's/^.*=\s*"\(.*\)"/\1/g')"
|
||||
|
||||
PUBLIC_IP_OUTPUT="groups_hostnames_ips"
|
||||
PRIVATE_IP_OUTPUT="groups_hostnames_private_ips"
|
||||
IP_TYPE="$PRIVATE_IP_OUTPUT"
|
||||
|
||||
# This command stores the output data in the format below.
|
||||
# [
|
||||
# {
|
||||
@@ -48,7 +52,7 @@ VM_NAME_PREFIX="$(
|
||||
# }
|
||||
# ]
|
||||
DATA="$(terraform show -json | \
|
||||
jq '.values.outputs.groups_hostnames_ips.value | to_entries |
|
||||
jq '.values.outputs.'"$IP_TYPE"'.value | to_entries |
|
||||
map({group: .key, vms:.value | to_entries |
|
||||
map({hostname:.key,ip:.value})})')"
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
locals {
|
||||
nodes-config = {
|
||||
"master" = {
|
||||
base-image = var.centos8-ami
|
||||
base-image = var.ubuntu-ami
|
||||
num = 1
|
||||
},
|
||||
"worker" = {
|
||||
base-image = var.centos8-ami
|
||||
base-image = var.ubuntu-ami
|
||||
num = 2
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,8 @@ module "cloud-init-config" {
|
||||
|
||||
module "aws-network-existing" {
|
||||
source = "./modules/aws-network-existing"
|
||||
default-vpc-name = var.aws-existing-vpc-name
|
||||
default-security-group-name = var.aws-existing-sg-name
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -79,8 +81,8 @@ module "nodes" {
|
||||
source = "./modules/aws-nodes"
|
||||
ami = each.value.base-image
|
||||
ec2-instance-type = var.aws-ec2-instance-type
|
||||
subnet-id = module.aws-network.subnet.id
|
||||
security-group-ids = [module.aws-network.default-security-group.id]
|
||||
subnet-id = module.aws-network-existing.k8s-subnets-ids[0]
|
||||
security-group-ids = [module.aws-network-existing.default-sg.id]
|
||||
user-datas = lookup(module.cloud-init-config, each.key, null).user-datas
|
||||
num-nodes = each.value.num
|
||||
name-prefix = "${var.vm-name-prefix}-${each.key}"
|
||||
@@ -127,8 +129,14 @@ module "nodes" {
|
||||
# end libvirt
|
||||
################################################################################
|
||||
|
||||
# This will output a map of group => [{hostname, ip}].
|
||||
# This will outpus a map of group => [{hostname, ip}].
|
||||
# TODO A 'names' output needs to be added to libvirt.
|
||||
output "groups_hostnames_ips" {
|
||||
value = { for type, node in module.nodes : type => zipmap(node.names, node.ips) }
|
||||
}
|
||||
|
||||
# This will outpus a map of group => [{hostname, private_ip}].
|
||||
# TODO Figure out how what to do about private_ips for libvirt.
|
||||
output "groups_hostnames_private_ips" {
|
||||
value = { for type, node in module.nodes : type => zipmap(node.names, node.private_ips) }
|
||||
}
|
||||
|
||||
+37
-16
@@ -1,31 +1,52 @@
|
||||
locals {
|
||||
amis = {
|
||||
amzn2 = {
|
||||
owner-id = "137112412989"
|
||||
# us-east-2
|
||||
# owner-id = "137112412989"
|
||||
# us-gov-west-1
|
||||
owner-id = "045324592363"
|
||||
name = "amzn2-ami-hvm-2*x86_64-gp2"
|
||||
},
|
||||
ubuntu = {
|
||||
owner-id = "099720109477"
|
||||
# us-east-2
|
||||
# owner-id = "099720109477"
|
||||
# us-gov-west-1
|
||||
owner-id = "513442679011"
|
||||
name = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"
|
||||
},
|
||||
centos7 = {
|
||||
owner-id = "125523088429"
|
||||
name = "CentOS 7.*x86_64"
|
||||
},
|
||||
centos8 = {
|
||||
owner-id = "125523088429"
|
||||
name = "CentOS 8.*x86_64"
|
||||
},
|
||||
arch = {
|
||||
owner-id = "093273469852"
|
||||
name = "arch-linux-lts-hvm*x86_64-ebs"
|
||||
},
|
||||
# centos7 = {
|
||||
# # us-east-2
|
||||
# # owner-id = "125523088429"
|
||||
# # us-gov-west-1
|
||||
# # owner-id = THERE IS NO CENTOS7 IMAGE in us-gov-west-1!!
|
||||
# name = "CentOS 7.*x86_64"
|
||||
# },
|
||||
# centos8 = {
|
||||
# # us-east-2
|
||||
# # owner-id = "125523088429"
|
||||
# # us-gov-west-1
|
||||
# # owner-id = THERE IS NO CENTOS8 IMAGE in us-gov-west-1!!
|
||||
# name = "CentOS 8.*x86_64"
|
||||
# },
|
||||
# arch = {
|
||||
# # us-east-2
|
||||
# # owner-id = "093273469852"
|
||||
# # us-gov-west-1
|
||||
# # owner-id = THERE IS NO ARCH IMAGE in us-gov-west-1!!
|
||||
# name = "arch-linux-lts-hvm*x86_64-ebs"
|
||||
# },
|
||||
rhel7 = {
|
||||
owner-id = "309956199498"
|
||||
# us-east-2
|
||||
# owner-id = "309956199498"
|
||||
# us-gov-west-1
|
||||
owner-id = "219670896067"
|
||||
name = "RHEL-7.*HVM*x86_64*GP2"
|
||||
},
|
||||
rhel8 = {
|
||||
owner-id = "309956199498"
|
||||
# us-east-2
|
||||
# owner-id = "309956199498"
|
||||
# us-gov-west-1
|
||||
owner-id = "219670896067"
|
||||
name = "RHEL-8.*HVM*x86_64*GP2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,3 +21,7 @@ data "aws_subnet" "subnets" {
|
||||
for_each = toset(data.aws_subnets.subnet-ids.ids)
|
||||
id = each.key
|
||||
}
|
||||
|
||||
data "aws_security_group" "default" {
|
||||
name = var.default-security-group-name
|
||||
}
|
||||
|
||||
@@ -2,12 +2,16 @@ output "default-vpc" {
|
||||
value = data.aws_vpc.default
|
||||
}
|
||||
|
||||
output "default-sg" {
|
||||
value = data.aws_security_group.default
|
||||
}
|
||||
|
||||
output "subnets" {
|
||||
description = "An array of all subnets in default-vpc."
|
||||
value = data.aws_subnet.subnets
|
||||
}
|
||||
|
||||
output "k8s-subnets" {
|
||||
output "k8s-subnets-ids" {
|
||||
description = "An array of subnets to be used for k8s VMs. These subnets were chosen by selecting a single subnet from each availability_zone."
|
||||
value = [for k,v in local.az-to-subnets : v[0]]
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
variable "default-security-group-name" {
|
||||
description = "The name of the existing default security group. This module will query AWS for a security group with this name,"
|
||||
}
|
||||
|
||||
variable "default-vpc-name" {
|
||||
description = "The name of the existing default VPC. This module will query AWS for a VPC with this name,"
|
||||
default = "Managed VPC"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
resource "aws_vpc" "vpc" {
|
||||
cidr_block = var.vpc-cidr-block
|
||||
tags = {
|
||||
Name = "${var.name-prefix}-vpc"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_subnet" "subnet" {
|
||||
vpc_id = aws_vpc.vpc.id
|
||||
cidr_block = var.subnet-cidr-block
|
||||
# availability_zone = var.avail_zone
|
||||
tags = {
|
||||
Name = "${var.name-prefix}-subnet"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_default_security_group" "sg" {
|
||||
vpc_id = aws_vpc.vpc.id
|
||||
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
cidr_blocks = var.admin-ips
|
||||
}
|
||||
|
||||
egress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
prefix_list_ids = []
|
||||
}
|
||||
|
||||
tags = {
|
||||
Name = "${var.name-prefix}-ssh-from-admins-sg"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_internet_gateway" "igw" {
|
||||
vpc_id = aws_vpc.vpc.id
|
||||
tags = {
|
||||
Name = "${var.name-prefix}-igw"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_default_route_table" "route-table" {
|
||||
default_route_table_id = aws_vpc.vpc.main_route_table_id
|
||||
|
||||
route {
|
||||
cidr_block = "0.0.0.0/0"
|
||||
gateway_id = aws_internet_gateway.igw.id
|
||||
}
|
||||
|
||||
# default route, mapping VPC CIDR block to "local", created implicitly and
|
||||
# cannot be specified.
|
||||
|
||||
tags = {
|
||||
Name = "${var.name-prefix}-route-table"
|
||||
}
|
||||
}
|
||||
|
||||
# Associate subnet with Route Table
|
||||
resource "aws_route_table_association" "a-rtb-subnet" {
|
||||
subnet_id = aws_subnet.subnet.id
|
||||
route_table_id = aws_default_route_table.route-table.id
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
output "vpc" {
|
||||
value = aws_vpc.vpc
|
||||
}
|
||||
|
||||
output "subnet" {
|
||||
value = aws_subnet.subnet
|
||||
}
|
||||
|
||||
output "default-security-group" {
|
||||
value = aws_default_security_group.sg
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
variable "admin-ips" {
|
||||
description = "A list of ips or cidr blocks that are allowed to connect to the nodes."
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
variable "name-prefix" {
|
||||
default = "tf"
|
||||
description = "This prefix will be used in all the names of the resources creates in our AWS network."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "subnet-cidr-block" {
|
||||
default = "10.0.1.0/24"
|
||||
description = "The address space to be used for this subnet."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vpc-cidr-block" {
|
||||
default = "10.0.0.0/16"
|
||||
description = "The address space to be used for out networks VPC."
|
||||
type = string
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
resource "aws_instance" "nodes" {
|
||||
ami = var.ami
|
||||
instance_type = var.ec2-instance-type
|
||||
# TODO REM double check this key.
|
||||
# key_name = aws_key_pair.debug1.key_name
|
||||
# TODO Make this a variable.
|
||||
associate_public_ip_address = true
|
||||
subnet_id = var.subnet-id
|
||||
vpc_security_group_ids = var.security-group-ids
|
||||
|
||||
@@ -2,6 +2,10 @@ output "ips" {
|
||||
value = aws_instance.nodes.*.public_ip
|
||||
}
|
||||
|
||||
output "private_ips" {
|
||||
value = aws_instance.nodes.*.private_ip
|
||||
}
|
||||
|
||||
output "names" {
|
||||
value = aws_instance.nodes.*.tags.Name
|
||||
}
|
||||
|
||||
+31
-4
@@ -1,4 +1,5 @@
|
||||
variable "admin-ips" {
|
||||
default = ["0.0.0.0/0"]
|
||||
description = "A list of ips or cidr blocks that are allowed to connect to the nodes."
|
||||
type = list(string)
|
||||
}
|
||||
@@ -8,6 +9,16 @@ variable "aws-ec2-instance-type" {
|
||||
description = "The AWS instance type to use for all nodes."
|
||||
}
|
||||
|
||||
variable "aws-existing-sg-name" {
|
||||
default = "change-me-if-using-aws-network-existing"
|
||||
description = "The name of the existing security group when using aws-network-existing."
|
||||
}
|
||||
|
||||
variable "aws-existing-vpc-name" {
|
||||
default = "change-me-if-using-aws-network-existing"
|
||||
description = "The name of the existing VPC when using aws-network-existing."
|
||||
}
|
||||
|
||||
variable "aws-region" {
|
||||
default = "us-east-1"
|
||||
description = "The AWS region to use."
|
||||
@@ -33,6 +44,7 @@ variable "disk-image-pool-name" {
|
||||
}
|
||||
|
||||
variable "libvirt-connection-url" {
|
||||
default = "nobody@localhost"
|
||||
description = "The libvirt connection URI, ie. qemu+ssh://<user>@<host>/system"
|
||||
}
|
||||
|
||||
@@ -95,31 +107,46 @@ variable "vm-name-prefix" {
|
||||
################################################################################
|
||||
|
||||
variable "amzn2-ami" {
|
||||
default = "ami-0dd0ccab7e2801812"
|
||||
# us-east-2
|
||||
# default = "ami-0dd0ccab7e2801812"
|
||||
# us-gov-west-1
|
||||
default = "ami-098bf51d9a35299f0"
|
||||
description = "The AMI to use for Amazon Linux 2."
|
||||
}
|
||||
variable "ubuntu-ami" {
|
||||
default = "ami-06c7d6c0987eaa46c"
|
||||
# us-east-2
|
||||
# default = "ami-06c7d6c0987eaa46c"
|
||||
# us-gov-west-1
|
||||
default = "ami-087ee83c8de303181"
|
||||
description = "The AMI to use for Ubuntu."
|
||||
}
|
||||
variable "centos7-ami" {
|
||||
# us-east-2
|
||||
default = "ami-00f8e2c955f7ffa9b"
|
||||
description = "The AMI to use for CentOS 7."
|
||||
}
|
||||
variable "centos8-ami" {
|
||||
# us-east-2
|
||||
default = "ami-057cacbfbbb471bb3"
|
||||
description = "The AMI to use for CentOS 8."
|
||||
}
|
||||
variable "arch-ami" {
|
||||
# us-east-2
|
||||
default = "ami-02653f06de985e3ba"
|
||||
description = "The AMI to use for Arch Linux."
|
||||
}
|
||||
variable "rhel7-ami" {
|
||||
default = "ami-0a509b3c2a4d05b3f"
|
||||
# us-east-2
|
||||
# default = "ami-0a509b3c2a4d05b3f"
|
||||
# us-gov-west-1
|
||||
default = "ami-04ccdf5793086ea95"
|
||||
description = "The AMI to use for RHEL 7."
|
||||
}
|
||||
variable "rhel8-ami" {
|
||||
default = "ami-0d871ca8a77af2948"
|
||||
# us-east-2
|
||||
# default = "ami-0d871ca8a77af2948"
|
||||
# us-gov-west-1
|
||||
default = "ami-0b1f10cd1cd107dd2"
|
||||
description = "The AMI to use for RHEL 8."
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user