I am working on a artifact for helping TFE users provide some self service (to be unveiled soon!). One of the things I needed to do was provide a repeatable way to have a tfe workspace create workspaces in the same project. At first I thought I'd need a new data source for this since the tfe data sources require organization
and at the very least.
Turns out I can do it today with some magic runtime env vars:
variable "TFC_WORKSPACE_SLUG" {}
variable "TFC_PROJECT_NAME" {}
locals {
org_name = split("/",var.TFC_WORKSPACE_SLUG)[0]
}
data "tfe_project" "current" {
name = var.TFC_PROJECT_NAME
organization = local.org_name
}
resource "tfe_workspace" "ws" {
name = "new-ws"
organization = local.org_name
project_id = data.tfe_project.current.id
}
Executing that code in a TFE workspace will let you create workspaces without knowing the organization name or project! Niche but pretty nifty!