terraform-provider-bitbucket icon indicating copy to clipboard operation
terraform-provider-bitbucket copied to clipboard

404 on repository creation (repository is actually created)

Open aadamovich opened this issue 2 years ago • 8 comments

Terraform Version

Terraform v1.5.1
on windows_amd64
+ provider registry.terraform.io/drfaust92/bitbucket v2.33.0
+ provider registry.terraform.io/hashicorp/local v2.4.0
+ provider registry.terraform.io/hashicorp/null v3.2.1
+ provider registry.terraform.io/hashicorp/tls v4.0.4

Affected Resource(s)

  • bitbucket_repository

Terraform Configuration Files

data "bitbucket_workspace" "parent" {
  workspace = "xxx"
}

resource "bitbucket_project" "parent" {
  owner = data.bitbucket_workspace.parent.slug
  name  = "main"
  key   = "MAIN"
}

resource "bitbucket_repository" "setup" {
  owner       = data.bitbucket_workspace.parent.name
  name        = "setup"
  slug        = "setup"
  project_key = bitbucket_project.parent.key
}

Debug Output

2023-06-24T12:16:38.864+0300 [DEBUG] ReferenceTransformer: "bitbucket_repository.setup (expand)" references: []
2023-06-24T12:16:38.864+0300 [DEBUG] ReferenceTransformer: "bitbucket_project.parent (expand)" references: []
2023-06-24T12:16:38.864+0300 [DEBUG] ReferenceTransformer: "data.bitbucket_current_user.me (expand)" references: []
2023-06-24T12:16:38.864+0300 [DEBUG] ReferenceTransformer: "bitbucket_repository.setup" references: [data.bitbucket_workspace.parent (expand) bitbucket_project.parent (expand)]
2023-06-24T12:16:38.864+0300 [DEBUG] ReferenceTransformer: "data.bitbucket_workspace.parent (expand)" references: []
2023-06-24T12:16:38.864+0300 [DEBUG] ReferenceTransformer: "output.me (expand)" references: [data.bitbucket_current_user.me (expand)]
2023-06-24T12:16:38.864+0300 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/drfaust92/bitbucket\"]" references: []
2023-06-24T12:16:38.865+0300 [DEBUG] pruneUnusedNodes: data.bitbucket_current_user.me (expand) is no longer needed, removing
2023-06-24T12:16:38.869+0300 [INFO]  backend/local: apply calling Apply
2023-06-24T12:16:38.869+0300 [DEBUG] Building and walking apply graph for NormalMode plan
2023-06-24T12:16:38.869+0300 [DEBUG] Resource state not found for node "bitbucket_repository.setup", instance bitbucket_repository.setup
2023-06-24T12:16:38.870+0300 [DEBUG] ProviderTransformer: "bitbucket_repository.setup (expand)" (*terraform.nodeExpandApplyableResource) needs provider["registry.terraform.io/drfaust92/bitbucket"]
2023-06-24T12:16:38.870+0300 [DEBUG] ProviderTransformer: "bitbucket_project.parent (expand)" (*terraform.nodeExpandApplyableResource) needs provider["registry.terraform.io/drfaust92/bitbucket"]
2023-06-24T12:16:38.870+0300 [DEBUG] ProviderTransformer: "data.bitbucket_current_user.me (expand)" (*terraform.nodeExpandApplyableResource) needs provider["registry.terraform.io/drfaust92/bitbucket"]
2023-06-24T12:16:38.870+0300 [DEBUG] ProviderTransformer: "data.bitbucket_workspace.parent (expand)" (*terraform.nodeExpandApplyableResource) needs provider["registry.terraform.io/drfaust92/bitbucket"]
2023-06-24T12:16:38.870+0300 [DEBUG] ProviderTransformer: "bitbucket_repository.setup" (*terraform.NodeApplyableResourceInstance) needs provider["registry.terraform.io/drfaust92/bitbucket"]
2023-06-24T12:16:38.870+0300 [DEBUG] pruning unused provider["registry.terraform.io/hashicorp/local"]
2023-06-24T12:16:38.870+0300 [DEBUG] pruning unused provider["registry.terraform.io/hashicorp/null"]
2023-06-24T12:16:38.870+0300 [DEBUG] pruning unused provider["registry.terraform.io/hashicorp/tls"]
2023-06-24T12:16:38.870+0300 [DEBUG] ReferenceTransformer: "bitbucket_repository.setup (expand)" references: []
2023-06-24T12:16:38.870+0300 [DEBUG] ReferenceTransformer: "bitbucket_project.parent (expand)" references: []
2023-06-24T12:16:38.870+0300 [DEBUG] ReferenceTransformer: "data.bitbucket_current_user.me (expand)" references: []
2023-06-24T12:16:38.870+0300 [DEBUG] ReferenceTransformer: "data.bitbucket_workspace.parent (expand)" references: []
2023-06-24T12:16:38.870+0300 [DEBUG] ReferenceTransformer: "output.me (expand)" references: [data.bitbucket_current_user.me (expand)]
2023-06-24T12:16:38.870+0300 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/drfaust92/bitbucket\"]" references: []
2023-06-24T12:16:38.870+0300 [DEBUG] ReferenceTransformer: "bitbucket_repository.setup" references: [data.bitbucket_workspace.parent (expand) bitbucket_project.parent (expand)]
2023-06-24T12:16:38.870+0300 [DEBUG] pruneUnusedNodes: data.bitbucket_current_user.me (expand) is no longer needed, removing
2023-06-24T12:16:38.870+0300 [DEBUG] Starting graph walk: walkApply
2023-06-24T12:16:38.872+0300 [DEBUG] created provider logger: level=debug
2023-06-24T12:16:38.872+0300 [INFO]  provider: configuring client automatic mTLS
2023-06-24T12:16:38.880+0300 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/drfaust92/bitbucket/2.33.0/windows_amd64/terraform-provider-bitbucket_v2.33.0.exe args=[.terraform/providers/registry.terraform.io/drfaust92/bitbucket/2.33.0/windows_amd64/terraform-provider-bitbucket_v2.33.0.exe]
2023-06-24T12:16:38.883+0300 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/drfaust92/bitbucket/2.33.0/windows_amd64/terraform-provider-bitbucket_v2.33.0.exe pid=24100
2023-06-24T12:16:38.883+0300 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/drfaust92/bitbucket/2.33.0/windows_amd64/terraform-provider-bitbucket_v2.33.0.exe
2023-06-24T12:16:38.898+0300 [INFO]  provider.terraform-provider-bitbucket_v2.33.0.exe: configuring server automatic mTLS: timestamp=2023-06-24T12:16:38.898+0300
2023-06-24T12:16:38.916+0300 [DEBUG] provider: using plugin: version=5
2023-06-24T12:16:38.916+0300 [DEBUG] provider.terraform-provider-bitbucket_v2.33.0.exe: plugin address: address=127.0.0.1:10000 network=tcp timestamp=2023-06-24T12:16:38.916+0300
2023-06-24T12:16:38.934+0300 [INFO]  provider.terraform-provider-bitbucket_v2.33.0.exe: 2023/06/24 12:16:38 [DEBUG] Using API Basic Auth: timestamp=2023-06-24T12:16:38.934+0300
2023-06-24T12:16:38.937+0300 [WARN]  Provider "registry.terraform.io/drfaust92/bitbucket" produced an invalid plan for bitbucket_repository.setup, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .fork_policy: planned value cty.StringVal("allow_forks") for a non-computed attribute
      - .is_private: planned value cty.True for a non-computed attribute
      - .pipelines_enabled: planned value cty.False for a non-computed attribute
      - .has_issues: planned value cty.False for a non-computed attribute
      - .has_wiki: planned value cty.False for a non-computed attribute
      - .scm: planned value cty.StringVal("git") for a non-computed attribute
      - .link: attribute representing nested block must not be unknown itself; set nested attribute values to unknown instead
