taliesins / terraform-provider-hyperv

HyperV provider for Terraform
Mozilla Public License 2.0
225 stars 80 forks source link

wait_for_ips and ip_addresses does not distinguish between IPv4/6 #249

Open japicken opened 5 months ago

japicken commented 5 months ago

Terraform Version

1.7.1

Affected Resource(s)

Terraform Configuration Files

resource "hyperv_machine_instance" "vm" {
  ...

  dynamic "network_adaptors" {
    for_each = var.vm_instance.hyperv.network_adaptors

    content {
      name                     = try(network_adaptors.value.name, null)
      switch_name              = try(network_adaptors.value.switch_name, "")
      dynamic_mac_address      = try(network_adaptors.value.dynamic_mac_address, null)
      static_mac_address       = try(network_adaptors.value.static_mac_address, null)
      mac_address_spoofing     = try(network_adaptors.value.mac_address_spoofing ? "On" : "Off", "Off")
      vlan_access              = try(network_adaptors.value.vlan_access, true)
      vlan_id                  = try(network_adaptors.value.vlan_id, 392)
      vrss_enabled             = try(network_adaptors.value.vrss_enabled, null)
      vmmq_enabled             = try(network_adaptors.value.vmmq_enabled, null)
      wait_for_ips             = try(network_adaptors.value.wait_for_ips, false)
      iov_weight               = try(network_adaptors.value.iov_weight, 0)
      port_mirroring           = "None"
    }
  }

  connection {
    type     = var.vm_instance.ansible.communication_method
    port     = lookup({ winrm = 5986, ssh = 22 }, var.vm_instance.ansible.communication_method, null)
    user     = var.vm_instance.connection_username
    password = var.vm_instance.connection_password
    host     = self.network_adaptors[0].ip_addresses[0]
    https    = var.vm_instance.ansible.communication_method == "winrm" ? true : null
    insecure = var.vm_instance.ansible.communication_method == "winrm" ? true : null
    use_ntlm = var.vm_instance.ansible.communication_method == "winrm" ? true : null
    timeout  = try(var.vm_instance.ansible.initial_connection_timeout, "30m")
  }
  ...
}

Enhancement Request

This is an enhancement request, apologies if is this is not the correct way to submit one. We have a problem where sometimes self.network_adaptors[0].ip_addesses[0] contains an IPv6 address, and what we're really wanting is an IPv4 address. If there were a wait_for_ipv4 and a separate wait_for_ipv6, then maybe in addition to ip_addresses if we had an ipv4_addresses and an ipv6_addresses this would solve the issue.