Introduction & Use-Case
When working with Terraform Enterprise/Cloud, there are times where you'd like to set your TFE/C Workspace's execution type to "Local". You can set it easily on the UI as explained here [a], but there are times when you'd like to set the Local execution mode by default either programmatically or through the CLI workflow -- that's what this article walks you through.
At the time of this writing, there are currently 2 ways to select the
local execution mode by default:
- when using the TFE provider [b] OR
- through the
data.attributes.execution-mode API setting [c].
The API method is pretty self-explanatory so I'll focus on how to do this using the TFE provider.
Because local workspaces in Terraform (via the
terraform workspace command) is a local execution concept only and different from TFE/C workspaces, we have to link them up for a programmatic/CLI-based workflow.
Here are the steps to do so:
Add tags to your TFE workspaces using the TFE provider [d] or the API [e]. To learn more about workspace tags, please see [f].
Link your working directory to multiple TFE workspaces using workspace tags - via the
workspace selectcommand [g] to select which remote workspace to use. The explanation of the principle behind this can be found here [h].
If you proceed to use the TFE provider or API to specify local execution modes, please do NOT use/specify the now deprecated
operations argument [i] or
data.attributes.operations [c] to avoid running into issues.