ibm-cloud-architecture / terraform-icp-vmware

Terraform recipe to deploy IBM Cloud Private on VMware
10 stars 15 forks source link

Allow VM folder to pre-exist #44

Open jesusmah opened 5 years ago

jesusmah commented 5 years ago

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.

jesusmah commented 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

hassenius commented 5 years ago

Seems like this is a design decision by the vsphere guys: https://github.com/terraform-providers/terraform-provider-vsphere/issues/219

petervansickel commented 5 years ago

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.

hassenius commented 5 years ago

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

rootmadhu commented 3 years ago

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 ??