From e3b15f952c716e314de4eed1ad8e53e053479f87 Mon Sep 17 00:00:00 2001 From: shnee Date: Fri, 12 Nov 2021 18:31:01 -0500 Subject: [PATCH] Created aws-node module. --- main.tf | 61 +++++++++++++++++++++++++++++++--------------------- variables.tf | 2 +- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/main.tf b/main.tf index 5bb2c7b..c41a45d 100644 --- a/main.tf +++ b/main.tf @@ -40,25 +40,34 @@ data "template_file" "node-user-datas" { count = var.master-nodes } -resource "aws_instance" "test-node" { - ami = var.base-image - instance_type = var.aws-ec2-instance-type - # key_name = aws_key_pair.debug1.key_name - associate_public_ip_address = true - subnet_id = module.aws-network.subnet.id - vpc_security_group_ids = [module.aws-network.default-security-group.id] - user_data = element(data.template_file.node-user-datas.*.rendered, count.index) - count = var.master-nodes - - tags = { - Name = "${var.vm-name-prefix}-test" - } +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 + num-nodes = var.master-nodes + name-prefix = "${var.vm-name-prefix}-master" } -output "master-ips" { - value = aws_instance.test-node.*.public_ip +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.node-user-datas + num-nodes = var.worker-nodes + name-prefix = "${var.vm-name-prefix}-worker" } +################################################################################ +# libvirt +# To use the libvirt module, uncomment the libvirt modules/resources and comment +# out the aws modules/resources. +################################################################################ + # provider "libvirt" { # uri = var.libvirt-connection-url # } @@ -94,12 +103,16 @@ output "master-ips" { # type = "dir" # path = var.disk-image-dir # } -# -# # TODO REM move to other file? -# output "master-ips" { -# value = module.master-nodes.ips -# } -# -# output "worker-ips" { -# value = module.worker-nodes.ips -# } + +################################################################################ +# end libvirt +################################################################################ + +# TODO REM move to other file? +output "master-ips" { + value = module.master-nodes.ips +} + +output "worker-ips" { + value = module.worker-nodes.ips +} diff --git a/variables.tf b/variables.tf index 3455efa..52cf7a2 100644 --- a/variables.tf +++ b/variables.tf @@ -15,7 +15,7 @@ variable "aws-subnet-cidr-block" { variable "aws-vpc-cidr-block" { default = "10.0.0.0/16" - description = "The address space to be used for this VPC." + description = "The address space to be used for the VPC that all the AWS nodes will be in." } variable "disk-image-dir" {