Hi @rcoughtrey!
Terraform’s language does not include features for this sort of dynamic operation because the intent is that your configuration is a description of the intended result, not a description of how to achieve that result. Terraform expects that it is either managing an object or it isn’t; conditionally owning an object is not part of its model.
To think about why, consider that once you have applied that hypothetical configuration once then all of the folders would exist, and thus the next run of Terraform would be forced to conclude that it’s not supposed to manage any of them anymore, and so the system would converge on a state where Terraform is managing nothing.
This leaves you with a couple different alternative options:
- Explicitly import the existing folders into Terraform’s care using
terraform import
. I’m not sure ifvsphere_folder
in particular supports this, but if it does you should be able to find some information about how to use it in the documentation for that resource type. In this case you’d import into a specific named instance of the resource to create the right correlation:'vsphere_folder.win_folder["the server id"]'
. Once you’ve done that, Terraform will see that these items already exist and that Terraform manages them and so subsequent changes to the configuration will be applied to them by Terraform. - Add a new column to your CSV file to indicate explicitly whether a particular entry is to be managed by Terraform or not, and then filter out the ones not managed by Terraform using an
if
clause on yourfor
expression.
Which of these is most appropriate depends on whether your end-goal is for all of these servers to be managed by Terraform (use import
) or whether Terraform will always only be managing a subset of them (use the conditional flag).