terraform-provider-tfe icon indicating copy to clipboard operation
terraform-provider-tfe copied to clipboard

Add `url` output to `tfe_workspace` resource and data source

Open gdavison opened this issue 4 years ago • 3 comments

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
}

gdavison avatar May 31 '21 22:05 gdavison

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.

chrisarcand avatar Jun 02 '21 13:06 chrisarcand

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.

gdavison avatar Aug 06 '21 22:08 gdavison

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.

chrisarcand avatar Aug 09 '21 14:08 chrisarcand

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

brandonc avatar Feb 09 '23 18:02 brandonc