Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

bitbucket_default_reviewers.reviewers broken #37

Open
kmoe opened this issue Jun 18, 2019 · 0 comments
Open

bitbucket_default_reviewers.reviewers broken #37

kmoe opened this issue Jun 18, 2019 · 0 comments
Assignees
Labels

Comments

@kmoe
Copy link
Member

kmoe commented Jun 18, 2019

Terraform version

0.11 and 0.12

Affected resource

bitbucket_default_reviewers

Terraform configuration file

resource "bitbucket_repository" "test_repo" {
  owner = "my_username"
  name = "test-repo-default-reviewers"
}

resource "bitbucket_default_reviewers" "test_reviewers" {
  owner = "my_username"
  repository = "${bitbucket_repository.test_repo.name}"
  reviewers = [
    "my_username",
  ]
}

Steps to reproduce

terraform apply -auto-approve
terraform apply -auto-approve

Expected result

Both terraform apply commands exit successfully.

Actual result

First apply successful.

Second apply:

$ terraform apply
bitbucket_repository.test_repo: Refreshing state... [id=terraform/test-repo-default-reviewers]
bitbucket_default_reviewers.test_reviewers: Refreshing state... [id=terraform/test-repo-default-reviewers/reviewers]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # bitbucket_default_reviewers.test_reviewers must be replaced
-/+ resource "bitbucket_default_reviewers" "test_reviewers" {
      ~ id         = "terraform/test-repo-default-reviewers/reviewers" -> (known after apply)
        owner      = "terraform"
        repository = "test-repo-default-reviewers"
      ~ reviewers  = [ # forces replacement
          - "",
          + "terraform",
        ]
    }

Plan: 1 to add, 0 to change, 1 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

bitbucket_default_reviewers.test_reviewers: Destroying... [id=terraform/test-repo-default-reviewers/reviewers]

Error: API Error: 405 2.0/repositories/terraform/test-repo-default-reviewers/default-reviewers/ 

Analysis

BitBucket has deprecated the username field in its REST API: please see #36 for more details.

GET requests to /2.0/repositories/{username}/{repo_slug}/default-reviewers now return an empty Username field in the response.

This means that when the provider runs resourceDefaultReviewersRead to populate the value of bitbucket_default_reviewers.test_reviewers.reviewers in the local state, it ends up with a value of "" for every username.

On the next apply, this "" value is passed to the resourceDefaultReviewersDelete function, which makes a DELETE request to /2.0/repositories/terraform/test-repo-default-reviewers/default-reviewers/{username}. With an empty username, this ends up being an invalid method against a different API endpoint, i.e. /2.0/repositories/terraform/test-repo-default-reviewers/default-reviewers/.

Impact

Any config with a bitbucket_default_reviewers.reviewers attribute set will produce errors after the first terraform apply.

Recommendation

Either require the reviewers attribute to be a set of user UUIDs rather than usernames, or remove this attribute and add a new attribute reviewer_uuids. This is a breaking change.

@kmoe kmoe added the bug label Jun 18, 2019
slhabity added a commit to slhabity/terraform-provider-bitbucket that referenced this issue Sep 16, 2019
slhabity added a commit to slhabity/terraform-provider-bitbucket that referenced this issue Sep 16, 2019
Uses UUID in requests instead

Bitbucket made a breaking change, removing the support
for referencing (and returning) usernames directly.

Naiive fix for issue hashicorp#37
mescam pushed a commit to nordcloud/terraform-provider-bitbucket that referenced this issue Nov 11, 2019
Uses UUID in requests instead

Bitbucket made a breaking change, removing the support
for referencing (and returning) usernames directly.

Naiive fix for issue hashicorp#37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants