From f8b894739fd433d5253120f27c1a320338445e8e Mon Sep 17 00:00:00 2001 From: shnee Date: Fri, 12 Nov 2021 20:28:12 -0500 Subject: [PATCH] Fixed cloud-init for aws. - Organized main.tf - Still need to add cloud-init as an input parameter for the libvirt module. --- main.tf | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/main.tf b/main.tf index c41a45d..cd96132 100644 --- a/main.tf +++ b/main.tf @@ -8,6 +8,36 @@ 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 +} + +################################################################################ +# aws +# To use the aws module, uncomment the aws modules/resources and comment out the +# libvirt modules/resources. +################################################################################ + provider "aws" { region = "us-east-2" } @@ -30,23 +60,13 @@ resource "aws_key_pair" "key" { } } -data "template_file" "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}-${count.index}" - } - count = var.master-nodes -} - module "master-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.node-user-datas + user-datas = data.template_file.master-node-user-datas num-nodes = var.master-nodes name-prefix = "${var.vm-name-prefix}-master" } @@ -57,11 +77,15 @@ module "worker-nodes" { 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.node-user-datas + user-datas = data.template_file.worker-node-user-datas num-nodes = var.worker-nodes name-prefix = "${var.vm-name-prefix}-worker" } +################################################################################ +# end aws +################################################################################ + ################################################################################ # libvirt # To use the libvirt module, uncomment the libvirt modules/resources and comment