2023-06-24T12:16:38.937+0300 [INFO]  Starting apply for bitbucket_repository.setup
2023-06-24T12:16:38.937+0300 [DEBUG] bitbucket_repository.setup: applying the planned Create change
2023-06-24T12:16:38.938+0300 [INFO]  provider.terraform-provider-bitbucket_v2.33.0.exe: 2023/06/24 12:16:38 [DEBUG] setting computed for "link" from ComputedKeys: timestamp=2023-06-24T12:16:38.938+0300
2023-06-24T12:16:40.620+0300 [ERROR] provider.terraform-provider-bitbucket_v2.33.0.exe: Response contains error diagnostic: diagnostic_severity=ERROR diagnostic_summary="404 Not Found: Not found" tf_resource_type=bitbucket_repository @caller=github.com/hashicorp/[email protected]/tfprotov5/internal/diag/diagnostics.go:55 @module=sdk.proto diagnostic_detail= tf_proto_version=5.3 tf_provider_addr=DrFaust92/bitbucket tf_req_id=cf1248d7-9155-4590-c3b9-b8f2d46ae4a7 tf_rpc=ApplyResourceChange timestamp=2023-06-24T12:16:40.620+0300
2023-06-24T12:16:40.631+0300 [DEBUG] State storage *statemgr.Filesystem declined to persist a state snapshot
2023-06-24T12:16:40.631+0300 [ERROR] vertex "bitbucket_repository.setup" error: 404 Not Found: Not found
2023-06-24T12:16:40.642+0300 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2023-06-24T12:16:40.662+0300 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/drfaust92/bitbucket/2.33.0/windows_amd64/terraform-provider-bitbucket_v2.33.0.exe pid=24100
2023-06-24T12:16:40.663+0300 [DEBUG] provider: plugin exited

