Terraform - Customize vm question -- credentials to be used

This is a pretty basic question, but I want to understand how terraform will customize an OS VM (new Linux VM for example). I know you specify in the main.tf what you want customized (networking, hostname, etc.), but terraform would need credentials to log into the newly cloned/created VM and make those changes? That being said, how/where do you specify those credentials? I’ve been looking at the docs, but i am unable to locate that section.

Thanks.

This is done by the cloud provider when creating the VM and Terraform uses the cloud provider’s API to specify how the VM should be created.

In the case of Linux-based VMs, the image is configured using cloud-init which is run upon first boot.

Interesting. What if i am using vsphere and want to create a vm from an exisiting template?
I have created a image with packer (setup the OS, packages, user etc.) and my thought was to use terraform to go in, create a new VM off that template and do some basic configuration. Stuff like ,set hostname, configure IP address.

When I looked an example, something like:

clone {
template_uuid = data.vsphere_virtual_machine.template.id

customize {
  linux_options {
    host_name = "terraform-test"
    domain    = "test.internal"
  }

  network_interface {
    ipv4_address = "10.0.3.110"
    ipv4_netmask = 24
  }

  ipv4_gateway = "10.0.3.1"
}
  }

I am just a tad confused on how terraform would do that. are you saying that would be done via cloud-init as well?
Appreciate the help.

Ahh that one looks to be different. From a quick read, the cloning is done in vSphere so the clone bit is done on the vmx file - but still done at the time you create the machine, not afterwards. So for example if you’ve hardcoded a staticip address in the OS instead of using DHCP, then I would guess you have a problem.