DrFaust92 / terraform-provider-bitbucket

Terraform Bitbucket Cloud provider.
https://registry.terraform.io/providers/drfaust92/bitbucket
Mozilla Public License 2.0
36 stars 29 forks source link

Allow Bitbucket authentication with a workspace/project/repo access token #190

Open giveadamakick opened 7 months ago

giveadamakick commented 7 months ago

Terraform Version

1.6.4

Affected Resource(s)

Authentication

Terraform Configuration Files

provider "bitbucket" {
  access_token = "<valid_access_token>"
}

Alternative: BITBUCKET_ACCESS_TOKEN environment variable set.

Expected Behavior

The provider uses the access token to authenticate with Bitbucket Cloud.

Actual Behavior

access_token/BITBUCKET_ACCESS_TOKEN are not supported.

Steps to Reproduce

  1. terraform apply

Important Factoids

Using Workspace Access Tokens describes how to use the token when calling the Bitbucket Cloud API (via a header like this: Authorization: Bearer <workspace_access_token>).

Project tokens and repo tokens use exactly the same auth mechanism.

References

DrFaust92 commented 7 months ago

Hi @giveadamakick, have you tried using oauth_token/BITBUCKET_OAUTH_TOKEN ? at the very least it implents this as a bearer token

giveadamakick commented 7 months ago

Hi @DrFaust92, I had tried setting BITBUCKET_OAUTH_TOKEN to my workspace access token, and it failed with an Error: unexpected end of JSON input message for multiple resources when I did a terraform plan. I had assumed that this was because workspace access tokens were unsupported.

Looking at the particular resources that failed more closely, I now see that they are all bitbucket_group resources. My best guess is that in fact these errors are related to the "You can't use an Access Token to manipulate or query repository, project, or workspace permissions." restriction as stated here: https://developer.atlassian.com/cloud/bitbucket/rest/intro/#considerations-for-using-access-tokens

Long story short, setting BITBUCKET_OAUTH_TOKEN to an access token does indeed seem to work. I still think it would be good to more intuitively support access tokens rather than shoehorning into the OAuth token var.