Dynamically passing values to terraform init

I have a terraform project set up with a terraform remote backend utilizing terraform cloud to handle workspace state.

When I run terraform init locally I get an output asking me to select a workspace.

Is there any possible way to dynamically pass a value when using this setup in a CI/CD solution ?

Initializing the backend...

The currently selected workspace (default) does not exist.
  This is expected behavior when the selected workspace did not have an
  existing non-empty state. Please enter a number to select a workspace:
  1. management
  2. production
  3. staging

  Enter a value:

Yes - use TF_WORKSPACE to set the workspace name you want to have selected. Note that it has to be an existing workspace you’ve mapped in the cloud configuration block (with the correct tags) - in other words, it has to be selectable in the list above.

1 Like

Thank you so much, that is exactly what I needed :slight_smile:

1 Like