terraform-provider-tfe
terraform-provider-tfe copied to clipboard
Add `url` output to `tfe_workspace` resource and data source
It would be useful in some cases to return the URL of a tfe_workspace instead of needing to manually compose it.
Currently, we have to do the following:
locals {
tfe_host = "app.terraform.io"
}
provider "tfe" {
hostname = local.tfe_host
}
data "tfe_workspace" "current" {
name = var.workspace_name
organization = var.workspace_org
}
output "tfe_workspace_url" {
value = "${local.tfe_host}/app/${data.tfe_workspace.current.organization}/workspaces/${data tfe_workspace.current.name}"
}
We could instead do something like:
locals {
tfe_host = "app.terraform.io"
}
provider "tfe" {
hostname = local.tfe_host
}
data "tfe_workspace" "current" {
name = var.workspace_name
organization = var.workspace_org
}
output "tfe_workspace_url" {
value = data.tfe_workspace.current.url
}
Would the purpose of this endpoint be mostly for browsing in the Terraform Cloud UI (what you have), or programmatic use, do you think?
Do you have any example from the AWS provider as an example, out of curiosity? I went looking and just found Cloud9 environments, which seem to do exactly what your example does above 😄
Not opposed, just looking for more context. If we added the exact org/name URL here I would name it browser_url/browseable_url/something, I think, leaving the direct immutable URL addable as url.
My specific use case is to use the URL as a tag on some AWS resources. Essentially, "these resources are managed using this TFC workspace". Right now, I'm composing the URL with "${local.tfe_host}/app/${data.tfe_workspace.current.organization}/workspaces/${data.tfe_workspace.current.name}" like above.
Seems reasonable!
For posterity: This will require an addition to the platform itself; we'll need to add a links member to the response to indicate the browseable URL (not just self, which is the Workspaces API path), which I propose to be html or self-html. The provider here would expose this via html_url.
This was added in #784 as html_url on tfe_workspace and data.tfe_workspace and will appear in the next release of hashicorp/tfe