integrations / terraform-provider-github

Terraform GitHub provider
https://www.terraform.io/docs/providers/github/
MIT License
899 stars 741 forks source link

Importing github_repository_environment state crashes with SIGSEGV #976

Closed damir-dezeljin closed 5 months ago

damir-dezeljin commented 2 years ago

Terraform Version

$ terraform -v
Terraform v1.0.8
on linux_amd64
+ provider registry.terraform.io/hashicorp/github v4.18.0
+ provider registry.terraform.io/hashicorp/google v4.0.0
+ provider registry.terraform.io/hashicorp/google-beta v4.0.0
+ provider registry.terraform.io/hashicorp/null v3.1.0
+ provider registry.terraform.io/hashicorp/random v3.1.0
+ provider registry.terraform.io/integrations/github v4.18.0

Affected Resource(s)

github_repository_environment

Terraform Configuration Files

resource "google_folder" "iac_folder" {
  display_name = "Infrastructure as Code"
  parent       = "folders/${var.folder_id}"
}

resource "google_project" "iac_tools" {
  name            = "IAC TOOLS"
  project_id      = "tools-iac-myorg"
  folder_id       = google_folder.iac_folder.id
  billing_account = var.billing_account
}

resource "google_project" "iac_tfstate" {
  name            = "IAC TFSTATE"
  project_id      = "tfstate-iac-myorg"
  folder_id       = google_folder.iac_folder.id
  billing_account = var.billing_account
}

resource "google_project_service" "iac_tfstate_proj_services" {
  for_each                   = toset(["compute", "storage-component"])
  project                    = google_project.iac_tfstate.project_id
  service                    = "${each.value}.googleapis.com"
  disable_on_destroy         = false
  disable_dependent_services = false
  provisioner "local-exec" {
    command = "sleep 20s"
  }
}

resource "google_storage_bucket" "iac_tfstate_storage" {
  name                        = "tfstate-iac-myorg"
  location                    = "EU"
  uniform_bucket_level_access = false
  project                     = google_project.iac_tfstate.project_id

  versioning {
    enabled = true
  }

  depends_on = [
    google_project.iac_tfstate
  ]
}

resource "google_service_account" "tf_management" {
  project      = google_project.iac_tools.project_id
  account_id   = "tf-my-saacc"
  display_name = "TF xyz"
  description  = "Terraform account for xyz"
  depends_on = [
    google_project.iac_tools
  ]
}

resource "github_repository" "tf_mgmt" {
  name                   = var.tf_mgmt__repo
  description            = "Terraform xyz"
  visibility             = "internal"
  has_issues             = false
  has_wiki               = false
  allow_merge_commit     = true
  allow_squash_merge     = true
  allow_rebase_merge     = true
  delete_branch_on_merge = true
  auto_init              = false
  vulnerability_alerts   = false
}

resource "github_repository_environment" "myenv" {
  environment = var.tf_mgmt__prod_environment
  repository  = github_repository.tf_mgmt.name
  depends_on = [
    github_repository.tf_mgmt
  ]
}

^^^ NOTE: I changed /masked a few sensitive names, I hope I didn't introduce any error with this. Still, the concept should be same. I'm experiencing the issue when importing the state with:

$ terraform import module.mycore.github_repository_environment.myenv 'tf-mgmt:MyEnv'

Debug Output

https://gist.github.com/damir-dezeljin/92a280c32e8d9671faea2de24384286d

Expected Behavior

The environment being imported in the TfState.

Actual Behavior

The import operation failed.

Steps to Reproduce

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

  1. Create a GitHub repo.
  2. Create a GitHub environment in that repo.
  3. Create all dependent resources in TF (repo and environment). 3.terraform import module.mycore.github_repository_environment.myenv 'tf-mgmt:MyEnv'

Important Factoids

n/a

References

n/a

0xBigBoss commented 2 years ago

This is still an issue with v5.2.0.

