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

Attempting to disable the branch_types for the project never seems to get "fixed". #183

Closed rquadling closed 4 months ago

rquadling commented 11 months ago

All the resources we're operating on have been imported as we am working on placing over 50 repos into an IaC setup simply because of the volume of manual changes and no-one knows who did what or necessarily where it is.

So, from that, there MAY be a 100 things we're not doing right simply due to the volume, but this is a slow and careful import and each step at the moment is to just confirm the resources are matching the live form and synchronizing things across the repos as we need to get that done.

The issue we're having is turning off the branch types (what I see as GitFlow branch name prefixes). None of the repos are used with GitFlow in mind and there's a mix of them being enabled / disabled amongst the repos. By disabling them at the project level (to start with) and see how far we get.

By having the following block in the module.project.bitbucket_project_branching_model.branching_model :

  # GitFlow
  dynamic "branch_type" {
    for_each = ["bugfix", "feature", "hotfix", "release"]
    content {
      enabled = false
      kind    = branch_type.value
      prefix  = format("%s/", branch_type.value)
    }
  }

we get (as expected)

Terraform will perform the following actions:

  # module.project.bitbucket_project_branching_model.branching_model will be updated in-place
  ~ resource "bitbucket_project_branching_model" "branching_model" {
        id        = "digitickets/CID"
        # (2 unchanged attributes hidden)

      + branch_type {
          + enabled = false
          + kind    = "bugfix"
          + prefix  = "bugfix/"
        }
      + branch_type {
          + enabled = false
          + kind    = "feature"
          + prefix  = "feature/"
        }
      + branch_type {
          + enabled = false
          + kind    = "hotfix"
          + prefix  = "hotfix/"
        }
      + branch_type {
          + enabled = false
          + kind    = "release"
          + prefix  = "release/"
        }

        # (2 unchanged blocks hidden)
    }

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

When we apply :

$  terraform apply "terraform.tfplan"
module.project.bitbucket_project_branching_model.branching_model: Modifying... [id=xxxx/CID]
module.project.bitbucket_project_branching_model.branching_model: Modifications complete after 2s [id=xxxx/CID]

All looks good so far!

Re-run the plan and the same outstanding change is required. Repeat this as often as you want and the same thing happens.

Tried replacing false with null, and with the enabled line removed, and the plan output is slightly different :

Terraform will perform the following actions:

  # module.project.bitbucket_project_branching_model.branching_model will be updated in-place
  ~ resource "bitbucket_project_branching_model" "branching_model" {
        id        = "digitickets/CID"
        # (2 unchanged attributes hidden)

      + branch_type {
          + enabled = (known after apply)
          + kind    = "bugfix"
          + prefix  = "bugfix/"
        }
      + branch_type {
          + enabled = (known after apply)
          + kind    = "feature"
          + prefix  = "feature/"
        }
      + branch_type {
          + enabled = (known after apply)
          + kind    = "hotfix"
          + prefix  = "hotfix/"
        }
      + branch_type {
          + enabled = (known after apply)
          + kind    = "release"
          + prefix  = "release/"
        }

        # (2 unchanged blocks hidden)
    }

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

But the apply and replan shows that the change is still outstanding.

I also tried the fully expanded form, just in case that was the reason ... nope.

Plan always seems to want to change the bitbucket_project_branching_model.

Slightly behind on Terraform, and so null, false, handling ... maybe something there, but this is normally a provider issue.

### Terraform Version
$ terraform -v
Terraform v1.4.5
on darwin_amd64
+ provider registry.terraform.io/drfaust92/bitbucket v2.37.0
+ provider registry.terraform.io/hashicorp/aws v4.67.0

Affected Resource(s)

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.

Expected Behavior

Only update the resource if there is a difference to the branching model

Actual Behavior

Every plan says the branch_types need "adding" with the enabled being set to false or known after apply.

ZaxR commented 10 months ago

I'm experiencing the same issue with bitbucket_branching_model. @DrFaust92 any chance you can take a look?

ZaxR commented 10 months ago

I think this might be the issue. Looks like enabled is just hardcoded to true.

barrywhart commented 4 months ago

I have a fix for this. There were multiple code issues involved. See #205.