Terraform with VSphere

Hi!

I have the following impediment and need:
I’m creating a provisioning VM’s using the VSphere provider, everything is working fine and the VM is being provisioned correctly.
I have a problem related to the folder in which Terraform will allocate the VM, inside VSphere.

Currently my scenario is as follows:
I have a locals doing all the logic for deciding which Datacenter we have will install the VM, basically the scenario is as follows:

terraform.tfvars
hostname = [
   "webserver-01",
   "webserver-01-ro",
]
env="DC1"
variables.tf
locals {
folder = var.env == "DC1" ? "Folder/Path/In/DC/1" : "Folder/Path/In/DC/2"
}
resource "vsphere_virtual_machine" "vm"
...
folder = local.folder
...

In this scheme, it is working perfectly, however, I am trying to do the following:
Note that the hostname list has a server called ‘webserver-01-ro’ and this hostname is allocated in different folders in both Datacenters, for example:
I need webserver-01 to be allocated in folder = “CompanyName/DC1/Folder/Path/In/DC/1”
I need the webserver-01-ro to be allocated in the folder=“CompanyName/DC1/Folder/Path/In/DC/1/ro”

And when the var.env is “DC2”, I need this:
I need webserver-01 to be allocated in folder = “DC2/Folder/Path/DC/2”
I need the webserver-01-ro to be allocated in the folder = “DC2/Folder/Path/DC/2/ro”

You can see that the folders are not symmetrical, correct?

I tried to make several conditions for this, but I wasn’t successful, I would need Terraform to read each attribute of the ‘hostname’ map and assign the correct value to this attribute, based on my var.env.
I’ve tried to do it the following way, in recent attempts:

folder = [
     for host in var.hostname :
       var.env == "DC1" && regexall("ro", host) ? "CompanyName/DC1/Folder/Path/In/DC/1/ro" :
       var.env == "DC1" && regexall("ro", host) ? "CompanyName/DC1/Folder/Path/In/DC/1" :
       var.env == "DC2" && regexall("ro", host) ? "DC2/Folder/Path/DC/2/ro" : "DC2/Folder/Path/DC/2"
   ]

Can you help me? Any tips?

Just to complement, I changed the condition to validate whether it received true or false, but I was still unsuccessful, because when reading the conditions, it returns to me that it is a tuple of two values, but I need it to be a string (the attribute folder of the provider asks it to be a string).
I would like that when reading the var.hostname list, the folder was configured correctly for each attribute of this list, that is:

hostname = [
    "webserver-01",
    "webserver-01-ro",
]
env="DC1"

Then:

webserver-01 will receive the value in its local.folder = CompanyName/DC1/Folder/Path/In/DC/1
And webserver-01-ro in your local.folder=CompanyName/DC1/Folder/Path/In/DC/1/ro

OR

If var.env="DC2":
webserver-01 = local.folder = DC2/Folder/Path/DC/2
webserver-01-ro = local.folder = DC2/Folder/Path/DC/2/ro
folder = [
      for host in var.hostname :
        var.env == "DC1" && regexall("ro", host) == true ? "CompanyName/DC1/Folder/Path/In/DC/1/ro" :
        var.env == "DC1" && regexall("ro", host) == false ? "CompanyName/DC1/Folder/Path/In/DC/1" :
        var.env == "DC2" && regexall("ro", host) == true ? "DC2/Folder/Path/DC/2/ro" : "DC2/Folder/Path/DC/2"
    ]

A more readable example (I think):

if (var.env == "DC1" && regexall("ro", var.hostname){
   folder = "CompanyName/DC1/Folder/Path/In/DC/1/ro"
} 
elseif (var.env == "DC1" && !regexall("ro", var.hostname){
   folder = "CompanyName/DC1/Folder/Path/In/DC/1"
} 
elseif (var.env == "DC2" && regexall("ro", var.hostname){
   folder = "DC2/Folder/Path/DC/2/ro"
} 
   else folder = "DC2/Folder/Path/DC/2/ro"