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 = <