diff --git a/.gitignore b/.gitignore index 7103111..71e6cdb 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ terraform.rc ################################################################################ k8s-key* -STARTHERE +*admin-key* +TARTHERE inventory diff --git a/get-vm-ips.sh b/get-vm-ips.sh index b8ab1df..7fc5178 100755 --- a/get-vm-ips.sh +++ b/get-vm-ips.sh @@ -22,6 +22,10 @@ VM_NAME_PREFIX="$( tail -n 1 | \ sed 's/^.*=\s*"\(.*\)"/\1/g')" +PUBLIC_IP_OUTPUT="groups_hostnames_ips" +PRIVATE_IP_OUTPUT="groups_hostnames_private_ips" +IP_TYPE="$PRIVATE_IP_OUTPUT" + # This command stores the output data in the format below. # [ # { @@ -48,7 +52,7 @@ VM_NAME_PREFIX="$( # } # ] DATA="$(terraform show -json | \ - jq '.values.outputs.groups_hostnames_ips.value | to_entries | + jq '.values.outputs.'"$IP_TYPE"'.value | to_entries | map({group: .key, vms:.value | to_entries | map({hostname:.key,ip:.value})})')" diff --git a/main.tf b/main.tf index 0b7b0ab..fdcc3a2 100644 --- a/main.tf +++ b/main.tf @@ -2,11 +2,11 @@ locals { nodes-config = { "master" = { - base-image = var.centos8-ami + base-image = var.ubuntu-ami num = 1 }, "worker" = { - base-image = var.centos8-ami + base-image = var.ubuntu-ami num = 2 } } @@ -79,8 +79,8 @@ module "nodes" { source = "./modules/aws-nodes" 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] + subnet-id = module.aws-network-existing.k8s-subnets[0] + security-group-ids = [data.aws_security_group.default.id] 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}" @@ -132,3 +132,9 @@ module "nodes" { output "groups_hostnames_ips" { value = { for type, node in module.nodes : type => zipmap(node.names, node.ips) } } + +# This will outpus a map of group => [{hostname, private_ip}]. +# TODO Figure out how what to do about private_ips for libvirt. +output "groups_hostnames_private_ips" { + value = { for type, node in module.nodes : type => zipmap(node.names, node.private_ips) } +} diff --git a/modules/aws-amis/main.tf b/modules/aws-amis/main.tf index 1949653..8cb82d8 100644 --- a/modules/aws-amis/main.tf +++ b/modules/aws-amis/main.tf @@ -1,31 +1,52 @@ locals { amis = { amzn2 = { - owner-id = "137112412989" + # us-east-2 + # owner-id = "137112412989" + # us-gov-west-1 + owner-id = "045324592363" name = "amzn2-ami-hvm-2*x86_64-gp2" }, ubuntu = { - owner-id = "099720109477" + # us-east-2 + # owner-id = "099720109477" + # us-gov-west-1 + owner-id = "513442679011" name = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*" }, - centos7 = { - owner-id = "125523088429" - name = "CentOS 7.*x86_64" - }, - centos8 = { - owner-id = "125523088429" - name = "CentOS 8.*x86_64" - }, - arch = { - owner-id = "093273469852" - name = "arch-linux-lts-hvm*x86_64-ebs" - }, + # centos7 = { + # # us-east-2 + # # owner-id = "125523088429" + # # us-gov-west-1 + # # owner-id = THERE IS NO CENTOS7 IMAGE in us-gov-west-1!! + # name = "CentOS 7.*x86_64" + # }, + # centos8 = { + # # us-east-2 + # # owner-id = "125523088429" + # # us-gov-west-1 + # # owner-id = THERE IS NO CENTOS8 IMAGE in us-gov-west-1!! + # name = "CentOS 8.*x86_64" + # }, + # arch = { + # # us-east-2 + # # owner-id = "093273469852" + # # us-gov-west-1 + # # owner-id = THERE IS NO ARCH IMAGE in us-gov-west-1!! + # name = "arch-linux-lts-hvm*x86_64-ebs" + # }, rhel7 = { - owner-id = "309956199498" + # us-east-2 + # owner-id = "309956199498" + # us-gov-west-1 + owner-id = "219670896067" name = "RHEL-7.*HVM*x86_64*GP2" }, rhel8 = { - owner-id = "309956199498" + # us-east-2 + # owner-id = "309956199498" + # us-gov-west-1 + owner-id = "219670896067" name = "RHEL-8.*HVM*x86_64*GP2" } } diff --git a/modules/aws-nodes/main.tf b/modules/aws-nodes/main.tf index 282a488..8a0f793 100644 --- a/modules/aws-nodes/main.tf +++ b/modules/aws-nodes/main.tf @@ -3,6 +3,7 @@ resource "aws_instance" "nodes" { instance_type = var.ec2-instance-type # TODO REM double check this key. # key_name = aws_key_pair.debug1.key_name + # TODO Make this a variable. associate_public_ip_address = true subnet_id = var.subnet-id vpc_security_group_ids = var.security-group-ids diff --git a/modules/aws-nodes/outputs.tf b/modules/aws-nodes/outputs.tf index 0b4fe7c..ac1ae29 100644 --- a/modules/aws-nodes/outputs.tf +++ b/modules/aws-nodes/outputs.tf @@ -2,6 +2,10 @@ output "ips" { value = aws_instance.nodes.*.public_ip } +output "private_ips" { + value = aws_instance.nodes.*.private_ip +} + output "names" { value = aws_instance.nodes.*.tags.Name } diff --git a/variables.tf b/variables.tf index aa13de2..94c8bd6 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,5 @@ variable "admin-ips" { + default = ["0.0.0.0/0"] description = "A list of ips or cidr blocks that are allowed to connect to the nodes." type = list(string) } @@ -33,6 +34,7 @@ variable "disk-image-pool-name" { } variable "libvirt-connection-url" { + default = "nobody@localhost" description = "The libvirt connection URI, ie. qemu+ssh://@/system" } @@ -95,31 +97,46 @@ variable "vm-name-prefix" { ################################################################################ variable "amzn2-ami" { - default = "ami-0dd0ccab7e2801812" + # us-east-2 + # default = "ami-0dd0ccab7e2801812" + # us-gov-west-1 + default = "ami-098bf51d9a35299f0" description = "The AMI to use for Amazon Linux 2." } variable "ubuntu-ami" { - default = "ami-06c7d6c0987eaa46c" + # us-east-2 + # default = "ami-06c7d6c0987eaa46c" + # us-gov-west-1 + default = "ami-087ee83c8de303181" description = "The AMI to use for Ubuntu." } variable "centos7-ami" { + # us-east-2 default = "ami-00f8e2c955f7ffa9b" description = "The AMI to use for CentOS 7." } variable "centos8-ami" { + # us-east-2 default = "ami-057cacbfbbb471bb3" description = "The AMI to use for CentOS 8." } variable "arch-ami" { + # us-east-2 default = "ami-02653f06de985e3ba" description = "The AMI to use for Arch Linux." } variable "rhel7-ami" { - default = "ami-0a509b3c2a4d05b3f" + # us-east-2 + # default = "ami-0a509b3c2a4d05b3f" + # us-gov-west-1 + default = "ami-04ccdf5793086ea95" description = "The AMI to use for RHEL 7." } variable "rhel8-ami" { - default = "ami-0d871ca8a77af2948" + # us-east-2 + # default = "ami-0d871ca8a77af2948" + # us-gov-west-1 + default = "ami-0b1f10cd1cd107dd2" description = "The AMI to use for RHEL 8." }