In our Terraform infrastructure, we generate resources dynamically: a local script is executed and returns a list: something like that:
module "subdomains" {
source = "../modules/subdomains"
}
module "cluster" {
for_each = module.subdomains.subdomains
source = "..."
module_name = each.value.subdomain_name
}
The strings in this list contains URL path, like:
"/subdomains/random.mydomain.com",
"/subdomains/another.mydomain.com",
How can I address these resources in command line, e.g.: terraform destroy --target=...
I have tried without success:
terraform destroy module.cluster["/subdomains/random.mydomain.com"]
╷
│ Error: Index value required
│
│ on line 1:
│ (source code not available)
│
│ Index brackets must contain either a literal number or a literal string.
Can anybody help me?
Thank you
You need to use quotes, e.g.:
$ terraform destroy -target='module.cluster["/subdomains/random.mydomain.com"]'