integrations / terraform-provider-github

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

[BUG]: Cannot import github_repository into child module when authenticating with GitHub App installation token #2262

Open nbentfeld opened 1 month ago

nbentfeld commented 1 month ago

Expected Behavior

Plan is successful and displays resource module.test.github_repository.this to be imported

Actual Behavior

Plan errors with message

╷ │ Error: Cannot import non-existent remote object │ │ While attempting to import an existing object to │ "module.github_actions_repository.github_repository.this", the provider │ detected that no object exists with the given id. Only pre-existing objects │ can be imported; check that the id is correct and that it is associated │ with the provider's configured region or endpoint, or use "terraform apply" │ to create a new remote object for this resource. ╵

Terraform Version

Terraform v1.7.3 on Terraform Cloud remote runner + registry.terraform.io/integrations/github v6.2.1 also tried Terraform v1.8

Affected Resource(s)

Terraform Configuration Files

# terraform.tf
provider "github" {
  owner = "<test-organization>"
  app_auth {
    id              = var.terraform_github_app_id
    installation_id = var.terraform_github_app_installation_id
    pem_file        = var.terraform_github_app_pem_file
  }
}

# repositories.tf
import {
  id = "test"
  to = module.test.github_repository.this
}

module "test" {
  source       = "./modules/repository"
  name         = "test"
}

# ./modules/repository/main.tf
variable "name" {
  type = string
}

resource "github_repository" "this" {
  name       = var.name
}

Steps to Reproduce

When using the GITHUB_TOKEN environment variable to authenticate, the plan is successful with the expected output.

Debug Output

2024-05-14T13:15:17.382Z [INFO]  provider.terraform-provider-github_v6.2.1: 2024/05/14 13:15:17 [INFO] Selecting owner  from GITHUB_OWNER environment variable: timestamp=2024-05-14T13:15:17.379Z
module.test.github_repository.this: Refreshing state... [id=test]
2024-05-14T13:15:17.386Z [INFO]  provider.terraform-provider-azuread_v2.47.0_x5: 2024/05/14 13:15:17 
2024-05-14T13:15:17.426Z [INFO]  provider.terraform-provider-github_v6.2.1: 2024/05/14 13:15:17 [INFO] Removing repository /test from state because it no longer exists in GitHub: timestamp=2024-05-14T13:15:17.426Z
2024-05-14T13:15:17.427Z [WARN]  Provider "registry.terraform.io/hashicorp/github" produced an unexpected new value for module.test.github_repository.this during refresh.
      - Root object was present, but now absent
2024-05-14T13:15:17.427Z [ERROR] vertex "module.test.github_repository.this" error: Cannot import non-existent remote object
2024-05-14T13:15:17.427Z [ERROR] vertex "module.test.github_repository.this (expand)" error: Cannot import non-existent remote object

Panic Output

No response

Code of Conduct