Open jesusmah opened 5 years ago
@petervansickel, what is the use case for this?
Apparently, there is no easy way to implement an if-then-else statement in terraform to handle the situation where the folder your VMs will go into already exists prior to your first terraform apply.
We can either create a folder (for which we must ensure that folder does not exist) or import a folder (for which we must ensure the folder already exist) before you execute terraform apply...
In fact, it might be a better practice to error out when a folder already exists so that you avoid team mates (or even worse, people you that does not have anything to do with you project wise) deploying stuff into your folder in case permissions in the vCenter are a bit too loose...
What are your thoughts around this? @hassenius
Seems like this is a design decision by the vsphere guys: https://github.com/terraform-providers/terraform-provider-vsphere/issues/219
The use case arose out of the folder structure we're using in the CSP lab. When you end up rerunning the terraform multiple times due to something having screwed up (a bunch of cockpit errors, in my case), it is annoying to have to delete the folder. There seem to be scenarios where I would do a plan-apply cycle and I ended up having to delete the folder to get things into a state where that wasn't a cause for erroring out.
I think that's probably a perfect use case for importing the folder: Importing An existing folder can be imported into this resource via its full path, via the following command:
terraform import vsphere_folder.icpenv /default-dc/vm/terraform-test-folder
In this case the folder would of course be deleted again with a terraform destroy
since terraform takes over the lifecycle of imported resrouces
the command didn't work for me. with terrform 0.13.6. I don't understand. I destroyed the cluster and the folder was deleted and again removed the tfstate file and hidden terraform folders.
Now I init +plan & apply the folder creates in this apply portion but fails indicating folder exists ??
Per Peter Van Sickel,
At the moment, terraform for VMware will error out if the folder where VM will be place under already exists.
This enhancement should handle this situation.