|
|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
terraform {
|
|
|
|
|
required_version = ">= 0.13"
|
|
|
|
|
required_version = ">= 1.0.8"
|
|
|
|
|
required_providers {
|
|
|
|
|
libvirt = {
|
|
|
|
|
source = "dmacvicar/libvirt"
|
|
|
|
|
source = "dmacvicar/libvirt"
|
|
|
|
|
version = "0.6.11"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -12,24 +12,14 @@ terraform {
|
|
|
|
|
# cloud-init
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
data "template_file" "master-node-user-datas" {
|
|
|
|
|
template = file("${path.module}/cloud_init.cfg")
|
|
|
|
|
vars = {
|
|
|
|
|
admin-passwd = "${var.root-admin-passwd}"
|
|
|
|
|
admin-pub-key = "${var.root-admin-pub-key}"
|
|
|
|
|
hostname = "${var.vm-name-prefix}-master-${count.index}"
|
|
|
|
|
}
|
|
|
|
|
count = var.master-nodes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data "template_file" "worker-node-user-datas" {
|
|
|
|
|
template = file("${path.module}/cloud_init.cfg")
|
|
|
|
|
vars = {
|
|
|
|
|
admin-passwd = "${var.root-admin-passwd}"
|
|
|
|
|
admin-pub-key = "${var.root-admin-pub-key}"
|
|
|
|
|
hostname = "${var.vm-name-prefix}-worker-${count.index}"
|
|
|
|
|
}
|
|
|
|
|
count = var.worker-nodes
|
|
|
|
|
module "cloud-init-config" {
|
|
|
|
|
for_each = var.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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
@ -42,16 +32,20 @@ provider "aws" {
|
|
|
|
|
region = "us-east-2"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "aws-amis" {
|
|
|
|
|
source = "./modules/aws-amis"
|
|
|
|
|
}
|
|
|
|
|
# This module will grab the latest ami for a variety of distros.
|
|
|
|
|
# module "aws-amis" {
|
|
|
|
|
# source = "./modules/aws-amis"
|
|
|
|
|
# }
|
|
|
|
|
# output "amis" {
|
|
|
|
|
# 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
|
|
|
|
|
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
|
|
|
|
|
admin-ips = var.admin-ips
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# This key pair is not actually used. Keys are added to the nodes via cloud-init
|
|
|
|
|
@ -64,30 +58,16 @@ resource "aws_key_pair" "key" {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "master-nodes" {
|
|
|
|
|
module "nodes" {
|
|
|
|
|
for_each = var.nodes-config
|
|
|
|
|
source = "./modules/aws-nodes"
|
|
|
|
|
ami = var.base-image
|
|
|
|
|
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]
|
|
|
|
|
user-datas = data.template_file.master-node-user-datas
|
|
|
|
|
num-nodes = var.master-nodes
|
|
|
|
|
name-prefix = "${var.vm-name-prefix}-master"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "worker-nodes" {
|
|
|
|
|
source = "./modules/aws-nodes"
|
|
|
|
|
ami = var.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]
|
|
|
|
|
user-datas = data.template_file.worker-node-user-datas
|
|
|
|
|
num-nodes = var.worker-nodes
|
|
|
|
|
name-prefix = "${var.vm-name-prefix}-worker"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output "amis" {
|
|
|
|
|
value = module.aws-amis.amis
|
|
|
|
|
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}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
@ -142,11 +122,6 @@ output "amis" {
|
|
|
|
|
# end libvirt
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
# TODO REM move to other file?
|
|
|
|
|
output "master-ips" {
|
|
|
|
|
value = module.master-nodes.ips
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output "worker-ips" {
|
|
|
|
|
value = module.worker-nodes.ips
|
|
|
|
|
output "ips" {
|
|
|
|
|
value = { for type, node in module.nodes : type => node.ips }
|
|
|
|
|
}
|
|
|
|
|
|