Panic Output

bitbucket_repository.setup: Creating...
╷
│ Error: 404 Not Found: Not found
│
│   with bitbucket_repository.setup,
│   on 20_repos.tf line 8, in resource "bitbucket_repository" "setup":
│    8: resource "bitbucket_repository" "setup" {
│
╵

Expected Behavior

Repository is created and no error is thrown.

Actual Behavior

Repository is created, but terraform throws 404

Steps to Reproduce

terraform apply

aadamovich avatar Jun 24 '23 09:06 aadamovich

I'm not sure what is causing the error (workspace exists, project is created without problem, but repo gives 404):

[ERROR] provider.terraform-provider-bitbucket_v2.33.0.exe: 
Response contains error diagnostic: 
diagnostic_severity=ERROR diagnostic_summary="404 Not Found: Not found" 
tf_resource_type=bitbucket_repository 
@caller=github.com/hashicorp/[email protected]/tfprotov5/internal/diag/diagnostics.go:55 
@module=sdk.proto 
diagnostic_detail= 
tf_proto_version=5.3 
tf_provider_addr=DrFaust92/bitbucket 
tf_req_id=cf1248d7-9155-4590-c3b9-b8f2d46ae4a7 
tf_rpc=ApplyResourceChange 
timestamp=2023-06-24T12:16:40.620+0300

aadamovich avatar Jun 24 '23 09:06 aadamovich

Tried with 2.33.0, 2.32.0, 2.31.0, 2.30.2, 2.28.0. Same result.

aadamovich avatar Jun 24 '23 09:06 aadamovich

It started to work after I went to the created repo and manually enabled the pipelines:

image

Now it works with repo resource creation/deletion. Weird.

aadamovich avatar Jun 24 '23 09:06 aadamovich

The way I found it was about the pipelines: I tried provider version 2.16 and when running terraform apply it showed me extra error message:

bitbucket_repository.setup: Creating...
╷
│ Error: error enabling pipeline for repository (setup): 404 Not Found
│
│   with bitbucket_repository.setup,
│   on 20_repos.tf line 9, in resource "bitbucket_repository" "setup":
│    9: resource "bitbucket_repository" "setup" {
│
╵

Regardless of pipelines_enabled value it still showed the above error.

aadamovich avatar Jun 24 '23 09:06 aadamovich

This was a completely new workspace. I guess the initial error is related to the expectations of the provider that the workspace is initialized with some default settings and certain URLs just work.

aadamovich avatar Jun 24 '23 09:06 aadamovich

Another observation, setting pipelines_enabled attribute to true - enables the pipelines as expected, but setting it to false, does not actually disable it.

aadamovich avatar Jun 24 '23 09:06 aadamovich

I had a similar problem and found that my app key didn't have the correct permissions. Have not delved into it yet, but checking all the boxes for test purposes worked for me.

sboardwell avatar Aug 28 '24 16:08 sboardwell

It started to work after I went to the created repo and manually enabled the pipelines:

image

Now it works with repo resource creation/deletion. Weird.

The issue is definitely related to Pipelines. Enabling Pipelines in any repo in a workspace fixes the issue permanently. This is definitely the root cause. Steps to reproduce:

  1. Create a new workspace.
  2. Try to create a bitbucket_repository.
  3. The repo will be created, but the task will then immediately fail with a 404 error.

To fix, simply enable pipelines in any repo in the workspace. It doesn't need to be the same repo, and can be deleted immediately. Afterwards, all bitbucket_repository resources can be created normally.

Suspect that the Pipelines API isn't enabled at all for a workspace until at least one repository has pipelines enabled. This needs to be documented or worked around.

chriscunningham-qodea avatar Sep 16 '24 13:09 chriscunningham-qodea