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

Changing pipelines_enabled from true to false on a bitbucket_repository does not disable pipelines #191

Open giveadamakick opened 7 months ago

giveadamakick commented 7 months ago

Terraform Version

1.6.1

Affected Resource(s)

Terraform Configuration Files

resource "bitbucket_repository" "infrastructure" {
  owner                  = "myteam"
  name                   = "terraform-code"
  pipelines_enabled = false
}

Expected Behavior

The "Enable Pipelines" setting of the repo should have been set to false.

Actual Behavior

The "Enable Pipelines" setting of the repo was still set to true.

Steps to Reproduce

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

  1. Define a bitbucket_repository resource with pipelines_enabled set to true.
  2. terraform apply the new resource.
  3. Note that pipelines are enabled for the new repo, see https://bitbucket.org///admin/pipelines/settings
  4. Set pipelines_enabled to false in the Terraform config for that repo.
  5. terraform apply the change.
  6. Note that pipelines are still enabled for the repo.

Important Factoids

Creating a new repo with pipelines_enabled initially to false does work - pipelines are disabled. This bug only occurs when a repo that previously had pipelines enabled is updated to disable pipelines.

References

Nkmol commented 3 months ago

I had a quick look at what could cause this, and it seems to be caused by the encoding of the body to JSON of the client. The following struct defines the pipelines configuration entity:

type PipelinesConfig struct {
    Type_ string `json:"type"`
    Enabled    bool        `json:"enabled,omitempty"`
    Repository *Repository `json:"repository,omitempty"`
}

The problem here is that omitempty is also applied when Enabled: false, thus the value is never sent to the Bitbucket API.

The code solution is to transform the type to a pointer, so the value is only omitted when nil.


Related issue: https://github.com/swagger-api/swagger-codegen/issues/7391