Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
nbentfeld opened this issue May 14, 2024 · 0 comments
Labels
Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented

Comments

@nbentfeld
Copy link

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)

  • github_repository

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

  • Set Terraform variables terraform_github_app_id, terraform_github_app_installation_id and terraform_github_app_pem_file in Terraform Cloud workspace or github.tfvars file
  • run terraform plan (when using Terraform Cloud remote runs) or terraform plan -var-file github.tfvars (when running locally)

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

  • I agree to follow this project's Code of Conduct
@nbentfeld nbentfeld added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented
Projects
None yet
Development

No branches or pull requests

1 participant