I have a question regarding Terraform Cloud (TFC) and its variable capabilities. Is it possible to define variables in TFC that can automatically extract specific information from the workspace name? using split, join functions?
For instance, let’s say my workspace naming convention follows the pattern “EnvName-region-projectName”. I would like to know if there is a way to extract the environment name and region from the workspace name itself and assign them directly to variables within TFC.
Based on my understanding, it is not currently possible to directly pass variables in Terraform Cloud (TFC) variables or even in Terraform variables. Is this correct?
After implementing the suggestion, it worked perfectly. I wasn’t aware of these variables that could be exposed in TFC.
Thanks appreciate it @stewart.campbell
Another solution I’d like to share is the use of ${terraform.workspace} within your code, allowing you to expose the workspace name from Terraform Cloud (TFC). This enables us to access and extract any necessary values associated with it.