github.com/openshift/installer@v1.4.17/upi/vsphere/main.tf (about)

     1  
     2  locals {
     3    failure_domains     = length(var.failure_domains) == 0 ? [{
     4          datacenter = var.vsphere_datacenter
     5          cluster = var.vsphere_cluster
     6          datastore = var.vsphere_datastore
     7          network = var.vm_network
     8          distributed_virtual_switch_uuid = ""
     9    }] : var.failure_domains
    10  
    11    failure_domain_count = length(local.failure_domains)
    12    bootstrap_fqdns     = ["bootstrap-0.${var.cluster_domain}"]
    13    lb_fqdns            = ["lb-0.${var.cluster_domain}"]
    14    api_lb_fqdns        = formatlist("%s.%s", ["api", "api-int", "*.apps"], var.cluster_domain)
    15    control_plane_fqdns = [for idx in range(var.control_plane_count) : "control-plane-${idx}.${var.cluster_domain}"]
    16    compute_fqdns       = [for idx in range(var.compute_count) : "compute-${idx}.${var.cluster_domain}"]
    17    datastores          = [for idx in range(length(local.failure_domains)) : local.failure_domains[idx]["datastore"]]
    18    datacenters         = [for idx in range(length(local.failure_domains)) : local.failure_domains[idx]["datacenter"]]
    19    datacenters_distinct = distinct([for idx in range(length(local.failure_domains)) : local.failure_domains[idx]["datacenter"]])
    20    clusters            = [for idx in range(length(local.failure_domains)) : local.failure_domains[idx]["cluster"]]
    21    networks            = [for idx in range(length(local.failure_domains)) : local.failure_domains[idx]["cluster"]]
    22    folders             = [for idx in range(length(local.datacenters)) : "/${local.datacenters[idx]}/vm/${var.cluster_id}"]
    23  }
    24  
    25  provider "vsphere" {
    26    user                 = var.vsphere_user
    27    password             = var.vsphere_password
    28    vsphere_server       = var.vsphere_server
    29    allow_unverified_ssl = true
    30  }
    31  
    32  data "vsphere_datacenter" "dc" {
    33     count = length(local.datacenters_distinct)
    34     name = local.datacenters_distinct[count.index]
    35  }
    36  
    37  data "vsphere_compute_cluster" "compute_cluster" {
    38     count = length(local.failure_domains)
    39     name = local.clusters[count.index]
    40     datacenter_id = data.vsphere_datacenter.dc[index(data.vsphere_datacenter.dc.*.name, local.datacenters[count.index])].id
    41  }
    42  # 
    43  data "vsphere_datastore" "datastore" {
    44     count = length(local.failure_domains)
    45     name = local.datastores[count.index]
    46     datacenter_id = data.vsphere_datacenter.dc[index(data.vsphere_datacenter.dc.*.name, local.datacenters[count.index])].id
    47  }
    48  
    49  # 
    50  data "vsphere_network" "network" {
    51    count = length(local.failure_domains)
    52    name          = local.failure_domains[count.index]["network"]
    53    datacenter_id = data.vsphere_datacenter.dc[index(data.vsphere_datacenter.dc.*.name, local.failure_domains[count.index]["datacenter"])].id
    54    distributed_virtual_switch_uuid = local.failure_domains[count.index]["distributed_virtual_switch_uuid"]
    55  }
    56   
    57  data "vsphere_virtual_machine" "template" {
    58    count = length(local.datacenters_distinct)
    59    name          = var.vm_template
    60    datacenter_id = data.vsphere_datacenter.dc[index(data.vsphere_datacenter.dc.*.name, local.datacenters_distinct[count.index])].id
    61  }
    62   
    63  resource "vsphere_resource_pool" "resource_pool" {
    64    count                   = length(data.vsphere_compute_cluster.compute_cluster)
    65    name                    = var.cluster_id
    66    parent_resource_pool_id = data.vsphere_compute_cluster.compute_cluster[count.index].resource_pool_id
    67  }
    68   
    69  resource "vsphere_folder" "folder" {
    70    count = length(local.datacenters_distinct)
    71    path          = var.cluster_id
    72    type          = "vm"  
    73    datacenter_id = data.vsphere_datacenter.dc[index(data.vsphere_datacenter.dc.*.name, local.datacenters_distinct[count.index])].id
    74  }
    75   
    76   // Request from phpIPAM a new IP address for the bootstrap node
    77   module "ipam_bootstrap" {
    78     source = "./ipam"
    79   
    80     // The hostname that will be added to phpIPAM when requesting an ip address
    81     hostnames = local.bootstrap_fqdns
    82   
    83     // Hostname or IP address of the phpIPAM server
    84     ipam = var.ipam
    85   
    86     // Access token for phpIPAM
    87     ipam_token = var.ipam_token
    88   
    89     // Subnet where we will request an ip address from phpIPAM
    90     machine_cidr = var.machine_cidr
    91   
    92     static_ip_addresses = var.bootstrap_ip_address == "" ? [] : [var.bootstrap_ip_address]
    93   
    94   }
    95   
    96   // Request from phpIPAM a new IP addresses for the control-plane nodes
    97   module "ipam_control_plane" {
    98     source              = "./ipam"
    99     hostnames           = local.control_plane_fqdns
   100     ipam                = var.ipam
   101     ipam_token          = var.ipam_token
   102     machine_cidr        = var.machine_cidr
   103     static_ip_addresses = var.control_plane_ip_addresses
   104   }
   105   
   106   // Request from phpIPAM a new IP addresses for the compute nodes
   107   module "ipam_compute" {
   108     source              = "./ipam"
   109     hostnames           = local.compute_fqdns
   110     ipam                = var.ipam
   111     ipam_token          = var.ipam_token
   112     machine_cidr        = var.machine_cidr
   113     static_ip_addresses = var.compute_ip_addresses
   114   }
   115   
   116   // Request from phpIPAM a new IP addresses for the load balancer nodes
   117   module "ipam_lb" {
   118     source              = "./ipam"
   119     hostnames           = local.lb_fqdns
   120     ipam                = var.ipam
   121     ipam_token          = var.ipam_token
   122     machine_cidr        = var.machine_cidr
   123     static_ip_addresses = var.lb_ip_address == "" ? [] : [var.lb_ip_address]
   124   }
   125   
   126   module "lb" {
   127     source        = "./lb"
   128     lb_ip_address = module.ipam_lb.ip_addresses[0]
   129   
   130     api_backend_addresses = flatten([
   131       module.ipam_bootstrap.ip_addresses[0],
   132       module.ipam_control_plane.ip_addresses]
   133     )
   134   
   135     ingress_backend_addresses = module.ipam_compute.ip_addresses
   136     ssh_public_key_path       = var.ssh_public_key_path
   137   }
   138   
   139   module "dns_cluster_domain" {
   140     source         = "./cluster_domain"
   141     cluster_domain = var.cluster_domain
   142     base_domain    = var.base_domain
   143   }
   144   
   145   module "lb_a_records" {
   146     source  = "./host_a_record"
   147     zone_id = module.dns_cluster_domain.zone_id
   148     records = zipmap(
   149       local.api_lb_fqdns,
   150       [for name in local.api_lb_fqdns : module.ipam_lb.ip_addresses[0]]
   151     )
   152   }
   153   
   154   module "control_plane_a_records" {
   155     source  = "./host_a_record"
   156     zone_id = module.dns_cluster_domain.zone_id
   157     records = zipmap(local.control_plane_fqdns, module.ipam_control_plane.ip_addresses)
   158   }
   159   
   160   module "compute_a_records" {
   161     source  = "./host_a_record"
   162     zone_id = module.dns_cluster_domain.zone_id
   163     records = zipmap(local.compute_fqdns, module.ipam_compute.ip_addresses)
   164   }
   165   
   166   module "lb_vm" {
   167     source = "./vm"   
   168     vmname                = element(split(".", local.lb_fqdns[0]), 0)
   169     ipaddress             = module.ipam_lb.ip_addresses[0]
   170     ignition               = module.lb.ignition
   171     resource_pool_id      = vsphere_resource_pool.resource_pool[0].id
   172     datastore_id          = data.vsphere_datastore.datastore[0].id
   173     datacenter_id         = data.vsphere_datacenter.dc[0].id
   174     network_id            = data.vsphere_network.network[0].id
   175     folder_id             = vsphere_folder.folder[0].path
   176     guest_id              = data.vsphere_virtual_machine.template[0].guest_id
   177     template_uuid         = data.vsphere_virtual_machine.template[0].id
   178     disk_thin_provisioned = data.vsphere_virtual_machine.template[0].disks[0].thin_provisioned
   179     cluster_domain = var.cluster_domain
   180     machine_cidr   = var.machine_cidr
   181     num_cpus      = 2
   182     memory        = 2096
   183     dns_addresses = var.vm_dns_addresses
   184   }
   185   
   186  module "bootstrap" {
   187    source = "./vm"
   188  
   189    ignition = file(var.bootstrap_ignition_path)
   190  
   191    vmname                = element(split(".", local.bootstrap_fqdns[0]), 0)
   192    ipaddress             = module.ipam_bootstrap.ip_addresses[0]
   193    resource_pool_id      = vsphere_resource_pool.resource_pool[0].id
   194    datastore_id          = data.vsphere_datastore.datastore[0].id
   195    datacenter_id         = data.vsphere_datacenter.dc[0].id
   196    network_id            = data.vsphere_network.network[0].id
   197    folder_id             = vsphere_folder.folder[0].path
   198    guest_id              = data.vsphere_virtual_machine.template[0].guest_id
   199    template_uuid         = data.vsphere_virtual_machine.template[0].id
   200    disk_thin_provisioned = data.vsphere_virtual_machine.template[0].disks[0].thin_provisioned
   201  
   202    cluster_domain = var.cluster_domain
   203    machine_cidr   = var.machine_cidr
   204  
   205    num_cpus      = 2
   206    memory        = 8192
   207    dns_addresses = var.vm_dns_addresses
   208  }
   209   
   210  module "control_plane_vm" {
   211    count = length(module.control_plane_a_records.fqdns)
   212    source = "./vm"
   213    // Using the output from control_plane_a_records
   214    // is on purpose. I want the A records to be created before
   215    // the virtual machines which gives additional time to
   216    // replicate the records.
   217  
   218  
   219    vmname = element(split(".", module.control_plane_a_records.fqdns[count.index]), 0)
   220    ipaddress = module.ipam_control_plane.ip_addresses[count.index]
   221    ignition = file(var.control_plane_ignition_path)
   222    resource_pool_id      = vsphere_resource_pool.resource_pool[count.index % local.failure_domain_count].id
   223    datastore_id          = data.vsphere_datastore.datastore[count.index % local.failure_domain_count].id
   224    datacenter_id         = data.vsphere_datacenter.dc[index(data.vsphere_datacenter.dc.*.name, local.failure_domains[count.index % local.failure_domain_count]["datacenter"])].id
   225    network_id            = data.vsphere_network.network[count.index % local.failure_domain_count].id
   226    folder_id             = vsphere_folder.folder[index(data.vsphere_datacenter.dc.*.name, local.failure_domains[count.index % local.failure_domain_count]["datacenter"])].path
   227    guest_id              = data.vsphere_virtual_machine.template[index(data.vsphere_datacenter.dc.*.name, local.failure_domains[count.index % local.failure_domain_count]["datacenter"])].guest_id
   228    template_uuid         = data.vsphere_virtual_machine.template[index(data.vsphere_datacenter.dc.*.name, local.failure_domains[count.index % local.failure_domain_count ]["datacenter"])].id
   229    disk_thin_provisioned = data.vsphere_virtual_machine.template[index(data.vsphere_datacenter.dc.*.name, local.failure_domains[count.index % local.failure_domain_count]["datacenter"])].disks[0].thin_provisioned
   230    cluster_domain = var.cluster_domain
   231    machine_cidr   = var.machine_cidr
   232    num_cpus      = var.control_plane_num_cpus
   233    memory        = var.control_plane_memory
   234    dns_addresses = var.vm_dns_addresses
   235  }
   236  module "compute_vm" {
   237    count = length(module.compute_a_records.fqdns)
   238    source = "./vm"
   239    ignition = file(var.compute_ignition_path)
   240    vmname = element(split(".", module.compute_a_records.fqdns[count.index]), 0)
   241    ipaddress = module.ipam_compute.ip_addresses[count.index]
   242  
   243    resource_pool_id      = vsphere_resource_pool.resource_pool[count.index % local.failure_domain_count].id
   244    datastore_id          = data.vsphere_datastore.datastore[count.index % local.failure_domain_count].id
   245    datacenter_id         = data.vsphere_datacenter.dc[index(data.vsphere_datacenter.dc.*.name, local.failure_domains[count.index % local.failure_domain_count]["datacenter"])].id
   246    network_id            = data.vsphere_network.network[count.index % local.failure_domain_count].id
   247    folder_id             = vsphere_folder.folder[index(data.vsphere_datacenter.dc.*.name, local.failure_domains[count.index % local.failure_domain_count]["datacenter"])].path
   248    guest_id              = data.vsphere_virtual_machine.template[index(data.vsphere_datacenter.dc.*.name, local.failure_domains[count.index % local.failure_domain_count]["datacenter"])].guest_id
   249    template_uuid         = data.vsphere_virtual_machine.template[index(data.vsphere_datacenter.dc.*.name, local.failure_domains[count.index % local.failure_domain_count]["datacenter"])].id
   250    disk_thin_provisioned = data.vsphere_virtual_machine.template[index(data.vsphere_datacenter.dc.*.name, local.failure_domains[count.index % local.failure_domain_count]["datacenter"])].disks[0].thin_provisioned
   251    cluster_domain = var.cluster_domain
   252    machine_cidr   = var.machine_cidr
   253    num_cpus      = var.compute_num_cpus
   254    memory        = var.compute_memory
   255    dns_addresses = var.vm_dns_addresses
   256  }