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

tfe_oauth_client data source by name

Open jonmaestas opened this issue 3 years ago • 0 comments

Use-cases

It would be very beneficial to use a friendly name instead of oauth_client_id to lookup an oauth_client. If you have to get the oauth_client_id as input, you could have just queried for the oauth_token_id.

We are trying to use a "workspace-manager" approach to build workspaces and the worksapces need the oauth_token_id to connect the repo to VCS.

The process to create the VCS connection is external to this "workspace-manager" so we don't have the oauth_client_id handy.

Attempted Solutions

@djaboxx put together an external lookup solution here.

Here is how you can query for the id by name using jq.

curl -s \
  https://tfe.my-site.com/api/v2/organizations/my-org/oauth-clients \
  --header "Authorization: Bearer my_token" \
  --header "Content-Type: application/vnd.api+json" \
  | jq '.data[] | select(.attributes.name=="my-vcs-connection-name") | .id'

Proposal

Very similar to how you can do the lookup of ssh_key by name, we should also be able to lookup oauth_client by name.

data "tfe_ssh_key" "test" {
  name         = "my-ssh-key-name"
  organization = "my-org-name"
}

# ↑↑↑ this lookup functionality, here ↓↓↓

data "tfe_oauth_client" "client" {
  name         = "my-vcs-connection-name"
  organization = "my-org-name" 
}

jonmaestas avatar Jun 29 '21 20:06 jonmaestas