josenk / terraform-provider-esxi

Terraform-provider-esxi plugin
GNU General Public License v3.0
544 stars 154 forks source link

Possible to store ESXi hostname in terraform state file? #108

Closed iPhrankie closed 4 years ago

iPhrankie commented 4 years ago

Would it be possible to store the esxi hostname within the Terraform state file?

I would like to target an ESXi host based on a variable, which might be a random_shuffle. I believe the state file would need the ESXI hostname so Terraform knows which host the VM resides on?

Or is there a different approach?

Thanks!

josenk commented 4 years ago

If the entire deployment will be on the same ESXi host, then you can use workspaces. But I don't think you can random shuffle the hosts... You would have to experiment a bit with it. Workspaces is a great way to separate code from variables.

If the deployment has resources deployed to multiple esxi hosts as the same time. I know of two different ways to do it... This is a similar type of problem if you are trying to deploy to AWS in multiple regions. You can google many examples how people solve that problem.

iPhrankie commented 4 years ago

Thank you for your response and help.

I've been deploying VMs against a single esxi host via automation. This esxi host is getting full. I need to target another esxi host for new VMs. However, I still need to target either host if an automated task comes in that references an existing VM.

I could pass the "host" in the terraform command line? If I do this, will it get stored in the state file? I inspected the existing state file and it contains a lot of info, but it's missing the esxi host info. I think if it contained the host info where the VM is located then I would be all set because I already reference the state files in the automation.

This is my variables.tf file.

variable "host" { type = string default = "172.0.0.1" }

josenk commented 4 years ago

Your issue has nothing to do with this plugin. You may want to read the terraform documentation for other solutions if my suggestions didn't work for you..