stacktrace ``` Stack trace from the terraform-provider-github_v5.2.0 plugin: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x78 pc=0x19f7eb0] goroutine 64 [running]: github.com/integrations/terraform-provider-github/v5/github.resourceGithubRepositoryEnvironmentRead(0xc0002288c0, {0x1a86d00?, 0xc00013ab80?}) github.com/integrations/terraform-provider-github/v5/github/resource_github_repository_environment.go:125 +0x490 github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000781d60, 0xc000181d10, {0x1a86d00, 0xc00013ab80}) github.com/hashicorp/terraform-plugin-sdk@v1.17.2/helper/schema/resource.go:470 +0x1aa github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc000116a50, {0xc00058d0e0?, 0x10b3ba6?}, 0xc00058d0e0) github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/helper/plugin/grpc_provider.go:535 +0x34b github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler({0x1c2a1c0?, 0xc000116a50}, {0x1e89730, 0xc00017a120}, 0xc00058d080, 0x0) github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/tfplugin5/tfplugin5.pb.go:3269 +0x170 google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002b0380, {0x1e8cea0, 0xc000682340}, 0xc00097a6c0, 0xc0003acc30, 0x2534710, 0x0) google.golang.org/grpc@v1.46.2/server.go:1283 +0xcfd google.golang.org/grpc.(*Server).handleStream(0xc0002b0380, {0x1e8cea0, 0xc000682340}, 0xc00097a6c0, 0x0) google.golang.org/grpc@v1.46.2/server.go:1620 +0xa1b google.golang.org/grpc.(*Server).serveStreams.func1.2() google.golang.org/grpc@v1.46.2/server.go:922 +0x98 created by google.golang.org/grpc.(*Server).serveStreams.func1 google.golang.org/grpc@v1.46.2/server.go:920 +0x28a Error: The terraform-provider-github_v5.2.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. ```
adaadb6 commented 1 year ago

Still experiencing this issue on TF version 1.4.2 and GitHub provider version v5.20.0

Error ``` Stack trace from the terraform-provider-github_v5.20.0 plugin: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x78 pc=0xaadc9c] goroutine 1203 [running]: github.com/integrations/terraform-provider-github/v5/github.resourceGithubRepositoryEnvironmentRead(0x40000ad180, {0xb50840?, 0x40002160c0?}) github.com/integrations/terraform-provider-github/v5/github/resource_github_repository_environment.go:137 +0x3ec github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0x400002ed20, 0x400031d860, {0xb50840, 0x40002160c0}) github.com/hashicorp/terraform-plugin-sdk@v1.17.2/helper/schema/resource.go:470 +0x1a0 github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0x4000288a38, {0x4000952ae0?, 0x0?}, 0x4000952ae0) github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/helper/plugin/grpc_provider.go:535 +0x32c github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler({0xd48a60?, 0x4000288a38}, {0x10f0900, 0x400092aa50}, 0x40000accb0, 0x0) github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/tfplugin5/tfplugin5.pb.go:3269 +0x170 google.golang.org/grpc.(*Server).processUnaryRPC(0x4000206000, {0x10f4868, 0x400025c000}, 0x4000979440, 0x4000385260, 0x19094d0, 0x0) google.golang.org/grpc@v1.50.1/server.go:1340 +0xb7c google.golang.org/grpc.(*Server).handleStream(0x4000206000, {0x10f4868, 0x400025c000}, 0x4000979440, 0x0) google.golang.org/grpc@v1.50.1/server.go:1713 +0x854 google.golang.org/grpc.(*Server).serveStreams.func1.2() google.golang.org/grpc@v1.50.1/server.go:965 +0x88 created by google.golang.org/grpc.(*Server).serveStreams.func1 google.golang.org/grpc@v1.50.1/server.go:963 +0x29c Error: The terraform-provider-github_v5.20.0 plugin crashed! ```

Update: Same issue as this https://github.com/integrations/terraform-provider-github/issues/840

github-actions[bot] commented 6 months ago

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!