Closed jimmyR closed 6 months ago
can you make a PR? please
@DrFaust92 how do you feel about this solution?
i was able to get this to work with the username, so i don't really feel like this is an issue.
I tried to reproduce this issue, but was unable to reproduce it:
All seems to work.
The reason for the mentioned code, is that the Bitbucket API accepts a user object that can contain the uuid
and/or the username
property. The code transform the input of a string array to this object, so the Bitbucket API correctly accepts this value.
The current shortcomings of this resource are:
The only action I can think of is to add the username part to the example documentation, so it is clear no UUID are used, but the Bitbucket username.
bitbucket_branch_restriction doesn't handle "users" changes properly, whereas bitbucket_default_reviewers does.
This is caused by the fact that bitbucket_default_reviewers uses account "uuid", whereas bitbucket_branch_restriction uses account "username".
The "username" isn't returned in the user list associated with a branch restrictions using the bitbucket API. So it's not possible for terraform to correlate the users associated with a branch restriction to the users defined in the terraform configuration, as one is a list of usernames and the other a list of uuids.
Terraform Version
Terraform v1.0.4 on darwin_amd64 provider registry.terraform.io/DrFaust92/bitbucket v2.13.1
Affected Resource(s)
bitbucket_branch_restriction
Terraform Configuration Files
Expected Behavior
terraform handles user changes to branch restrictions in the same manner as default reviewers.
Adding and removing users, both in terraform and behind terraforms back, results in no errors.
Removing users from a branch restriction behind terraforms back, followed by running a terraform apply, reverts the user list to the correct state as defined in the terraform configuration
Actual Behavior
terraform throws an error, caused by pushing a list of bitbucket.Account types, where a list of strings should be
If users are added or removed to a branch restriction behind terraforms back using the bitbucket web UI, terraform will not add or remove users added to the branch restriction list.
Steps to Reproduce
Create a branch restriction on any repo in bitbucket that requires a users list
Apply the change using terraform using TFLOG=DEBUG
An error is thrown indicating that a bitbucket.Account cannot be returned when a string was expected
Important Factoids
"users" is defined as schema.TypeSet, which I believe is a []string but "users" is passed []bitbucket.Account not []string, resulting in a consistent error.
Converting "users" to a list of uuids (strings), resolves the error:
However, the impact on this is that the users field in terraform config now needs to be of type uuid, and not username. However, a list of usernames is impossible (as far as I can see) to correlate anyway, so only uuids make sense (I think).
As such I changed from bitbucket.Account.Username to bitbucket.Account.Uuid
with
Using this code, the error is no more, and user list management on branch restrictions starts working correctly, the same as default reviewers.