zahiar / terraform-provider-bitbucket

Terraform Provider for Bitbucket Cloud
https://registry.terraform.io/providers/zahiar/bitbucket/latest
Mozilla Public License 2.0
19 stars 22 forks source link

Provider Creates Repo But Fails With: Error: unable to enable pipelines for repository with error: 404 Not Found #174

Open archmangler opened 1 year ago

archmangler commented 1 year ago

I'm running a basic create repo test with resource "bitbucket_repository". The terraform apply fails, even though the repo is created in bitbucket:

Error: unable to enable pipelines for repository with error: 404 Not Found

Note: This is even though enable_pipeline=false ... which suggests the false parameter is being ignored in the provider Note: the App Password created for authentication has been granted permissions to enable and create pipelines in BB settings.

//main module file

resource "bitbucket_repository" "orion" {
  workspace        = "engeneon"
  name             = "orion"
  project_key      = "ORION"
  description      = "fully automated repository"
  enable_pipelines = false
}

variable "username" {
 type = string
 description = "SCM service username"
}

variable "password" {
 type = string
 description = "SCM service password"
}

provider "bitbucket" {
  username = var.username
  password = var.password
}

terraform {
  required_providers {
    bitbucket = {
      source = "zahiar/bitbucket"
      version = "1.6.0"
    }
  }
}
╷
│ Error: unable to enable pipelines for repository with error: 404 Not Found
│ 
│   with bitbucket_repository.orion,
│   on main.tf line 3, in resource "bitbucket_repository" "orion":
│    3: resource "bitbucket_repository" "orion" {
│ 

Is there a workaround or solution for this?

Note: Destroy is clean:

(base) welcome@Traianos-MacBook-Pro bitbucket-iac % terraform destroy                                               
bitbucket_repository.orion: Refreshing state... [id={091b3337-91f3-46e3-9d7d-c63d2f88924a}]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # bitbucket_repository.orion will be destroyed
  - resource "bitbucket_repository" "orion" {
      - description      = "fully automated repository" -> null
      - enable_pipelines = false -> null
      - fork_policy      = "no_forks" -> null
      - has_wiki         = false -> null
      - id               = "{091b3337-91f3-46e3-9d7d-c63d2f88924a}" -> null
      - is_private       = true -> null
      - name             = "orion" -> null
      - project_key      = "ORION" -> null
      - workspace        = "engeneon" -> null
    }

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

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

bitbucket_repository.orion: Destroying... [id={091b3337-91f3-46e3-9d7d-c63d2f88924a}]
bitbucket_repository.orion: Destruction complete after 2s

Destroy complete! Resources: 1 destroyed.
archmangler commented 1 year ago

Terraform trace debug output seems to indicate the provider might be unstable:

(NOTE: enable_pipelines tested with both true and false with same result)


2023-07-28T00:57:54.751+0800 [TRACE] provider.terraform-provider-bitbucket_v1.6.0: Served request: @module=sdk.proto tf_resource_type=bitbucket_repository tf_rpc=PlanResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.15.0/tfprotov5/tf5server/server.go:796 tf_proto_version=5.3 tf_provider_addr=provider tf_req_id=4412fc07-e17a-5c11-b16b-8188421ed50f timestamp=2023-07-28T00:57:54.751+0800
2023-07-28T00:57:54.751+0800 [WARN]  Provider "registry.terraform.io/zahiar/bitbucket" produced an invalid plan for bitbucket_repository.orion, 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("no_forks") for a non-computed attribute
      - .is_private: planned value cty.True for a non-computed attribute
      - .has_wiki: planned value cty.False for a non-computed attribute
2023-07-28T00:57:54.751+0800 [TRACE] plan: bitbucket_repository.orion treating Create change as DeleteThenCreate change to match with earlier plan
2023-07-28T00:57:54.751+0800 [TRACE] checkPlannedChange: Verifying that actual change (action DeleteThenCreate) matches planned change (action DeleteThenCreate)
2023-07-28T00:57:54.751+0800 [TRACE] reducePlan: bitbucket_repository.orion change simplified from DeleteThenCreate to Create for apply node
bitbucket_repository.orion: Creating...
2023-07-28T00:57:54.751+0800 [INFO]  Starting apply for bitbucket_repository.orion
2023-07-28T00:57:54.751+0800 [DEBUG] bitbucket_repository.orion: applying the planned Create change

.
.
.

2023-07-28T00:57:56.452+0800 [TRACE] provider.terraform-provider-bitbucket_v1.6.0: Received downstream response: tf_req_duration_ms=1700 tf_resource_type=bitbucket_repository tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.15.0/tfprotov5/internal/tf5serverlogging/downstream_request.go:37 @module=sdk.proto diagnostic_warning_count=0 tf_proto_version=5.3 tf_provider_addr=provider tf_req_id=325f4d5c-1725-caec-67e2-b949b4dc89d0 diagnostic_error_count=1 timestamp=2023-07-28T00:57:56.452+0800
2023-07-28T00:57:56.452+0800 [ERROR] provider.terraform-provider-bitbucket_v1.6.0: Response contains error diagnostic: diagnostic_severity=ERROR tf_proto_version=5.3 tf_provider_addr=provider tf_resource_type=bitbucket_repository @caller=github.com/hashicorp/terraform-plugin-go@v0.15.0/tfprotov5/internal/diag/diagnostics.go:55 diagnostic_detail= diagnostic_summary="unable to enable pipelines for repository with error: 404 Not Found" tf_req_id=325f4d5c-1725-caec-67e2-b949b4dc89d0 tf_rpc=ApplyResourceChange @module=sdk.proto timestamp=2023-07-28T00:57:56.452+0800
2023-07-28T00:57:56.452+0800 [TRACE] provider.terraform-provider-bitbucket_v1.6.0: Served request: tf_req_id=325f4d5c-1725-caec-67e2-b949b4dc89d0 tf_resource_type=bitbucket_repository tf_rpc=ApplyResourceChange @module=sdk.proto tf_proto_version=5.3 tf_provider_addr=provider @caller=github.com/hashicorp/terraform-plugin-go@v0.15.0/tfprotov5/tf5server/server.go:831 timestamp=2023-07-28T00:57:56.452+0800
2023-07-28T00:57:56.453+0800 [TRACE] maybeTainted: bitbucket_repository.orion encountered an error during creation, so it is now marked as tainted
2023-07-28T00:57:56.453+0800 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for bitbucket_repository.orion
2023-07-28T00:57:56.453+0800 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for bitbucket_repository.orion
2023-07-28T00:57:56.453+0800 [TRACE] evalApplyProvisioners: bitbucket_repository.orion is tainted, so skipping provisioning
2023-07-28T00:57:56.453+0800 [TRACE] maybeTainted: bitbucket_repository.orion was already tainted, so nothing to do
2023-07-28T00:57:56.453+0800 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for bitbucket_repository.orion
2023-07-28T00:57:56.453+0800 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for bitbucket_repository.orion
2023-07-28T00:57:56.453+0800 [TRACE] statemgr.Filesystem: have already backed up original terraform.tfstate to terraform.tfstate.backup on a previous write
2023-07-28T00:57:56.453+0800 [TRACE] statemgr.Filesystem: state has changed since last snapshot, so incrementing serial to 10
2023-07-28T00:57:56.453+0800 [TRACE] statemgr.Filesystem: writing snapshot at terraform.tfstate
2023-07-28T00:57:56.474+0800 [ERROR] vertex "bitbucket_repository.orion" error: unable to enable pipelines for repository with error: 404 Not Found
2023-07-28T00:57:56.474+0800 [TRACE] vertex "bitbucket_repository.orion": visit complete, with errors
2023-07-28T00:57:56.474+0800 [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/zahiar/bitbucket\"] (close)" errored, so skipping
2023-07-28T00:57:56.474+0800 [TRACE] dag/walk: upstream of "root" errored, so skipping
2023-07-28T00:57:56.474+0800 [TRACE] statemgr.Filesystem: have already backed up original terraform.tfstate to terraform.tfstate.backup on a previous write
2023-07-28T00:57:56.474+0800 [TRACE] statemgr.Filesystem: state has changed since last snapshot, so incrementing serial to 11
2023-07-28T00:57:56.475+0800 [TRACE] statemgr.Filesystem: writing snapshot at terraform.tfstate