diff --git a/main.tf b/main.tf index 19b1c7b..e145ad1 100644 --- a/main.tf +++ b/main.tf @@ -11,20 +11,33 @@ locals { ] aws-security-group-id = module.aws-network-existing.default-sg.id # aws-security-group-id = module.aws-network-from-scratch.default-security-group.id + + # The names of these nodes is created by: + # "{var.vm-name-prefix}-{name from nodes-config}-{number}" + # The length of this full name must be < 16 characters. This is a limitaion of + # Active Directory? The "realm join" command failed when the name was too + # long, although it did not give the reason for the failure, the reason was + # surmised because it looked like it was truncating the name when attempting + # to join. nodes-config = { + # TODO if the above comment about the name length is true, then this name is + # too long. IMPORTANT! If you change this then you need to change the k8s + # ansible role that assigns roles based on wether or not 'master' is in the + # name. "k8s-master" = { base-image = var.ubuntu-ami aws-ec2-type = var.t2-medium-4gib-2vcpu subnet-ids = local.k8s-subnets-ids - num = 0 + num = 1 }, - "k8s-worker" = { + "k8s-wrkr" = { base-image = var.ubuntu-ami aws-ec2-type = var.t2-medium-4gib-2vcpu subnet-ids = local.k8s-subnets-ids - num = 0 + disk-size = 20 + num = 2 }, - "ansible-test" = { + "test" = { base-image = var.ubuntu-ami aws-ec2-type = var.t2-micro-1gib-1vcpu # subnet-ids = [module.aws-network-from-scratch.subnet.id] @@ -38,7 +51,7 @@ locals { subnet-ids = [module.aws-network-existing.subnet-by-name["subnet_4"].id] num = 1 num-disks = 1 - disk-size = 10 + zfs-disk-size = 10 }, "proxy" = { base-image = var.ubuntu-ami @@ -119,7 +132,7 @@ 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 + size = local.nodes-config["nfs"].zfs-disk-size encrypted = true count = local.nodes-config["nfs"].num-disks tags = { @@ -147,12 +160,27 @@ module "nodes" { 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 + disk-size = try(each.value.disk-size, null) 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. } +# TODO an attempt to create a windows machine. +# module "nodes-win" { +# source = "./modules/aws-nodes" +# ec2-instance-type = var.t2-small-2gib-1vcpu +# ami = var.win-srv-2019-ami +# subnet-ids = [module.aws-network-existing.subnet-by-name["subnet_2"].id] +# private-ips = [] +# security-group-ids = [local.aws-security-group-id] +# # TODO REM need to figure out how to not pass a user data. +# user-datas = [null] +# num-nodes = 1 +# name-prefix = "${var.vm-name-prefix}-win-test" +# } + ################################################################################ # end aws ################################################################################ diff --git a/modules/aws-amis/main.tf b/modules/aws-amis/main.tf index 8cb82d8..37989ff 100644 --- a/modules/aws-amis/main.tf +++ b/modules/aws-amis/main.tf @@ -48,7 +48,14 @@ locals { # us-gov-west-1 owner-id = "219670896067" name = "RHEL-8.*HVM*x86_64*GP2" - } + }, + win-srv-2019 = { + # us-east-2 + # owner-id = "???" + # us-gov-west-1 + owner-id = "077303321853" + name = "Windows_Server-2019-English-Full-Base*" + }, } } diff --git a/modules/aws-nodes/main.tf b/modules/aws-nodes/main.tf index 1b994b7..a3f9873 100644 --- a/modules/aws-nodes/main.tf +++ b/modules/aws-nodes/main.tf @@ -8,8 +8,12 @@ resource "aws_instance" "nodes" { # 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 + user_data = element(var.user-datas.*.rendered, count.index) + root_block_device { + volume_size = var.disk-size + delete_on_termination = true + } + count = var.num-nodes tags = { Name = "${var.name-prefix}-${count.index}" diff --git a/modules/aws-nodes/variables.tf b/modules/aws-nodes/variables.tf index 9eec3f0..0476f5b 100644 --- a/modules/aws-nodes/variables.tf +++ b/modules/aws-nodes/variables.tf @@ -1,30 +1,36 @@ variable "ami" { description = "The AWS AMI to be used for all the nodes" - type = string + type = string +} + +variable "disk-size" { + default = 8 + description = "The size of the root FS disk in GB." + type = number } variable "ec2-instance-type" { - default = "t2.micro" + default = "t2.micro" description = "The AWS instance type to use for all nodes." - type = string + type = string } variable "name-prefix" { - default = "tf-node" + default = "tf-node" description = "This prefix will be applied to all names created by this module." - type = string + type = string } variable "num-nodes" { - default = 1 + default = 1 description = "The number of nodes to create from the given input parameters." - type = number + type = number } variable "private-ips" { - default = [] + 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) + type = list(string) } variable "user-datas" { @@ -33,10 +39,10 @@ variable "user-datas" { 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) + type = list(string) } variable "security-group-ids" { description = "A list of security group IDs to be applied to all the nodes." - type = list(string) + type = list(string) } diff --git a/variables.tf b/variables.tf index cd083b4..c84adb0 100644 --- a/variables.tf +++ b/variables.tf @@ -122,14 +122,14 @@ variable "amzn2-ami" { # us-east-2 # default = "ami-0dd0ccab7e2801812" # us-gov-west-1 - default = "ami-098bf51d9a35299f0" + default = "ami-02ab588324a95cf31" 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" + default = "ami-066189aeb91baa0ab" description = "The AMI to use for Ubuntu." } variable "centos7-ami" { @@ -161,6 +161,13 @@ variable "rhel8-ami" { default = "ami-0b1f10cd1cd107dd2" description = "The AMI to use for RHEL 8." } +variable "win-srv-2019-ami" { + # us-east-2 + # default = ??? + # us-gov-west-1 + default = "ami-0f838c3c35ab60fc4" + description = "The AMI to use for Windows Server 2019." +} ################################################################################ # AWS EC2 types. @@ -173,6 +180,11 @@ variable "t2-micro-1gib-1vcpu" { default = "t2.micro" } +variable "t2-small-2gib-1vcpu" { + description = "t2.small EC2 instance with 2 GiB mem and 1 vCPUs." + default = "t2.small" +} + variable "t2-medium-4gib-2vcpu" { description = "t2.medium EC2 instance with 4 GiB mem and 2 vCPUs." default = "t2.medium"