Hi,
I try to to create a layout of vsphere folders using the vsphere_folder resource. There is a limitation: to create a subfolder, parent folder must exists, which prevents using a simple list.
For example, this code may fail because sometimes Terraform will try to create folder1/subfolder1
before folder1
.
locals {
folders = [
"folder1",
"folder1/subfolder1"
]
}
resource "vsphere_folder" "myfolder" {
for_each = toset(local.folders)
path = each.value
type = "vm"
}
As a workaround, it is possible to use:
locals {
top_level_folders = [
"folder1"
]
second_level_folders = [
"folder1/subfolder1"
]
}
resource "vsphere_folder" "top_level_folder" {
for_each = toset(local.top_level_folders)
path = each.value
type = "vm"
}
resource "vsphere_folder" "second_level_folder" {
for_each = toset(local.second_level_folders)
path = each.value
type = "vm"
depends_on = [vsphere_folder.top_level_folder]
}
It works but it’s not clean and not scalable (you need to add a new variable/local each time you add a new subfolder level).
Does anyone know how to provision folders and subfolders from a single list and a single resource ?