DrFaust92 / terraform-provider-bitbucket

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

bitbucket_repository "This endpoint does not support token-based authentication" #185

Closed ZaxR closed 10 months ago

ZaxR commented 10 months ago

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

Affected Resource(s)

Please list the resources as a list, for example:

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

provider "bitbucket" {
  # BITBUCKET_OAUTH_TOKEN env var is set
}

resource "bitbucket_repository" "repo" {
  owner       = var.repo_owner
  name        = var.repo_name
  slug        = var.repo_slug
  project_key = var.project_key
}

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist. debug output

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

What should have happened? A new bitbucket repository should have been created

Actual Behavior

What actually happened? │ Error: This endpoint does not support token-based authentication │ │ with module.ds-cc-creation-test.bitbucket_repository.repo, │ on ../../../modules/repo/main.tf line 21, in resource "bitbucket_repository" "repo": │ 21: resource "bitbucket_repository" "repo" { │

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Set the oauth token env var with a real env var (export BITBUCKET_OAUTH_TOKEN="your_actual_oauth_token")
  2. replace owner, name, slug, and project_id above with appropriate values
  3. terraform apply
ZaxR commented 10 months ago

Hitting the BB API directly (see command below), I get the following error instead of what tf is returning: {"type": "error", "error": {"message": "Token is invalid or not supported for this endpoint."}}%

That seems to suggest one or both of:

  1. an issue with the token (e.g. token expired or missing scopes) that's not getting captured/logged
  2. A different request is being made than the one below

Since the docs show a token being supported for the endpoint.

curl --request POST \
  --url 'https://api.bitbucket.org/2.0/repositories/<workspace>/<repo name>' \
  --header 'Authorization: Bearer $BITBUCKET_OAUTH_TOKEN' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
    "project": {
      "key": "<project key>"
  }'
ZaxR commented 10 months ago

I tried switching to username and password instead, and am still hitting the same issue, though now the equivalent curl works.

I set BITBUCKET_USERNAME and BITBUCKET_PASSWORD (which is an app password) and unset BITBUCKET_OAUTH_TOKEN.

I still get Error: This endpoint does not support token-based authentication But the following works:

curl --request POST \
  --url 'https://api.bitbucket.org/2.0/repositories/<workspace>/<repo name>' \
  --user ${BITBUCKET_USERNAME}:${BITBUCKET_PASSWORD} \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
    "project": {
      "key": "<project key>"
    },
    "is_private": true
  }'

What am I doing wrong?

ZaxR commented 10 months ago

Working now. Not sure exactly what changed, but either some issue with cached values or additional arguments I added:

resource "bitbucket_repository" "repo" {
  owner                          = var.repo_owner
  name                           = var.repo_name
  slug                           = var.repo_slug
  scm                            = "git"
  is_private                     = true
  project_key                    = var.project_key
  pipelines_enabled              = true
  inherit_default_merge_strategy = false
  inherit_branching_model        = false
}