terraform-provider-github icon indicating copy to clipboard operation
terraform-provider-github copied to clipboard

[BUG]: archive_on_destroy leads to failed deletions of related resources like labels

Open Danielku15 opened this issue 2 years ago • 2 comments

Expected Behavior

When having archive_on_destroy set on github_repository removal of the whole repository inclusive related resources should not lead to an error.

Actual Behavior

As soon a repository is archived in GitHub, it becomes readonly. But Terraform will still try to delete related resources like github_issue_label. You would want to remove everything from your terraform code related to the repository and not keep those related items.

This provider will call deletes and fail ultimately:

Error: DELETE https:///repos///labels/

Those failed delete operations should be ignored in this case or done before the repository archiving.

Terraform Version

Terraform Version: 1.5.6 on Windows x64 CDKTF Version: 0.18.0 (C#) Provider: NuGet HashiCorp.Cdktf.Providers.Github 11.0.1

Affected Resource(s)

  • github_repository
  • github_issue_label

Likely more? I assume anything related to repositories like:

  • github_repository_***
  • github_team_repository
  • github_collaborator
  • github_collaborators

Terraform Configuration Files

Hard to share as we have a dynamic project with C# CDKTF. But I guess something like this will allow reproduction of a basic case:


resource "github_repository" "example" {
  name        = "example"
  description = "My awesome codebase"
  visibility = "public"
  archive_on_destroy = true
}

resource "github_issue_label" "example" {
  repository = github_repository.example.name
  name       = "Urgent"
  color      = "FF0000"
}

Steps to Reproduce

  1. Setup a new repository with archive_on_destroy set to true.
  2. Create resources relating directly to the repository like labels, branch protections etc.
  3. terraform apply
  4. Delete the repository and related resources from the file
  5. terraform apply
  6. Expect it to complete successfully with the repository archived and all resources removed from the tfstate.

Personally I wouldn't mind if first all related resources are deleted and then only the repository is archived leaving only the code behind.

Debug Output

No response

Panic Output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

Danielku15 avatar Aug 31 '23 15:08 Danielku15

I tried to reproduce this but don't see the same issue described in the post anymore. However, I did notice that the label deletion goes through as expected.

I haven't tested other aspects of an archived repository though.

Also ran into two other behaviors:

  • https://github.com/integrations/terraform-provider-github/issues/2117
  • https://github.com/integrations/terraform-provider-github/issues/2118

arunsathiya avatar Jan 26 '24 19:01 arunsathiya

I've run into this bug somewhat recently, but with a previous release. I'll retry to see if its working as expected now with the latest version of the provider.

RobertWHurst avatar Feb 01 '24 21:02 RobertWHurst