github.com/openshift/installer@v1.4.17/upi/vsphere/ipam/main.tf (about) 1 locals { 2 network = cidrhost(var.machine_cidr, 0) 3 hostnames = length(var.static_ip_addresses) == 0 ? var.hostnames : [] 4 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 5 } 6 7 data "http" "getip" { 8 for_each = null_resource.ip_address 9 10 url = "http://${var.ipam}/api/getIPs.php?apiapp=address&apitoken=${var.ipam_token}&domain=${null_resource.ip_address[each.key].triggers.hostname}" 11 12 request_headers = { 13 Accept = "application/json" 14 } 15 } 16 17 resource "null_resource" "ip_address" { 18 for_each = local.hostnames 19 20 triggers = { 21 ipam = var.ipam 22 ipam_token = var.ipam_token 23 network = local.network 24 hostname = each.key 25 } 26 27 provisioner "local-exec" { 28 command = <<EOF 29 echo '{"network":"${self.triggers.network}","hostname":"${self.triggers.hostname}","ipam":"${self.triggers.ipam}","ipam_token":"${self.triggers.ipam_token}"}' | ${path.module}/cidr_to_ip.sh 30 EOF 31 32 } 33 provisioner "local-exec" { 34 when = destroy 35 36 command = <<EOF 37 curl -s "http://${self.triggers.ipam}/api/removeHost.php?apiapp=address&apitoken=${self.triggers.ipam_token}&host=${self.triggers.hostname}" 38 EOF 39 40 } 41 }