From 27c03c8ead0ebd13efdde0d0c2498194be651b8e Mon Sep 17 00:00:00 2001 From: Joseph Callen Date: Wed, 8 Apr 2020 12:47:02 -0400 Subject: [PATCH] vsphere upi: terraform update, general updates and reorg - Update to terraform 0.12.x - ipam moved to a module and updated for 0.12 - creation of vsphere objects moved to module - removal of etcd dns records - domain dns records separated from creating rhcos node a records - create load balancer using openshift haproxy image and an additional rhcos virtual machine - create dns A record for lb ip and api, api-int, *.apps - change virtual machine ignition extra config to file path string vs ignition string. Simplifies bootstrap and other instance configuration - Updated Dockerfile CI UPI image for 0.12.24 --- images/installer/Dockerfile.upi.ci | 2 +- upi/vsphere/cluster_domain/main.tf | 22 ++ upi/vsphere/cluster_domain/outputs.tf | 3 + upi/vsphere/cluster_domain/variables.tf | 9 + upi/vsphere/folder/main.tf | 5 - upi/vsphere/folder/output.tf | 3 - upi/vsphere/folder/variables.tf | 7 - upi/vsphere/host_a_record/main.tf | 9 + upi/vsphere/host_a_record/outputs.tf | 3 + upi/vsphere/host_a_record/variables.tf | 9 + upi/vsphere/{machine => ipam}/cidr_to_ip.sh | 6 +- upi/vsphere/ipam/main.tf | 41 +++ upi/vsphere/ipam/outputs.tf | 3 + upi/vsphere/ipam/variables.tf | 20 ++ upi/vsphere/ipam/versions.tf | 3 + upi/vsphere/lb/haproxy.service | 20 ++ upi/vsphere/lb/haproxy.tmpl | 55 ++++ upi/vsphere/lb/main.tf | 29 ++ upi/vsphere/lb/outputs.tf | 4 + upi/vsphere/lb/variables.tf | 15 + upi/vsphere/machine/ignition.tf | 79 ----- upi/vsphere/machine/ip.tf | 42 --- upi/vsphere/machine/main.tf | 51 ---- upi/vsphere/machine/output.tf | 3 - upi/vsphere/machine/variables.tf | 68 ----- upi/vsphere/main.tf | 306 +++++++++++++++----- upi/vsphere/resource_pool/main.tf | 9 - upi/vsphere/resource_pool/output.tf | 3 - upi/vsphere/resource_pool/variables.tf | 11 - upi/vsphere/route53/main.tf | 92 ------ upi/vsphere/route53/variables.tf | 33 --- upi/vsphere/variables.tf | 175 ++++++----- upi/vsphere/vm/ifcfg.tmpl | 12 + upi/vsphere/vm/ignition.tf | 47 +++ upi/vsphere/vm/main.tf | 36 +++ upi/vsphere/vm/variables.tf | 61 ++++ upi/vsphere/vm/versions.tf | 3 + 37 files changed, 731 insertions(+), 568 deletions(-) create mode 100644 upi/vsphere/cluster_domain/main.tf create mode 100644 upi/vsphere/cluster_domain/outputs.tf create mode 100644 upi/vsphere/cluster_domain/variables.tf delete mode 100644 upi/vsphere/folder/main.tf delete mode 100644 upi/vsphere/folder/output.tf delete mode 100644 upi/vsphere/folder/variables.tf create mode 100644 upi/vsphere/host_a_record/main.tf create mode 100644 upi/vsphere/host_a_record/outputs.tf create mode 100644 upi/vsphere/host_a_record/variables.tf rename upi/vsphere/{machine => ipam}/cidr_to_ip.sh (99%) create mode 100644 upi/vsphere/ipam/main.tf create mode 100644 upi/vsphere/ipam/outputs.tf create mode 100644 upi/vsphere/ipam/variables.tf create mode 100644 upi/vsphere/ipam/versions.tf create mode 100644 upi/vsphere/lb/haproxy.service create mode 100644 upi/vsphere/lb/haproxy.tmpl create mode 100644 upi/vsphere/lb/main.tf create mode 100644 upi/vsphere/lb/outputs.tf create mode 100644 upi/vsphere/lb/variables.tf delete mode 100644 upi/vsphere/machine/ignition.tf delete mode 100644 upi/vsphere/machine/ip.tf delete mode 100644 upi/vsphere/machine/main.tf delete mode 100644 upi/vsphere/machine/output.tf delete mode 100644 upi/vsphere/machine/variables.tf delete mode 100644 upi/vsphere/resource_pool/main.tf delete mode 100644 upi/vsphere/resource_pool/output.tf delete mode 100644 upi/vsphere/resource_pool/variables.tf delete mode 100644 upi/vsphere/route53/main.tf delete mode 100644 upi/vsphere/route53/variables.tf create mode 100644 upi/vsphere/vm/ifcfg.tmpl create mode 100644 upi/vsphere/vm/ignition.tf create mode 100644 upi/vsphere/vm/main.tf create mode 100644 upi/vsphere/vm/variables.tf create mode 100644 upi/vsphere/vm/versions.tf diff --git a/images/installer/Dockerfile.upi.ci b/images/installer/Dockerfile.upi.ci index bfad7d212f..4c9067996b 100644 --- a/images/installer/Dockerfile.upi.ci +++ b/images/installer/Dockerfile.upi.ci @@ -30,7 +30,7 @@ RUN yum install --setopt=tsflags=nodocs -y \ yum clean all && rm -rf /var/cache/yum/* && \ chmod g+w /etc/passwd -ENV TERRAFORM_VERSION=0.11.11 +ENV TERRAFORM_VERSION=0.12.24 RUN curl -O https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \ unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /bin/ ENV MATCHBOX_VERSION=v0.2.3 diff --git a/upi/vsphere/cluster_domain/main.tf b/upi/vsphere/cluster_domain/main.tf new file mode 100644 index 0000000000..26814e8150 --- /dev/null +++ b/upi/vsphere/cluster_domain/main.tf @@ -0,0 +1,22 @@ +data "aws_route53_zone" "base" { + name = var.base_domain +} + +resource "aws_route53_zone" "cluster" { + name = var.cluster_domain + force_destroy = true + + tags = { + "Name" = var.cluster_domain + "Platform" = "vSphere" + } +} + +resource "aws_route53_record" "name_server" { + name = var.cluster_domain + type = "NS" + ttl = "300" + zone_id = data.aws_route53_zone.base.zone_id + records = aws_route53_zone.cluster.name_servers +} + diff --git a/upi/vsphere/cluster_domain/outputs.tf b/upi/vsphere/cluster_domain/outputs.tf new file mode 100644 index 0000000000..ef8db09d4c --- /dev/null +++ b/upi/vsphere/cluster_domain/outputs.tf @@ -0,0 +1,3 @@ +output "zone_id" { + value = aws_route53_zone.cluster.zone_id +} diff --git a/upi/vsphere/cluster_domain/variables.tf b/upi/vsphere/cluster_domain/variables.tf new file mode 100644 index 0000000000..83699e5c09 --- /dev/null +++ b/upi/vsphere/cluster_domain/variables.tf @@ -0,0 +1,9 @@ +variable "cluster_domain" { + description = "The domain for the cluster that all DNS records must belong" + type = string +} + +variable "base_domain" { + description = "The base domain used for public records." + type = string +} diff --git a/upi/vsphere/folder/main.tf b/upi/vsphere/folder/main.tf deleted file mode 100644 index 6f5605846f..0000000000 --- a/upi/vsphere/folder/main.tf +++ /dev/null @@ -1,5 +0,0 @@ -resource "vsphere_folder" "folder" { - path = "${var.path}" - type = "vm" - datacenter_id = "${var.datacenter_id}" -} diff --git a/upi/vsphere/folder/output.tf b/upi/vsphere/folder/output.tf deleted file mode 100644 index d20b194905..0000000000 --- a/upi/vsphere/folder/output.tf +++ /dev/null @@ -1,3 +0,0 @@ -output "path" { - value = "${vsphere_folder.folder.path}" -} diff --git a/upi/vsphere/folder/variables.tf b/upi/vsphere/folder/variables.tf deleted file mode 100644 index a02bf0cfbc..0000000000 --- a/upi/vsphere/folder/variables.tf +++ /dev/null @@ -1,7 +0,0 @@ -variable "path" { - type = "string" -} - -variable "datacenter_id" { - type = "string" -} diff --git a/upi/vsphere/host_a_record/main.tf b/upi/vsphere/host_a_record/main.tf new file mode 100644 index 0000000000..8ffa864c06 --- /dev/null +++ b/upi/vsphere/host_a_record/main.tf @@ -0,0 +1,9 @@ +resource "aws_route53_record" "a_record" { + for_each = var.records + + type = "A" + ttl = "60" + zone_id = var.zone_id + name = each.key + records = [each.value] +} diff --git a/upi/vsphere/host_a_record/outputs.tf b/upi/vsphere/host_a_record/outputs.tf new file mode 100644 index 0000000000..091a402885 --- /dev/null +++ b/upi/vsphere/host_a_record/outputs.tf @@ -0,0 +1,3 @@ +output "fqdns" { + value = values(aws_route53_record.a_record)[*].name +} diff --git a/upi/vsphere/host_a_record/variables.tf b/upi/vsphere/host_a_record/variables.tf new file mode 100644 index 0000000000..710ed1e1fd --- /dev/null +++ b/upi/vsphere/host_a_record/variables.tf @@ -0,0 +1,9 @@ +variable "zone_id" { + type = string + description = "The ID of the hosted zone to contain this record." +} + +variable "records" { + type = map(string) + description = "A records to be added to the zone_id" +} diff --git a/upi/vsphere/machine/cidr_to_ip.sh b/upi/vsphere/ipam/cidr_to_ip.sh similarity index 99% rename from upi/vsphere/machine/cidr_to_ip.sh rename to upi/vsphere/ipam/cidr_to_ip.sh index 9bfb742d7b..11cd84a3d6 100755 --- a/upi/vsphere/machine/cidr_to_ip.sh +++ b/upi/vsphere/ipam/cidr_to_ip.sh @@ -1,5 +1,5 @@ #!/bin/bash -# cidr_to_ip - +# cidr_to_ip - # https://www.terraform.io/docs/providers/external/data_source.html # Based on info from here: https://gist.github.com/irvingpop/968464132ded25a206ced835d50afa6b # This script takes requests an IP address from an IPAM server @@ -58,11 +58,11 @@ function produce_output() { # The verification and looping is a crude way of overcoming the lack of # currency safety in the IPAM server. while [[ $SECONDS -lt $timeout ]] - do + do ip_address=$(curl -s "http://$ipam/api/getFreeIP.php?apiapp=address&apitoken=$ipam_token&subnet=${network}&host=${hostname}") if [[ "$(is_ip_address "${ip_address}")" != "true" ]]; then error_exit "could not reserve an IP address: ${ip_address}"; fi - + if [[ "$ip_address" == "$(get_reservation)" ]] then jq -n \ diff --git a/upi/vsphere/ipam/main.tf b/upi/vsphere/ipam/main.tf new file mode 100644 index 0000000000..13501ea961 --- /dev/null +++ b/upi/vsphere/ipam/main.tf @@ -0,0 +1,41 @@ +locals { + network = cidrhost(var.machine_cidr, 0) + hostnames = length(var.static_ip_addresses) == 0 ? var.hostnames : [] + ip_addresses = length(var.static_ip_addresses) == 0 ? [for result in null_resource.ip_address : jsondecode(data.http.getip[result.triggers.hostname].body)[result.triggers.hostname]] : var.static_ip_addresses +} + +data "http" "getip" { + for_each = null_resource.ip_address + + url = "http://${var.ipam}/api/getIPs.php?apiapp=address&apitoken=${var.ipam_token}&domain=${null_resource.ip_address[each.key].triggers.hostname}" + + request_headers = { + Accept = "application/json" + } +} + +resource "null_resource" "ip_address" { + for_each = local.hostnames + + triggers = { + ipam = var.ipam + ipam_token = var.ipam_token + network = local.network + hostname = each.key + } + + provisioner "local-exec" { + command = <