diff --git a/images/installer/Dockerfile.upi.ci b/images/installer/Dockerfile.upi.ci index bfad7d212f2..1cf92829a05 100644 --- a/images/installer/Dockerfile.upi.ci +++ b/images/installer/Dockerfile.upi.ci @@ -30,13 +30,13 @@ 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 -RUN curl -L -O https://github.com/poseidon/terraform-provider-matchbox/releases/download/${MATCHBOX_VERSION}/terraform-provider-matchbox-${MATCHBOX_VERSION}-linux-amd64.tar.gz && \ - tar xzf terraform-provider-matchbox-${MATCHBOX_VERSION}-linux-amd64.tar.gz && \ - mv terraform-provider-matchbox-${MATCHBOX_VERSION}-linux-amd64/terraform-provider-matchbox /bin/terraform-provider-matchbox +ENV MATCHBOX_PROVIDER_VERSION=v0.3.0 +RUN curl -L -O https://github.com/poseidon/terraform-provider-matchbox/releases/download/${MATCHBOX_PROVIDER_VERSION}/terraform-provider-matchbox-${MATCHBOX_PROVIDER_VERSION}-linux-amd64.tar.gz && \ + tar xzf terraform-provider-matchbox-${MATCHBOX_PROVIDER_VERSION}-linux-amd64.tar.gz && \ + mv terraform-provider-matchbox-${MATCHBOX_PROVIDER_VERSION}-linux-amd64/terraform-provider-matchbox /bin/terraform-provider-matchbox RUN curl -L -O https://github.com/vmware/govmomi/releases/download/v0.20.0/govc_linux_amd64.gz && \ gzip -d govc_linux_amd64.gz && \ chmod +x govc_linux_amd64 && mv govc_linux_amd64 /bin/govc diff --git a/upi/metal/bootstrap/matchbox.tf b/upi/metal/bootstrap/matchbox.tf index 9d8ae8e16ad..f2f26e20bcb 100644 --- a/upi/metal/bootstrap/matchbox.tf +++ b/upi/metal/bootstrap/matchbox.tf @@ -1,25 +1,25 @@ resource "matchbox_profile" "bootstrap" { name = "${var.cluster_id}-bootstrap" - kernel = "${var.pxe_kernel}" + kernel = var.pxe_kernel initrd = [ - "${var.pxe_initrd}", + var.pxe_initrd, ] - args = [ - "${var.pxe_kernel_args}", - "coreos.inst.ignition_url=${var.matchbox_http_endpoint}/ignition?cluster_id=${var.cluster_id}&role=bootstrap", - ] + args = concat( + var.pxe_kernel_args, + ["coreos.inst.ignition_url=${var.matchbox_http_endpoint}/ignition?cluster_id=${var.cluster_id}&role=bootstrap"], + ) - raw_ignition = "${var.igntion_config_content}" + raw_ignition = var.igntion_config_content } resource "matchbox_group" "bootstrap" { name = "${var.cluster_id}-bootstrap" - profile = "${matchbox_profile.bootstrap.name}" + profile = matchbox_profile.bootstrap.name - selector { - cluster_id = "${var.cluster_id}" + selector = { + cluster_id = var.cluster_id role = "bootstrap" } } diff --git a/upi/metal/bootstrap/outputs.tf b/upi/metal/bootstrap/outputs.tf index 1d08a6a0fb9..a875c322eb8 100644 --- a/upi/metal/bootstrap/outputs.tf +++ b/upi/metal/bootstrap/outputs.tf @@ -1,11 +1,11 @@ output "device_ip" { - value = "${packet_device.bootstrap.network.0.address}" + value = packet_device.bootstrap.network[0].address } output "device_hostname" { - value = "${packet_device.bootstrap.hostname}" + value = packet_device.bootstrap.hostname } output "device_id" { - value = "${packet_device.bootstrap.id}" + value = packet_device.bootstrap.id } diff --git a/upi/metal/bootstrap/packet.tf b/upi/metal/bootstrap/packet.tf index e779b832cad..5f985988264 100644 --- a/upi/metal/bootstrap/packet.tf +++ b/upi/metal/bootstrap/packet.tf @@ -1,11 +1,11 @@ resource "packet_device" "bootstrap" { hostname = "${var.cluster_id}-bootstrap" plan = "c1.small.x86" - facilities = ["${var.packet_facility}"] + facilities = [var.packet_facility] operating_system = "custom_ipxe" ipxe_script_url = "${var.matchbox_http_endpoint}/ipxe?cluster_id=${var.cluster_id}&role=bootstrap" billing_cycle = "hourly" - project_id = "${var.packet_project_id}" + project_id = var.packet_project_id - depends_on = ["matchbox_group.bootstrap"] + depends_on = [matchbox_group.bootstrap] } diff --git a/upi/metal/bootstrap/variables.tf b/upi/metal/bootstrap/variables.tf index eb131e3ca65..bb5848d8883 100644 --- a/upi/metal/bootstrap/variables.tf +++ b/upi/metal/bootstrap/variables.tf @@ -1,31 +1,31 @@ variable "pxe_kernel" { - type = "string" + type = string } variable "pxe_initrd" { - type = "string" + type = string } variable "pxe_kernel_args" { - type = "list" + type = list(string) } variable "matchbox_http_endpoint" { - type = "string" + type = string } variable "cluster_id" { - type = "string" + type = string } variable "igntion_config_content" { - type = "string" + type = string } variable "packet_facility" { - type = "string" + type = string } variable "packet_project_id" { - type = "string" + type = string } diff --git a/upi/metal/config.tf b/upi/metal/config.tf index 168f9bfa70d..b6435fdb8c0 100644 --- a/upi/metal/config.tf +++ b/upi/metal/config.tf @@ -1,51 +1,56 @@ # ================COMMON===================== variable "cluster_id" { - type = "string" + type = string description = < 0 ? 1 : 0 - zone_id = "${data.aws_route53_zone.public.zone_id}" + zone_id = data.aws_route53_zone.public.zone_id type = "A" ttl = "60" name = "*.apps.${var.cluster_domain}" - records = ["${local.worker_public_ipv4}"] + records = local.worker_public_ipv4 } resource "aws_route53_record" "etcd_a_nodes" { - count = "${var.master_count}" - zone_id = "${data.aws_route53_zone.public.zone_id}" + count = var.master_count + zone_id = data.aws_route53_zone.public.zone_id type = "A" ttl = "60" name = "etcd-${count.index}.${var.cluster_domain}" - records = ["${local.master_public_ipv4[count.index]}"] + records = [local.master_public_ipv4[count.index]] } resource "aws_route53_record" "master_a_nodes" { - count = "${var.master_count}" - zone_id = "${data.aws_route53_zone.public.zone_id}" + count = var.master_count + zone_id = data.aws_route53_zone.public.zone_id type = "A" ttl = "60" name = "master-${count.index}.${var.cluster_domain}" - records = ["${local.master_public_ipv4[count.index]}"] + records = [local.master_public_ipv4[count.index]] } resource "aws_route53_record" "worker_a_nodes" { - count = "${var.worker_count}" - zone_id = "${data.aws_route53_zone.public.zone_id}" + count = var.worker_count + zone_id = data.aws_route53_zone.public.zone_id type = "A" ttl = "60" name = "worker-${count.index}.${var.cluster_domain}" - records = ["${local.worker_public_ipv4[count.index]}"] + records = [local.worker_public_ipv4[count.index]] } resource "aws_route53_record" "etcd_cluster" { - zone_id = "${data.aws_route53_zone.public.zone_id}" + zone_id = data.aws_route53_zone.public.zone_id type = "SRV" ttl = "60" name = "_etcd-server-ssl._tcp.${var.cluster_domain}" - records = ["${formatlist("0 10 2380 %s", aws_route53_record.etcd_a_nodes.*.fqdn)}"] + records = formatlist("0 10 2380 %s", aws_route53_record.etcd_a_nodes.*.fqdn) } diff --git a/upi/metal/outputs.tf b/upi/metal/outputs.tf index 9564021bfab..4f1814b59e0 100644 --- a/upi/metal/outputs.tf +++ b/upi/metal/outputs.tf @@ -1,11 +1,11 @@ output "master_ips" { - value = ["${local.master_public_ipv4}"] + value = local.master_public_ipv4 } output "worker_ips" { - value = ["${local.worker_public_ipv4}"] + value = local.worker_public_ipv4 } output "bootstrap_ip" { - value = "${module.bootstrap.device_ip}" + value = module.bootstrap.device_ip } diff --git a/upi/vsphere/cluster_domain/main.tf b/upi/vsphere/cluster_domain/main.tf new file mode 100644 index 00000000000..26814e8150e --- /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 00000000000..ef8db09d4ce --- /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 00000000000..83699e5c09c --- /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 6f5605846f1..00000000000 --- 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 d20b194905c..00000000000 --- 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 a02bf0cfbc4..00000000000 --- 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 00000000000..8ffa864c06d --- /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 00000000000..091a4028856 --- /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 00000000000..710ed1e1fdf --- /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 9bfb742d7bf..11cd84a3d6a 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 00000000000..13501ea961a --- /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 = <