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

Import of a bitbucket_forked_repository that has never had pipelines enabled fails #178

Closed giveadamakick closed 11 months ago

giveadamakick commented 11 months ago

Terraform Version

1.6.1

Affected Resource(s)

Terraform Configuration Files

resource "bitbucket_forked_repository" "test_repo" {
  owner                          = "test-owner"
  name                           = "test-repo"
  project_key                   = "TEST"
  pipelines_enabled          = false
  is_private                     = true
  fork_policy                    = "no_public_forks"

  parent = {
    owner = "test-owner"
    slug  = "test-parent"
  }
}

import {
  to = bitbucket_forked_repository.test_repo
  id = "test-owner/test-repo"
}

Debug Output

https://gist.github.com/giveadamakick/be9c6f3a820da7fa916c2b6562720bf2

Panic Output

N/A

Expected Behavior

terraform plan shows that the forked Bitbucket repo will be imported.

Actual Behavior

terraform plan fails with a cryptic Error: 404 Not Found: Not found message.

Steps to Reproduce

  1. Create a Bitbucket workspace named "test-owner".
  2. Create a Bitbucket repo in this workspace named "test-parent".
  3. Create a fork of "test-parent" named "test-repo".
  4. With the provided config in place, run terraform plan.

Important Factoids

With the forked repo to be imported, if you enable pipelines and then immediately disable again (via the Bitbucket Cloud UI), then the error no longer occurs.

Running in Terraform Cloud.

References

N/A

giveadamakick commented 11 months ago

On this line in resource_repository.go, we don't error out if getting the pipeline config returns a 404:

    if err := handleClientError(err); err != nil && res.StatusCode != http.StatusNotFound {
        return diag.FromErr(err)
    }

In the equivalent line in resource_forked_repository.go, we do error out:

    if err := handleClientError(err); err != nil {
        return diag.FromErr(err)
    }

My guess would be that the fix for this is as simple as adding the extra && res.StatusCode != http.StatusNotFound check to resource_forked_repository.go.

giveadamakick commented 11 months ago

Created PR https://github.com/DrFaust92/terraform-provider-bitbucket/pull/179 to fix.