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

Unable to create bitbucket_deployment_variable #165

Open djgoku opened 1 year ago

djgoku commented 1 year ago

The bitbucket repository and deployment were both terraform imported. I deleted the bitbucket deployment variable in the bitbucket web ui before my terraform apply.

There was a slight issue with importing the bitbucket deployment. The documentation says to import with terraform import bitbucket_deployment.example repository/uuid but I had to actually use terraform import bitbucket_deployment.example workspace_name/repository_name:{uuid}. I can open another issue if you want for this.

I initially tried to use the data resource for bitbucket deployment but that didn't work out well. I'll create another issue for this.

Terraform Version

$ terraform -v
Terraform v1.4.6
on darwin_amd64
+ provider registry.terraform.io/carlpett/sops v0.7.2
+ provider registry.terraform.io/drfaust92/bitbucket v2.33.0

Affected Resource(s)

Terraform Configuration Files

resource "bitbucket_deployment" "test-repo-development" {
  repository = bitbucket_repository.test-repo.id
  name       = "development"
  stage      = "Test"
}

resource "bitbucket_repository" "test-repo" {
  owner             = "Owner"
  name              = "test-repo"
  slug              = "test-repo"
  fork_policy       = "no_public_forks"
  pipelines_enabled = true
}

resource "bitbucket_deployment_variable" "test-repo-API_KEY-development" {
  deployment = bitbucket_deployment.test-repo-development.id
  key        = "API_KEY"
  value      = data.sops_file.variables.data["test-repo-API_KEY-development"]
  secured    = true
}

Panic Output

https://gist.github.com/djgoku/05922d5554e67bae4ece84cd2b293ce0

Expected Behavior

Bitbucket Deployment variable should be deployed/applied/created.

Actual Behavior

Terraform apply fails with errors.

Steps to Reproduce

  1. terraform import bitbucket_deployment
  2. terraform apply
AGirin commented 7 months ago

+1 Same issue.

╷
│ Error: Plugin did not respond
│
│   with bitbucket_deployment_variable.ec["Test"],
│   on test.tf line 94, in resource "bitbucket_deployment_variable" "ec":
│   94: resource "bitbucket_deployment_variable" "ec" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-bitbucket_v2.37.2 plugin:

panic: runtime error: index out of range [1] with length 1

goroutine 16 [running]:
github.com/terraform-providers/terraform-provider-bitbucket/bitbucket.parseDeploymentId(...)
        github.com/terraform-providers/terraform-provider-bitbucket/bitbucket/resource_deployment_variable.go:72
github.com/terraform-providers/terraform-provider-bitbucket/bitbucket.resourceDeploymentVariableCreate({0xfa9050, 0xc00047cf30}, 0x0?, {0xd8de60?, 0xc00007f3b0?})
        github.com/terraform-providers/terraform-provider-bitbucket/bitbucket/resource_deployment_variable.go:80 +0x49b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xfa9050?, {0xfa9050?, 0xc00047cf30?}, 0xd?, {0xd8de60?, 0xc00007f3b0?})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:773 +0x7a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0000f50a0, {0xfa9050, 0xc00047cf30}, 0xc000460270, 0xc000452f00, {0xd8de60, 0xc00007f3b0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:909 +0xa7e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000347ea8, {0xfa9050?, 0xc00047ce40?}, 0xc000466690)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:1060 +0xdbc
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0002b61e0, {0xfa9050?, 0xc00047c450?}, 0xc000410070)
        github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:859 +0x56a
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xe20b60?, 0xc0002b61e0}, {0xfa9050, 0xc00047c450}, 0xc000410000, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:467 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001b01e0, {0xfad3b8, 0xc000357380}, 0xc00047b7a0, 0xc000362930, 0x1529458, 0x0)
        google.golang.org/grpc@v1.57.0/server.go:1360 +0xe15
google.golang.org/grpc.(*Server).handleStream(0xc0001b01e0, {0xfad3b8, 0xc000357380}, 0xc00047b7a0, 0x0)
        google.golang.org/grpc@v1.57.0/server.go:1737 +0x9e7
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        google.golang.org/grpc@v1.57.0/server.go:982 +0x8d
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 25
        google.golang.org/grpc@v1.57.0/server.go:980 +0x165

Error: The terraform-provider-bitbucket_v2.37.2 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
hoebelix commented 7 months ago

+1 Same issue.

toriath commented 6 months ago

Can confirm that using workspace_name/repository_name:{uuid} to reference the deployment works fine using v2.38.0.

bitbucket_deployment.test-repo-development.id is in that format and can be used. bitbucket_deployment.test-repo-development.uuid is not and shouldn't be.

I'd recommend to rename the issue as from the original error it seems to be a problem with the import documentation only?

Also, I think #162 might improve on this area as well.