terraform-provider-bitbucket
terraform-provider-bitbucket copied to clipboard
bitbucket_default_reviewers.reviewers broken
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.