Moved node-config to be local, added AMI vars.
This commit is contained in:
@@ -21,19 +21,6 @@ aws-ec2-instance-type = "t2.micro"
|
|||||||
# 4 GiB, 2 vcpus
|
# 4 GiB, 2 vcpus
|
||||||
# aws-ec2-instnce-type = "t2.medium"
|
# aws-ec2-instnce-type = "t2.medium"
|
||||||
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
nodes-config = {
|
|
||||||
"master" = {
|
|
||||||
base-image = "ami-0dd0ccab7e2801812"
|
|
||||||
num = 1
|
|
||||||
},
|
|
||||||
"worker" = {
|
|
||||||
base-image = "ami-0dd0ccab7e2801812"
|
|
||||||
num = 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# AWS images (AMIs)
|
# AWS images (AMIs)
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ ANSIBLE_INV="$(
|
|||||||
sed -z 's/\n/,/g;s/,$/\n/g')"
|
sed -z 's/\n/,/g;s/,$/\n/g')"
|
||||||
|
|
||||||
# Create an inventory file for ansible.
|
# Create an inventory file for ansible.
|
||||||
|
echo "# Wrote an Ansible inventory file at ./inventory"
|
||||||
echo "[k8s_nodes]" > inventory
|
echo "[k8s_nodes]" > inventory
|
||||||
echo $VM_IP_EXPORTS | \
|
echo $VM_IP_EXPORTS | \
|
||||||
sed 's/"//g' | \
|
sed 's/"//g' | \
|
||||||
|
|||||||
@@ -8,12 +8,25 @@ terraform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
locals {
|
||||||
|
nodes-config = {
|
||||||
|
"master" = {
|
||||||
|
base-image = var.amzn2-ami
|
||||||
|
num = 1
|
||||||
|
},
|
||||||
|
"worker" = {
|
||||||
|
base-image = var.amzn2-ami
|
||||||
|
num = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# cloud-init
|
# cloud-init
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
module "cloud-init-config" {
|
module "cloud-init-config" {
|
||||||
for_each = var.nodes-config
|
for_each = local.nodes-config
|
||||||
source = "./modules/cloud-init-config"
|
source = "./modules/cloud-init-config"
|
||||||
cloud-init-template = "${path.module}/cloud_init.cfg"
|
cloud-init-template = "${path.module}/cloud_init.cfg"
|
||||||
hostname-prefix = "${var.vm-name-prefix}-${each.key}"
|
hostname-prefix = "${var.vm-name-prefix}-${each.key}"
|
||||||
@@ -32,7 +45,8 @@ provider "aws" {
|
|||||||
region = "us-east-2"
|
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" {
|
# module "aws-amis" {
|
||||||
# source = "./modules/aws-amis"
|
# source = "./modules/aws-amis"
|
||||||
# }
|
# }
|
||||||
@@ -59,7 +73,7 @@ resource "aws_key_pair" "key" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module "nodes" {
|
module "nodes" {
|
||||||
for_each = var.nodes-config
|
for_each = local.nodes-config
|
||||||
source = "./modules/aws-nodes"
|
source = "./modules/aws-nodes"
|
||||||
ami = each.value.base-image
|
ami = each.value.base-image
|
||||||
ec2-instance-type = var.aws-ec2-instance-type
|
ec2-instance-type = var.aws-ec2-instance-type
|
||||||
@@ -85,7 +99,7 @@ module "nodes" {
|
|||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# module "nodes" {
|
# module "nodes" {
|
||||||
# for_each = var.nodes-config
|
# for_each = local.nodes-config
|
||||||
# source = "./modules/libvirt-nodes"
|
# source = "./modules/libvirt-nodes"
|
||||||
# pool-name = libvirt_pool.images.name
|
# pool-name = libvirt_pool.images.name
|
||||||
# name-prefix = "${var.vm-name-prefix}-${each.key}"
|
# name-prefix = "${var.vm-name-prefix}-${each.key}"
|
||||||
|
|||||||
+36
-5
@@ -43,11 +43,6 @@ variable "node-vcpus" {
|
|||||||
type = number
|
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" {
|
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."
|
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 +71,39 @@ variable "vm-name-prefix" {
|
|||||||
default = "k8s-tf"
|
default = "k8s-tf"
|
||||||
description = "This prefix will appear before all VM names and hostnames, ie. k8s-tf-master-0."
|
description = "This prefix will appear before all VM names and hostnames, ie. k8s-tf-master-0."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# AWS AMI vars
|
||||||
|
# These variables are really mor 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" {
|
||||||
|
default = "ami-0dd0ccab7e2801812"
|
||||||
|
description = "The AMI to use for Amazon Linux 2."
|
||||||
|
}
|
||||||
|
variable "ubuntu-ami" {
|
||||||
|
default = "ami-06c7d6c0987eaa46c"
|
||||||
|
description = "The AMI to use for Ubuntu."
|
||||||
|
}
|
||||||
|
variable "centos7-ami" {
|
||||||
|
default = "ami-00f8e2c955f7ffa9b"
|
||||||
|
description = "The AMI to use for CentOS 7."
|
||||||
|
}
|
||||||
|
variable "centos8-ami" {
|
||||||
|
default = "ami-057cacbfbbb471bb3"
|
||||||
|
description = "The AMI to use for CentOS 8."
|
||||||
|
}
|
||||||
|
variable "arch-ami" {
|
||||||
|
default = "ami-02653f06de985e3ba"
|
||||||
|
description = "The AMI to use for Arch Linux."
|
||||||
|
}
|
||||||
|
variable "rhel7-ami" {
|
||||||
|
default = "ami-0a509b3c2a4d05b3f"
|
||||||
|
description = "The AMI to use for RHEL 7."
|
||||||
|
}
|
||||||
|
variable "rhel8-ami" {
|
||||||
|
default = "ami-0d871ca8a77af2948"
|
||||||
|
description = "The AMI to use for RHEL 8."
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user