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

Import repository failing #174

Open MichaelReubenDevSlalom opened 10 months ago

MichaelReubenDevSlalom commented 10 months ago

Hi there,

Terraform Version

Terraform is running on the latest version, I'm creating a docker image weekly that will download the latest terraform version, the command here ran on a bitbucket pipeline, I created a custom pipeline to import resources.

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

terraform {
  required_providers {
    bitbucket = {
      source  = "DrFaust92/bitbucket"
      version = "2.35.0"
    }
  }
}

provider "bitbucket" {} // Using OAuth consumer with Env Vars 

resource "bitbucket_repository" "situate" {
  name              = "x"
  owner             = "x"
  project_key       = "x"
  description       = "x"
  is_private        = true
  pipelines_enabled = true
}

Panic Output

Stack trace from the terraform-provider-bitbucket_v2.35.0 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0xcb2033]

Expected Behavior

The Repository should have been imported and added into state

Actual Behavior

Logs from import command:

+ terraform import $importCommand
Acquiring state lock. This may take a few moments...
bitbucket_repository.situate: Importing from ID "$DOCKER_HUB_USERNAME/situate_tooling"...
bitbucket_repository.situate: Import prepared!
  Prepared bitbucket_repository for import
bitbucket_repository.situate: Refreshing state... [id=$DOCKER_HUB_USERNAME/situate_tooling]
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more
│ details.
╵
Stack trace from the terraform-provider-bitbucket_v2.35.0 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0xcb2033]
goroutine 84 [running]:
github.com/terraform-providers/terraform-provider-bitbucket/bitbucket.resourceRepositoryRead({0x0?, 0x0?}, 0xc0000eca80, {0xdb5f00?, 0xc00042b7c0?})
    github.com/terraform-providers/terraform-provider-bitbucket/bitbucket/resource_repository.go:325 +0x3d3
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xfc16e0?, {0xfc16e0?, 0xc00018b1d0?}, 0xd?, {0xdb5f00?, 0xc00042b7c0?})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:745 +0x87
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc0003ba540, {0xfc16e0, 0xc00018b1d0}, 0xc0001bf110, {0xdb5f00, 0xc00042b7c0})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:1044 +0x59e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc0003a4168, {0xfc16e0?, 0xc00018b0b0?}, 0xc00048e9c0)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/grpc_provider.go:616 +0x4a5
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc0003a00a0, {0xfc16e0?, 0xc00018a6f0?}, 0xc0001156e0)
    github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/tf5server/server.go:751 +0x4b1
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xe3be40?, 0xc0003a00a0}, {0xfc16e0, 0xc00018a6f0}, 0xc000232230, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:386 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00019e1e0, {0xfc5478, 0xc0003d0680}, 0xc0000eb7a0, 0xc0003b4a50, 0x150b3b0, 0x0)
    google.golang.org/grpc@v1.56.2/server.go:1337 +0xdf3
google.golang.org/grpc.(*Server).handleStream(0xc00019e1e0, {0xfc5478, 0xc0003d0680}, 0xc0000eb7a0, 0x0)
    google.golang.org/grpc@v1.56.2/server.go:1714 +0xa36
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.56.2/server.go:959 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.56.2/server.go:957 +0x18c
Error: The terraform-provider-bitbucket_v2.35.0 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.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply with the repository
  2. terraform state rm bitbucket_repository.x
  3. create the configuration in a new directory
  4. terraform import bitbucket_repository.x owner/repo_name

Important Factoids

Using Google Cloud for Remote state, same Bucket different prefix for the old and new states

References

None that I can see.

I'm probably going to delete the repository and just re-create it in the new state, as I haven't committed to it yet but I think this is important to fix.

DrFaust92 commented 8 months ago

MichaelReubenDevSlalom can you try latest provider version?