Expected Outcome
To create a new workspace in an Organization within Terraform Enterprise or Terraform Cloud using the backend.tf
backend block.
Procedure
It is expected as an option to use the backend.tf
to create a new workspace, but the Organization needs to exist.
NOTE: The hostname attribute within the backend.tf
should be set to either Terraform Cloud such as app.terraform.io or Terraform Enterprise $tfe-hostname.
Access Level to create a workspace requires Implicit for token type for Organization tokens and explicit for token type for User and Team tokens.
- Create the
backend.tf
locally using the format below: -
terraform { backend "cloud" { hostname = "<$tfe-hostname_or_app.terraform.io>" organization = "<$orgname that already exists>" workspaces { name = "<$workspace name to be created within the org" } } }
- From a command prompt where the backend.tf exists, log in into Terraform API from the command line by issuing: terraform login
- Follow the instructions of the prompts, the second one will require the appropriate API token
- Run the command terraform init to initiate the connection to the TFC/TFE organization and create the workspace.
- Check the Organization to ensure the new workspace was created.
- For TFE $TFE_URL/app/$Organization-name/workspaces
- For TFC app.terraform.io/app/$Organization-name/workspaces
- Using the API, List workspaces
Additional Information
- For additional assistance please contact HashiCorp Support to request additional assistance.