hashicorp / terraform-provider-vsphere

Terraform Provider for VMware vSphere
https://registry.terraform.io/providers/hashicorp/vsphere/
Mozilla Public License 2.0
623 stars 453 forks source link

Allow ability to specify IP settings when using `customization_spec` in `r/vsphere_virtual_machine` #2079

Open flamingwasp opened 12 months ago

flamingwasp commented 12 months ago

Community Guidelines

Description

I have a vSphere VM Customization Spec that is set to Prompt User for IP Address, if I use an existing Customization spec it fails with "Error: error sending customization spec: A specified parameter was not correct: nicsettings:adapter:ip" I would like to see the ability to set custom IP settings when using customization_spec.

Use Case(s)

It would be helpful if there is a way to provide IP settings within the customization_spec when using existing vSphere specs when needing to specify static addresses.

Potential Terraform Provider Configuration

`clone {

template_uuid = data.vsphere_virtual_machine.template.id
customization_spec {
  id = data.vsphere_guest_os_customization.sysprep_adjoin.id
    network_interface {
      ipv4_address = var.server_ip_address
      ipv4_netmask = var.server_ip_subnet
    }
  ipv4_gateway = var.server_ip_gateway
}

}`

References

No response

github-actions[bot] commented 12 months ago

Hello, flamingwasp! 🖐

Thank you for submitting an issue for this provider. The issue will now enter into the issue lifecycle.

If you want to contribute to this project, please review the contributing guidelines and information on submitting pull requests.

mponton-cn commented 10 months ago

+1 on our end too. Our current customize block includes:

      // REMOVED windows_options

      network_interface {
        ipv4_address    = module.vm_ips[0].ipam_record.ipAddress
        ipv4_netmask    = local.vm_final_nics.main_subnet_mask_bits
        dns_server_list = local.dns_server_list
        dns_domain      = var.vm_domain
      }

      dynamic "network_interface" {
        for_each = { for idx, nic_idx in range(1, (length(local.vm_final_extra_nics) + 1)) : idx => nic_idx }
        content {
          ipv4_address    = module.vm_ips[network_interface.value].ipam_record.ipAddress
          ipv4_netmask    = local.vm_final_extra_nics[network_interface.key].subnet_mask_bits
          dns_server_list = local.dns_server_list
          dns_domain      = var.vm_domain
        }
      }
      ipv4_gateway = cidrhost(local.vm_final_nics.main_subnet, 1)
      timeout      = 10 # minutes

We'd like to be able to use a guest os customization spec to set the admin password and some other settings but still be able to provide the network config from Terraform, including any extra NICs and DNS settings (we deploy to multiple domains).

burnsjared0415 commented 2 months ago

i did some research on this and Terraform does not support prompts on apply or plan

To prompt for IP information during a Terraform apply or plan, you need to use Terraform's input variables rather than trying to read from standard input in Go. Terraform does not support interactive prompts from provider code during execution.

i tested other ways now to see if this is possible

based on testing we have two ways to do this, one is use

customization_spec 

with no IP info but let it set all the info outside networking or you use

  clone {
    template_uuid = data.vsphere_virtual_machine.template.id

    customize {
      linux_options {
        domain       = var.domain
        host_name    = var.host_name
        hw_clock_utc = var.hw_clock_utc
        script_text  = var.script_text
        time_zone    = var.time_zone
      }

      network_interface {
        ipv4_address = var.ip_address
        ipv4_netmask = var.subnet_mask
        ipv4_gateway = var.gateway
      }
    }
  }

and you can prompt for the ip address

mponton-cn commented 1 month ago

@burnsjared0415 To be clear, the request is not to prompt the user, it's:

I would like to see the ability to set custom IP settings when using customization_spec.

Sorry I did not reply to the request for additional information. I assumed the OP would and forgot about this. There is no need to prompt the user with Terraform. We just want to be able to provide this information in the TF code.

burnsjared0415 commented 1 month ago

I tried to write into the custom spec and have not found a call yet, i will take a look again

mponton-cn commented 1 month ago

@burnsjared0415 thanks for reopening. I know it's possible because we used to rely on a custom spec to set the admin password (mainly) and, inside vRealize Orchestrator we would specify the final network settings as well when specifying the custom spec. I don't have the details nearby and lots have changed since then. I would have to dig this up. Right now we "work around" the limitation of the TF implementation (I won't go into the details here) but it's certainly a feature we'd use if we could. We had a ticket open with both Hashicorp and VMware for this but not much success. Was keeping an eye on this issue hoping support would eventually come.

burnsjared0415 commented 1 month ago

got it, so the concern i am seeing is there a way to update the customize spec, will take a look around at what is out there