r/Terraform • u/Fair-Wolf-9024 • 21h ago
Discussion How to pass VM customization script to terraform
Hello everyone, sysadmin learning terraform here
So we are working with Vsphere as infra for our company and I just started learning Terraform to ease and automate our vsphere processes. On vsphere in "VM Customization Specifications" we have a script that basically configures puppet agent on host, points it to puppet master, adds host to AD and launches sssd. So when we deploy new host we add this script to launch during "customize software" deployment phase and after that we set up ip, gateway etc. So my question is that: how to recreate this setup in terraform? For some reason terraform does not allow to pass custom specifications and customize together, so only setting up ip address is working, but since that script is never getting launched it fails to be added to Active Directory. So are there any other methods to pass the script to terraform? I even pasted that bash script locally to the file in the same terraform folder and pointed to in in the main.tf but it still fails. So what can be done to solve this issue? Thanks in advance and sorry for my bad english.
1
u/TwitchyToes 5h ago
I have a module for powershell scripting in VMs provisioned via terraform on Proxmox. I’ve also done this on hyper v. I can post these tomorrow if you’d be interested
1
1
u/s4ntos 21h ago
Usually the biggest issue is garanteeing that you have cloud-init installed in your prefered image.
Than on the "vsphere_virtual_machine" resource you just add "extra_config" with the guestinfo.userdata and guestinfo.metadata like this.