Compare commits
42
Commits
852d8cfcf2
...
zfs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9504e3737d | ||
|
|
33f267b163 | ||
|
|
97f358332c | ||
|
|
861641dbd8 | ||
|
|
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 | ||
|
|
091b459046 | ||
|
|
b4ac04fbd8 | ||
|
|
31a70766ec | ||
|
|
e9df4cd1d6 | ||
|
|
25794c641a | ||
|
|
b0b959f28b | ||
|
|
2c0f1ff60e |
@@ -44,6 +44,7 @@ terraform.rc
|
||||
################################################################################
|
||||
|
||||
k8s-key*
|
||||
*admin-key*
|
||||
STARTHERE
|
||||
inventory
|
||||
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
A Terraform script to create k8s nodes. This script has modules for creating the
|
||||
nodes on a KVM/QEMU (libvirt) hypervisor or creating the nodes via AWS.
|
||||
|
||||
The modules allow you create N VMs of a specific type. So you could create 1
|
||||
master node and 3 worker nodes or you could create 3 Ubuntu VMs and 5 CentOS
|
||||
VMs, or whatever fits your needs.
|
||||
|
||||
Cloud-Init
|
||||
----------------------------------------
|
||||
|
||||
Both the libvirt and aws modules use cloud-init for initial configuration of the
|
||||
VMs.
|
||||
|
||||
Dependencies
|
||||
----------------------------------------
|
||||
|
||||
+19
-5
@@ -24,9 +24,23 @@ chpasswd:
|
||||
expire: false
|
||||
|
||||
hostname: ${hostname}
|
||||
fqdn: ${hostname}
|
||||
|
||||
# Use this when it's determined that we need a bigger disk image.
|
||||
# This must be used in conjuction with 'size' in 'libvirt_volume'
|
||||
# growpart:
|
||||
# mode: auto
|
||||
# devices: ['/']
|
||||
package_update: true
|
||||
package_upgrade: true
|
||||
package_reboot_if_required: true
|
||||
|
||||
%{ if install-qemu-agent }
|
||||
packages:
|
||||
# This are only necessary for libvirt.
|
||||
- qemu-guest-agent
|
||||
runcmd:
|
||||
# TODO At some point revisit this, this was added because it seemed like
|
||||
# apparmor was causing dhclient to not get an IP address for ubuntu. This
|
||||
# should be double checked.
|
||||
- echo "/proc/*/task/*/comm wr," | tee -a /etc/apparmor.d/local/sbin.dhclient
|
||||
# These are only necessary for libvirt.
|
||||
- systemctl enable qemu-guest-agent
|
||||
- systemctl start qemu-guest-agent
|
||||
- systemctl status qemu-guest-agent
|
||||
%{ endif }
|
||||
|
||||
+21
-26
@@ -1,4 +1,4 @@
|
||||
vm-name-prefix = "k8s-tf"
|
||||
vm-name-prefix = "ansible-test"
|
||||
|
||||
# A CIDR block ending in '/32' equates to a single IP address, '0.0.0.0/0'
|
||||
# equates to any ip address.
|
||||
@@ -10,29 +10,14 @@ libvirt-connection-url = "qemu+ssh://<user>@<host>/system"
|
||||
node-memory = 2048
|
||||
node-vcpus = 2
|
||||
|
||||
################################################################################
|
||||
# AWS EC2 instance types
|
||||
################################################################################
|
||||
|
||||
# 1 GiB, 1 vcpu, only one that is free.
|
||||
# This one won't work with k8s because it requires at least 2 vcpus.
|
||||
aws-ec2-instance-type = "t2.micro"
|
||||
|
||||
# 4 GiB, 2 vcpus
|
||||
# aws-ec2-instnce-type = "t2.medium"
|
||||
|
||||
################################################################################
|
||||
|
||||
nodes-config = {
|
||||
"master" = {
|
||||
base-image = "ami-0dd0ccab7e2801812"
|
||||
num = 1
|
||||
},
|
||||
"worker" = {
|
||||
base-image = "ami-0dd0ccab7e2801812"
|
||||
num = 2
|
||||
}
|
||||
}
|
||||
## libvirt disk size
|
||||
# 1 GiB = 1073741824
|
||||
# 4 GiB
|
||||
# libvirt-node-disk-size = "${4 * 1073741824}"
|
||||
# 8 GiB
|
||||
# libvirt-node-disk-size = "${8 * 1073741824}"
|
||||
# 12 GiB
|
||||
# libvirt-node-disk-size = "${12 * 1073741824}"
|
||||
|
||||
################################################################################
|
||||
# AWS images (AMIs)
|
||||
@@ -64,8 +49,18 @@ base-image = "ami-0dd0ccab7e2801812"
|
||||
################################################################################
|
||||
|
||||
# base-image = "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.img"
|
||||
# From https://cloud.centos.org/centos/7/images/ from 2020-11-12 06:52
|
||||
# base-image = "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-2009.qcow2"
|
||||
# From https://cloud.centos.org/centos/7/images/ from 2020-12-06
|
||||
# base-image = "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-2111.qcow2"
|
||||
|
||||
## Arch
|
||||
# From https://gitlab.archlinux.org/archlinux/arch-boxes/-/jobs/40102/artifacts/browse/output
|
||||
# on 2021-11-28
|
||||
# base-image = "/media/nas/software/isos/Arch-Linux-x86_64-libvirt-20211128.40102.box"
|
||||
|
||||
## Arch
|
||||
# From https://gitlab.archlinux.org/archlinux/arch-boxes/-/jobs/40102/artifacts/browse/output
|
||||
# on 2021-11-28
|
||||
# base-image = "/media/nas/software/isos/Arch-Linux-x86_64-libvirt-20211128.40102.box"
|
||||
|
||||
################################################################################
|
||||
# Keys/Passwords
|
||||
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
aws ec2 describe-instance-status | \
|
||||
jq '.InstanceStatuses[] | {id: .InstanceId, instance_status: .InstanceStatus.Status, system_status: .SystemStatus.Status}'
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script will grab the IPs for libvirt VMs. This script is only needed when
|
||||
# using a bridge as the network for the VMs. This should only be needed while
|
||||
# https://github.com/dmacvicar/terraform-provider-libvirt/issues/891 is
|
||||
# unresolved.
|
||||
|
||||
# These are the network interfaces that this script will attempt to get the IP
|
||||
# address for.
|
||||
# Ubuntu 20.04 ens3
|
||||
# Centos 7 & 8 eth0
|
||||
NET_INTERFACES="eth0 ens3"
|
||||
|
||||
LIBVIRT_CONNECTION_URL="libvirt-connection-url"
|
||||
VM_NAME_PREFIX="vm-name-prefix"
|
||||
|
||||
INV_GROUPS="$( \
|
||||
cat terraform.tfstate | \
|
||||
jq '.resources[] | select(.type=="libvirt_domain") | .module' | \
|
||||
sed 's/".*\[\\"\(.*\)\\.*$/\1/g' )"
|
||||
|
||||
# Grab the connection URL and the vm name prefix. We do this by greping all
|
||||
# *.tfvars files making sure to cat terraform.tfvars last. Then we just grab the
|
||||
# last grep result, this way we make sure any value in terraform.tfvars will
|
||||
# take priority.
|
||||
CONN_URLS="$( \
|
||||
find . -name "*.tfvars" -exec grep "$LIBVIRT_CONNECTION_URL" {} \; && \
|
||||
grep "$LIBVIRT_CONNECTION_URL" terraform.tfvars)"
|
||||
|
||||
CONN_URL="$(echo "$CONN_URLS" | tail -n 1 | sed 's/^.*=\s*"\(.*\)"/\1/g')"
|
||||
|
||||
NAME_PREFIXES="$( \
|
||||
find . -name "*.tfvars" -exec grep "$VM_NAME_PREFIX" {} \; && \
|
||||
grep "$VM_NAME_PREFIX" terraform.tfvars)"
|
||||
|
||||
NAME_PREFIX="$(echo "$NAME_PREFIXES" | tail -n 1 | sed 's/^.*=\s*"\(.*\)"/\1/g')"
|
||||
|
||||
# These can be used for debugging.
|
||||
# echo "Using connection URL: $CONN_URL"
|
||||
# echo "Using prefix: $NAME_PREFIX"
|
||||
|
||||
# Get the names of our VMs from libvirt.
|
||||
VMS="$(virsh -c $CONN_URL list --all | grep $NAME_PREFIX | awk '{print $2}')"
|
||||
|
||||
# Convert the lines of VM names to an array.
|
||||
OLD_IFS=$IFS
|
||||
IFS=$'\n'
|
||||
VMS=($VMS)
|
||||
IFS=$OLD_IFS
|
||||
|
||||
# Loop over our VM array and grab the ipv4 IP address from libvirt. Then add the
|
||||
# result to VM_IP_PAIRS as <vm-name>:<ipv4-address>.
|
||||
VM_IP_PAIRS=""
|
||||
for VM in "${VMS[@]}"; do
|
||||
for INTERFACE in $NET_INTERFACES; do
|
||||
IP="$( \
|
||||
virsh -c $CONN_URL qemu-agent-command $VM '{"execute": "guest-network-get-interfaces"}' | \
|
||||
jq '.return[] | select(.name=="'"$INTERFACE"'") | ."ip-addresses"[] | select(."ip-address-type"=="ipv4") | ."ip-address"' | \
|
||||
sed 's/"//g')"
|
||||
# Add the VM:IP pair if IP is not empty.
|
||||
if [ ! -z "$IP" ]; then
|
||||
VM_IP_PAIRS="$VM_IP_PAIRS"$'\n'"$VM:$IP"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# Write inventory
|
||||
cat /dev/null > inventory
|
||||
for GROUP in $INV_GROUPS; do
|
||||
echo "[$GROUP]" >> inventory
|
||||
echo "$VM_IP_PAIRS" | \
|
||||
grep $GROUP | \
|
||||
sed 's/^\(.*\):\(.*\)$/\1 ansible_host=\2/g' >> inventory
|
||||
done
|
||||
|
||||
# Print vars
|
||||
echo "$VM_IP_PAIRS" | \
|
||||
sed 's/^\(.*\):\(.*\)$/\1=\2/g' | \
|
||||
sed s/$NAME_PREFIX-//g | \
|
||||
sed 's/-/_/g' | \
|
||||
awk '{print toupper($1)}'
|
||||
+87
-49
@@ -1,60 +1,98 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# This script will create environment variables for all of the output IPs. It
|
||||
# will also create a `ANSIBLE_INV` variable that will be a comma separated
|
||||
# string of all the IPs. A anisble inventory file called "inventory is created
|
||||
# as well.
|
||||
# This script will create environment variables for all of the output IPs. An
|
||||
# anisble inventory file is created as well.
|
||||
#
|
||||
# Use eval $(./get-vm-ips.sh) to set env vars for ips.
|
||||
|
||||
terraform refresh > /dev/null
|
||||
|
||||
# All terraform outputs in json format.
|
||||
OUTPUTS_JSON="$(
|
||||
terraform show -json | \
|
||||
jq '.values.outputs' | \
|
||||
sed 's/-/_/g')"
|
||||
# Just the IP address outputs in json format. Also all '-' characters are
|
||||
# replaced by '_' becuase '-' causes jq some problems.
|
||||
IPS_JSON="$(
|
||||
echo $OUTPUTS_JSON | \
|
||||
jq 'to_entries | .[] | select(.key | contains("ips"))')"
|
||||
# An array of all node "types"
|
||||
NODE_TYPE_ARRAY="$(
|
||||
echo $IPS_JSON | \
|
||||
jq '.value.value | to_entries | .[] | .key' | \
|
||||
# The file to write the inventory to. This file will be completely overridden.
|
||||
INVENTORY_FILE="inventory"
|
||||
|
||||
# Grab the the vm name prefix. We do this by greping all *.tfvars files making
|
||||
# sure to cat terraform.tfvars last. Then we just grab the last grep result,
|
||||
# this way we make sure any value in terraform.tfvars will take priority.
|
||||
VM_NAME_PREFIX_VAR="vm-name-prefix"
|
||||
VM_NAME_PREFIXES="$( \
|
||||
find . -name "*.tfvars" -exec grep "$VM_NAME_PREFIX_VAR" {} \; && \
|
||||
grep "$VM_NAME_PREFIX_VAR" terraform.tfvars)"
|
||||
VM_NAME_PREFIX="$(
|
||||
echo "$VM_NAME_PREFIXES" | \
|
||||
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.
|
||||
# [
|
||||
# {
|
||||
# "group": "master",
|
||||
# "vms": [
|
||||
# {
|
||||
# "hostname": "ansible-test-master-0",
|
||||
# "ip": "52.14.114.48"
|
||||
# }
|
||||
# ]
|
||||
# },
|
||||
# {
|
||||
# "group": "worker",
|
||||
# "vms": [
|
||||
# {
|
||||
# "hostname": "ansible-test-worker-0",
|
||||
# "ip": "3.145.121.159"
|
||||
# },
|
||||
# {
|
||||
# "hostname": "ansible-test-worker-1",
|
||||
# "ip": "18.217.112.176"
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# ]
|
||||
DATA="$(terraform show -json | \
|
||||
jq '.values.outputs.'"$IP_TYPE"'.value | to_entries |
|
||||
map({group: .key, vms:.value | to_entries |
|
||||
map({hostname:.key,ip:.value})})')"
|
||||
|
||||
# Pull out the groups from $DATA. The format is a single string with the groups
|
||||
# separated by spaces, ie. "group1 group2 group3".
|
||||
ANS_GROUPS="$(
|
||||
echo $DATA | \
|
||||
jq '.[] | .group' | \
|
||||
sed 's/"//g' | \
|
||||
sed -z 's/\n/ /g;s/ $/\n/g')"
|
||||
tr '\n' ' '
|
||||
)"
|
||||
|
||||
# Loop over all the node types and create an export line for each IP.
|
||||
VM_IP_EXPORTS="$(
|
||||
for TYPE in $NODE_TYPE_ARRAY; do
|
||||
# Clear the inventory file.
|
||||
cat /dev/null > $INVENTORY_FILE
|
||||
|
||||
# Convert type, converts "master-ips" to "MASTER"
|
||||
TYPE_UPPER="$(echo ${TYPE^^} | sed s/_.*$//g)"
|
||||
echo "$IPS_JSON" | \
|
||||
jq '.value.value.'"$TYPE"'[]' | \
|
||||
# Add line numbers starting with 0.
|
||||
nl -v 0 | \
|
||||
# Print an export string with a type placeholder "__TYPE__".
|
||||
awk '{print "export __TYPE___" $1 "=" $2}' | \
|
||||
sed s/__TYPE__/$TYPE_UPPER/g
|
||||
done)"
|
||||
# For each group, write the VM info to $INVENTORY_FILE and also print a variable
|
||||
# expression to stdout.
|
||||
for GROUP in $ANS_GROUPS; do
|
||||
|
||||
ANSIBLE_INV="$(
|
||||
echo "$VM_IP_EXPORTS" | \
|
||||
# Write the inventory file to $INVENTORY_FILE.
|
||||
echo "[$GROUP]" >> $INVENTORY_FILE
|
||||
echo $DATA | \
|
||||
jq '.[] | select(.group=="'"$GROUP"'") | .vms[] |
|
||||
"\(.hostname) ansible_host=\(.ip)"' | \
|
||||
sed 's/"//g' \
|
||||
>> $INVENTORY_FILE
|
||||
|
||||
# For this group, collect expressions into VARS. The format is:
|
||||
# HOSTNAME1=0.0.0.0
|
||||
# HOSTNAME2=0.0.0.0
|
||||
VARS="$(
|
||||
echo -n $DATA | \
|
||||
jq '.[] | select(.group=="'"$GROUP"'") | .vms[] |
|
||||
"\(.hostname)=\(.ip)"' | \
|
||||
sed 's/"//g' | \
|
||||
sed 's/^.*=//g' | \
|
||||
sed -z 's/\n/,/g;s/,$/\n/g')"
|
||||
|
||||
# Create an inventory file for ansible.
|
||||
echo "[k8s_nodes]" > inventory
|
||||
echo $VM_IP_EXPORTS | \
|
||||
sed 's/"//g' | \
|
||||
sed 's/export //g' | \
|
||||
sed 's/ /\n/g' | \
|
||||
sed 's/^\(.*\)\(=.*\)$/\1 ansible_host\2/g' \
|
||||
>> inventory
|
||||
|
||||
echo $VM_IP_EXPORTS | sed 's/" /"\n/g'
|
||||
echo export ANSIBLE_INV=$ANSIBLE_INV
|
||||
sed "s/$VM_NAME_PREFIX-//g" | \
|
||||
sed 's/-/_/g'
|
||||
)"
|
||||
# Print the contents of $VARS converted to uppercase. If it's not expty.
|
||||
if [ ! -z "$VARS" ]; then
|
||||
echo "${VARS^^}"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -1,11 +1,55 @@
|
||||
terraform {
|
||||
required_version = ">= 1.0.8"
|
||||
required_providers {
|
||||
libvirt = {
|
||||
source = "dmacvicar/libvirt"
|
||||
version = "0.6.11"
|
||||
}
|
||||
|
||||
locals {
|
||||
k8s-subnets-ids = [
|
||||
# module.aws-network-from-scratch.subnet.id,
|
||||
module.aws-network-existing.subnet-by-name["subnet_1"].id,
|
||||
module.aws-network-existing.subnet-by-name["subnet_3"].id,
|
||||
]
|
||||
nfs-subnets = [
|
||||
# module.aws-network-from-scratch.subnet,
|
||||
module.aws-network-existing.subnet-by-name["subnet_4"],
|
||||
]
|
||||
aws-security-group-id = module.aws-network-existing.default-sg.id
|
||||
# aws-security-group-id = module.aws-network-from-scratch.default-security-group.id
|
||||
nodes-config = {
|
||||
"k8s-master" = {
|
||||
base-image = var.ubuntu-ami
|
||||
aws-ec2-type = var.t2-medium-4gib-2vcpu
|
||||
subnet-ids = local.k8s-subnets-ids
|
||||
num = 0
|
||||
},
|
||||
"k8s-worker" = {
|
||||
base-image = var.ubuntu-ami
|
||||
aws-ec2-type = var.t2-medium-4gib-2vcpu
|
||||
subnet-ids = local.k8s-subnets-ids
|
||||
num = 0
|
||||
},
|
||||
"ansible-test" = {
|
||||
base-image = var.ubuntu-ami
|
||||
aws-ec2-type = var.t2-micro-1gib-1vcpu
|
||||
# subnet-ids = [module.aws-network-from-scratch.subnet.id]
|
||||
subnet-ids = [module.aws-network-existing.subnet-by-name["subnet_2"].id]
|
||||
num = 0
|
||||
},
|
||||
"nfs" = {
|
||||
base-image = var.ubuntu-ami
|
||||
aws-ec2-type = var.t2-micro-1gib-1vcpu
|
||||
# subnet-ids = [module.aws-network-from-scratch.subnet.id]
|
||||
subnet-ids = [module.aws-network-existing.subnet-by-name["subnet_4"].id]
|
||||
num = 1
|
||||
num-disks = 1
|
||||
disk-size = 10
|
||||
},
|
||||
"proxy" = {
|
||||
base-image = var.ubuntu-ami
|
||||
aws-ec2-type = var.t2-micro-1gib-1vcpu
|
||||
# subnet-ids = [module.aws-network-from-scratch.subnet.id]
|
||||
subnet-ids = [module.aws-network-existing.subnet-by-name["subnet_4"].id]
|
||||
private-ips = [var.aws-proxy-private-ip]
|
||||
num = 1
|
||||
},
|
||||
}
|
||||
install-qemu-agent = false
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -13,13 +57,14 @@ terraform {
|
||||
################################################################################
|
||||
|
||||
module "cloud-init-config" {
|
||||
for_each = var.nodes-config
|
||||
for_each = local.nodes-config
|
||||
source = "./modules/cloud-init-config"
|
||||
cloud-init-template = "${path.module}/cloud_init.cfg"
|
||||
hostname-prefix = "${var.vm-name-prefix}-${each.key}"
|
||||
num = each.value.num
|
||||
root-admin-passwd = var.root-admin-passwd
|
||||
root-admin-pub-key = var.root-admin-pub-key
|
||||
install-qemu-agent = local.install-qemu-agent
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -28,11 +73,8 @@ module "cloud-init-config" {
|
||||
# libvirt modules/resources.
|
||||
################################################################################
|
||||
|
||||
provider "aws" {
|
||||
region = "us-east-2"
|
||||
}
|
||||
|
||||
# This module will grab the latest ami for a variety of distros.
|
||||
# This module will grab the latest ami for a variety of distros. Uncomment to
|
||||
# get a list of the latest AMIs for our supported distros.
|
||||
# module "aws-amis" {
|
||||
# source = "./modules/aws-amis"
|
||||
# }
|
||||
@@ -40,14 +82,30 @@ provider "aws" {
|
||||
# value = module.aws-amis.amis
|
||||
# }
|
||||
|
||||
module "aws-network" {
|
||||
source = "./modules/aws-network"
|
||||
name-prefix = var.vm-name-prefix
|
||||
vpc-cidr-block = var.aws-vpc-cidr-block
|
||||
subnet-cidr-block = var.aws-subnet-cidr-block
|
||||
admin-ips = var.admin-ips
|
||||
################################################################################
|
||||
# AWS Networking
|
||||
# Use of the 2 modules below to create resources for the AWS network.
|
||||
# aws-network-from-scratch will build the AWS network from scratch.
|
||||
# aws-network-existing will query AWS for an existing VPC.
|
||||
################################################################################
|
||||
|
||||
# module "aws-network-from-scratch" {
|
||||
# source = "./modules/aws-network-from-scratch"
|
||||
# name-prefix = var.vm-name-prefix
|
||||
# vpc-cidr-block = var.aws-vpc-cidr-block
|
||||
# subnet-cidr-block = var.aws-subnet-cidr-block
|
||||
# admin-ips = var.admin-ips
|
||||
# }
|
||||
|
||||
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
|
||||
existing-subnet-names = var.aws-existing-subnet-names
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
||||
# This key pair is not actually used. Keys are added to the nodes via cloud-init
|
||||
# instead. We just add this here that this key will show up in the AWS console."
|
||||
resource "aws_key_pair" "key" {
|
||||
@@ -58,16 +116,41 @@ resource "aws_key_pair" "key" {
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_ebs_volume" "zfs" {
|
||||
# TODO REM look at types.
|
||||
availability_zone = local.nfs-subnets[0].availability_zone
|
||||
size = local.nodes-config["nfs"].disk-size
|
||||
encrypted = true
|
||||
count = local.nodes-config["nfs"].num-disks
|
||||
tags = {
|
||||
Name = "zfs-disk-${count.index}"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_volume_attachment" "mount-nfs-volume" {
|
||||
device_name = "/dev/sd${element(var.aws-zfs-drive-letters, count.index)}"
|
||||
instance_id = module.nodes["nfs"].nodes[0].id
|
||||
count = local.nodes-config["nfs"].num-disks
|
||||
volume_id = element(aws_ebs_volume.zfs, count.index).id
|
||||
}
|
||||
|
||||
output "zfs-drive-letters" {
|
||||
value = aws_volume_attachment.mount-nfs-volume.*.device_name
|
||||
}
|
||||
|
||||
module "nodes" {
|
||||
for_each = var.nodes-config
|
||||
for_each = local.nodes-config
|
||||
source = "./modules/aws-nodes"
|
||||
ec2-instance-type = each.value.aws-ec2-type
|
||||
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-ids = each.value.subnet-ids
|
||||
private-ips = try(each.value.private-ips, [])
|
||||
security-group-ids = [local.aws-security-group-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}"
|
||||
# TODO add a input for the key so that it will show up as the key in the aws
|
||||
# console.
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -85,14 +168,16 @@ module "nodes" {
|
||||
# }
|
||||
#
|
||||
# module "nodes" {
|
||||
# for_each = var.nodes-config
|
||||
# for_each = local.nodes-config
|
||||
# source = "./modules/libvirt-nodes"
|
||||
# pool-name = libvirt_pool.images.name
|
||||
# name-prefix = "${var.vm-name-prefix}-${each.key}"
|
||||
# num-nodes = each.value.num
|
||||
# node-memory = var.node-memory
|
||||
# node-vcpus = var.node-vcpus
|
||||
# node-disk-size = var.libvirt-node-disk-size
|
||||
# base-image = each.value.base-image
|
||||
# network-name = var.libvirt-network-name
|
||||
# root-admin-passwd = var.root-admin-passwd
|
||||
# root-admin-pub-key = var.root-admin-pub-key
|
||||
# libvirt-connection-url = var.libvirt-connection-url
|
||||
@@ -109,6 +194,14 @@ module "nodes" {
|
||||
# end libvirt
|
||||
################################################################################
|
||||
|
||||
output "ips" {
|
||||
value = { for type, node in module.nodes : type => node.ips }
|
||||
# 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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
locals {
|
||||
az-to-subnets = {
|
||||
for s in data.aws_subnet.subnets : s.availability_zone => s.id...
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_vpc" "default" {
|
||||
tags = {
|
||||
Name = var.default-vpc-name
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_subnets" "subnet-ids" {
|
||||
filter {
|
||||
name = "vpc-id"
|
||||
values = [data.aws_vpc.default.id]
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_subnet" "subnets" {
|
||||
for_each = toset(data.aws_subnets.subnet-ids.ids)
|
||||
id = each.key
|
||||
}
|
||||
|
||||
data "aws_subnet" "subnet-by-name" {
|
||||
for_each = toset(var.existing-subnet-names)
|
||||
filter {
|
||||
name = "tag:Name"
|
||||
values = [each.key]
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_security_group" "default" {
|
||||
name = var.default-security-group-name
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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 "one-subnet-per-az" {
|
||||
description = "An array of subnets that selects 1 subnet per az."
|
||||
value = [for k,v in local.az-to-subnets : v[0]]
|
||||
}
|
||||
|
||||
output "subnet-by-name" {
|
||||
description = "A map of subnet name to subnet resource."
|
||||
value = data.aws_subnet.subnet-by-name
|
||||
}
|
||||
|
||||
output "az-to-subnets" {
|
||||
description = "A map of availability zone to array of subnets that are in thet availability zone."
|
||||
value = local.az-to-subnets
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
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,"
|
||||
}
|
||||
|
||||
variable "existing-subnet-names" {
|
||||
description = "A list of subnet names that already exist in default-vpc-name"
|
||||
default = []
|
||||
type = list(string)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ resource "aws_default_security_group" "sg" {
|
||||
}
|
||||
|
||||
tags = {
|
||||
Name = "${var.name-prefix}-ssh-from-admins--sg"
|
||||
Name = "${var.name-prefix}-ssh-from-admins-sg"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
resource "aws_instance" "nodes" {
|
||||
ami = var.ami
|
||||
instance_type = var.ec2-instance-type
|
||||
# key_name = aws_key_pair.debug1.key_name
|
||||
# TODO Make this a variable.
|
||||
associate_public_ip_address = true
|
||||
subnet_id = var.subnet-id
|
||||
subnet_id = element(var.subnet-ids, count.index % length(var.subnet-ids))
|
||||
# Set a private IP if var.private-ips is not empty, otherwise let AWS assign
|
||||
# the IP.
|
||||
private_ip = length(var.private-ips) == 0 ? null : element(var.private-ips, count.index)
|
||||
vpc_security_group_ids = var.security-group-ids
|
||||
user_data = element(var.user-datas.*.rendered, count.index)
|
||||
count = var.num-nodes
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
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
|
||||
}
|
||||
|
||||
output "nodes" {
|
||||
value = aws_instance.nodes
|
||||
}
|
||||
|
||||
@@ -21,13 +21,19 @@ variable "num-nodes" {
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "private-ips" {
|
||||
default = []
|
||||
description = "A list of private IP addresses to use for the nodes. If the list is empty then each node will get an IP assigned from AWS."
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
variable "user-datas" {
|
||||
description = "A list of cloud-init configs that get applied to their corresponding node."
|
||||
}
|
||||
|
||||
variable "subnet-id" {
|
||||
description = "The ID of the subnet that all the nodes will be added to."
|
||||
type = string
|
||||
variable "subnet-ids" {
|
||||
description = "An array of subnet ids. These subnets will be round robined as the subnet to use for each node."
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
variable "security-group-ids" {
|
||||
|
||||
@@ -4,6 +4,7 @@ data "template_file" "user-datas" {
|
||||
admin-passwd = "${var.root-admin-passwd}"
|
||||
admin-pub-key = "${var.root-admin-pub-key}"
|
||||
hostname = "${var.hostname-prefix}-${count.index}"
|
||||
install-qemu-agent = var.install-qemu-agent
|
||||
}
|
||||
count = var.num
|
||||
}
|
||||
|
||||
@@ -8,6 +8,12 @@ variable "hostname-prefix" {
|
||||
description = "This prefix wil be applied as a prefix for the hostnames."
|
||||
}
|
||||
|
||||
variable "install-qemu-agent" {
|
||||
default = false
|
||||
description = "This flag determines whether or not qemu-agent is installed."
|
||||
type = bool
|
||||
}
|
||||
|
||||
variable "num" {
|
||||
description = "The number of user-datas to create with these parameters."
|
||||
}
|
||||
|
||||
@@ -9,13 +9,20 @@ terraform {
|
||||
}
|
||||
|
||||
resource "libvirt_volume" "node-images" {
|
||||
name = "${var.name-prefix}-${count.index}"
|
||||
name = "${var.name-prefix}-base"
|
||||
pool = var.pool-name
|
||||
source = var.base-image
|
||||
count = var.num-nodes
|
||||
format = "qcow2"
|
||||
}
|
||||
|
||||
resource "libvirt_volume" "node-images-resized" {
|
||||
name = "${var.name-prefix}-${count.index}-resized"
|
||||
pool = var.pool-name
|
||||
base_volume_id = libvirt_volume.node-images.id
|
||||
count = var.num-nodes
|
||||
size = var.node-disk-size
|
||||
}
|
||||
|
||||
data "template_file" "network-config" {
|
||||
template = file("${path.module}/network_config.cfg")
|
||||
}
|
||||
@@ -37,9 +44,9 @@ resource "libvirt_domain" "nodes" {
|
||||
cloudinit = element(libvirt_cloudinit_disk.node-inits.*.id, count.index)
|
||||
|
||||
network_interface {
|
||||
network_name = "default"
|
||||
network_name = var.network-name
|
||||
hostname = "${var.name-prefix}-${count.index}"
|
||||
wait_for_lease = true
|
||||
# wait_for_lease = true
|
||||
}
|
||||
|
||||
# IMPORTANT: this is a known bug on cloud images, since they expect a console
|
||||
@@ -58,7 +65,7 @@ resource "libvirt_domain" "nodes" {
|
||||
}
|
||||
|
||||
disk {
|
||||
volume_id = element(libvirt_volume.node-images.*.id, count.index)
|
||||
volume_id = element(libvirt_volume.node-images-resized.*.id, count.index)
|
||||
}
|
||||
|
||||
graphics {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
|
||||
output "ips" {
|
||||
value = libvirt_domain.nodes.*.network_interface.0.addresses.0
|
||||
}
|
||||
# This only works on the default network. They will not work using the bridged
|
||||
# network.
|
||||
# output "ips" {
|
||||
# value = libvirt_domain.nodes.*.network_interface.0.addresses.0
|
||||
# }
|
||||
|
||||
@@ -12,6 +12,16 @@ variable "name-prefix" {
|
||||
description = "This will be a prefix for all resource names, ie. domains will be created suck as \"k8s-node-2\"."
|
||||
}
|
||||
|
||||
variable "network-name" {
|
||||
default = "default"
|
||||
description = "The name of a pre-existing virtual-network."
|
||||
}
|
||||
|
||||
variable "node-disk-size" {
|
||||
default = 4294967296
|
||||
description = "The size of the disk to be used for libvirt nodes. (in bytes)"
|
||||
}
|
||||
|
||||
variable "node-memory" {
|
||||
default = "2048"
|
||||
description = "The amount of memory to be used for all the nodes."
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
|
||||
provider "aws" {
|
||||
region = var.aws-region
|
||||
# profile = <aws cli profile>
|
||||
}
|
||||
|
||||
|
||||
terraform {
|
||||
required_version = ">= 1.0.8"
|
||||
|
||||
backend "s3" {
|
||||
|
||||
bucket = "mss-terraform-state"
|
||||
key = "global/s3/terraform.tfstate"
|
||||
region = "us-gov-west-1"
|
||||
|
||||
dynamodb_table = "mss-terraform-state-lock"
|
||||
encrypt = true
|
||||
|
||||
}
|
||||
required_providers {
|
||||
libvirt = {
|
||||
source = "dmacvicar/libvirt"
|
||||
version = "0.6.11"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##
|
||||
#S3 bucket create to hold our TFState file so we can all share env settings
|
||||
resource "aws_s3_bucket" "terraform_state" {
|
||||
bucket = "mss-terraform-state"
|
||||
|
||||
# enable versioning for the state files
|
||||
versioning {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
#enable server-side encryption
|
||||
server_side_encryption_configuration {
|
||||
|
||||
rule {
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "AES256"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
##
|
||||
# no sql database used so that we can lock the TFstate file in the S3 bucket to ensure two people
|
||||
# are not running a terraform command at the same time
|
||||
resource "aws_dynamodb_table" "terraform_locks" {
|
||||
name = "mss-terraform-state-lock"
|
||||
billing_mode = "PAY_PER_REQUEST"
|
||||
hash_key = "LockID"
|
||||
|
||||
attribute {
|
||||
name = "LockID"
|
||||
type = "S"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
# output variable to give details on the s3 bucket created
|
||||
#TODO: move to output.tf
|
||||
output "s3_bucket_arn" {
|
||||
value = aws_s3_bucket.terraform_state.arn
|
||||
description = "The ARN of the S3 bucket"
|
||||
}
|
||||
+141
-8
@@ -1,11 +1,39 @@
|
||||
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)
|
||||
}
|
||||
|
||||
variable "aws-ec2-instance-type" {
|
||||
default = "t2.micro"
|
||||
description = "The AWS instance type to use for all nodes."
|
||||
variable "aws-zfs-drive-letters" {
|
||||
default = ["f", "g", "h", "i", "j"]
|
||||
description = "These are the drove letters to use when attaching EBS volumes, ie. /dev/sdf or /dev/sdg"
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
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-existing-subnet-names" {
|
||||
description = "A list of subnet names that already exist in aws-existing-vpc-name"
|
||||
default = []
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
variable "aws-proxy-private-ip" {
|
||||
description = "The private IP to request for the proxy instance."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "aws-region" {
|
||||
default = "us-east-1"
|
||||
description = "The AWS region to use."
|
||||
}
|
||||
|
||||
variable "aws-subnet-cidr-block" {
|
||||
@@ -28,9 +56,20 @@ variable "disk-image-pool-name" {
|
||||
}
|
||||
|
||||
variable "libvirt-connection-url" {
|
||||
default = "nobody@localhost"
|
||||
description = "The libvirt connection URI, ie. qemu+ssh://<user>@<host>/system"
|
||||
}
|
||||
|
||||
variable "libvirt-network-name" {
|
||||
default = "default"
|
||||
description = "The name of a pre-existing libvirt virtual-network."
|
||||
}
|
||||
|
||||
variable "libvirt-node-disk-size" {
|
||||
default = 4294967296
|
||||
description = "The size of the disk to be used for libvirt nodes. (in bytes)"
|
||||
}
|
||||
|
||||
variable "node-memory" {
|
||||
default = "2048"
|
||||
description = "The amount of memory to be used for all the nodes."
|
||||
@@ -43,11 +82,6 @@ variable "node-vcpus" {
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "nodes-config" {
|
||||
description = "A config that declares how many nodes of each type you want created."
|
||||
type = map(object({base-image=string,num=number}))
|
||||
}
|
||||
|
||||
variable "root-admin-passwd" {
|
||||
description = "This will be the password for the root and admin user. The format of this can by any format accepted by cloud-init's chpasswd module."
|
||||
}
|
||||
@@ -76,3 +110,102 @@ variable "vm-name-prefix" {
|
||||
default = "k8s-tf"
|
||||
description = "This prefix will appear before all VM names and hostnames, ie. k8s-tf-master-0."
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# AWS AMI vars
|
||||
# These variables are really more like constants. Using variables improves
|
||||
# readability. The defaults are manually updated. Use the aws-amis module to get
|
||||
# the latest for each distro.
|
||||
################################################################################
|
||||
|
||||
variable "amzn2-ami" {
|
||||
# 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" {
|
||||
# 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" {
|
||||
# us-east-2
|
||||
# default = "ami-0a509b3c2a4d05b3f"
|
||||
# us-gov-west-1
|
||||
default = "ami-04ccdf5793086ea95"
|
||||
description = "The AMI to use for RHEL 7."
|
||||
}
|
||||
variable "rhel8-ami" {
|
||||
# us-east-2
|
||||
# default = "ami-0d871ca8a77af2948"
|
||||
# us-gov-west-1
|
||||
default = "ami-0b1f10cd1cd107dd2"
|
||||
description = "The AMI to use for RHEL 8."
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# AWS EC2 types.
|
||||
# These variables are really more like constants. Using variables improves
|
||||
# readability.
|
||||
################################################################################
|
||||
|
||||
variable "t2-micro-1gib-1vcpu" {
|
||||
description = "t2.micro EC2 instance with 1 GiB mem and 1 vCPU."
|
||||
default = "t2.micro"
|
||||
}
|
||||
|
||||
variable "t2-medium-4gib-2vcpu" {
|
||||
description = "t2.medium EC2 instance with 4 GiB mem and 2 vCPUs."
|
||||
default = "t2.medium"
|
||||
}
|
||||
|
||||
variable "t2-large-8gib-2vcpu" {
|
||||
description = "t2.large EC2 instance with 8 GiB mem and 2 vCPUs."
|
||||
default = "t2.large"
|
||||
}
|
||||
|
||||
variable "t2-xlarge-16gib-4vcpu" {
|
||||
description = "t2.xlarge EC2 instance with 16 GiB mem and 4 vCPUs."
|
||||
default = "t2.xlarge"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Libvirt Images
|
||||
# These variables are really more like constants. Using variables improves
|
||||
# readability. The defaults are manually updated.
|
||||
################################################################################
|
||||
|
||||
variable "ubuntu-img" {
|
||||
default = "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.img"
|
||||
description = "The libvirt image tp use for Ubuntu."
|
||||
}
|
||||
|
||||
variable "centos7-img" {
|
||||
# Latest as of 2021-12-06.
|
||||
default = "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-2111.qcow2"
|
||||
description = "The libvirt image tp use for CentOS 7."
|
||||
}
|
||||
|
||||
variable "centos8-img" {
|
||||
default = "https://cloud.centos.org/centos/8/x86_64/images/CentOS-8-GenericCloud-8.4.2105-20210603.0.x86_64.qcow2"
|
||||
description = "The libvirt image tp use for CentOS 8."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user