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

Issues With Archived Repositories #88

Closed
sprankhub opened this issue Jun 13, 2024 · 4 comments · Fixed by #89
Closed

Issues With Archived Repositories #88

sprankhub opened this issue Jun 13, 2024 · 4 comments · Fixed by #89

Comments

@sprankhub
Copy link
Contributor

This is about https://github.com/mage-os/terraform/actions/runs/9500022004/job/26182150184.

When a repository is archived, and we update some configuration like the branch protection rules, Terraform will try to apply the changes to the archived repository and GitHub will throw an error:

╷
│ Error: Repository is archived
│ 
│   with github_branch_protection.repositories["mage-os-website"],
│   on main.tf line 126, in resource "github_branch_protection" "repositories":
│  126: resource "github_branch_protection" "repositories" {
│ 
╵
Error: Process completed with exit code 1.

We had a similar issue in #54, but the new issue cannot be fixed in the same way.

My current idea is that we remove the old, archived repository from the Terraform state and from the variables.tf file. This way, Terraform might just ignore the existing, archived repository. Would that work, @Jakski?

Any other ideas?

@Vinai
Copy link
Contributor

Vinai commented Jun 14, 2024

Removing it from the terraform config sounds like a sensible way forward.

@Jakski
Copy link
Contributor

Jakski commented Jun 14, 2024

@sprankhub Yes. I believe solution you proposed will serve the best.

We could also filter repositories by .archived property in a for loop({ for key, value in ... : key => value if ... }), but it would require to manually remove github_branch_protection from state anyway.

https://developer.hashicorp.com/terraform/cli/commands/state/rm

I'm thinking about implementing state rm to be possible to invoke from a comment similar to how plans work right now, but I need to better refine this idea.

@furan917
Copy link

I'd defo go for the state removal.

You could use an expanded spec for conventional commits and then deignate specific keys for actions? Would make the knowledge share for actions maybe a bit easier to share with the team?

@sprankhub
Copy link
Contributor Author

I think the solution proposed by @Jakski to just filter out archived repos in a loop is a bit nicer, because it doesn't require two separate PRs to archive a repository. Theoretically, you'd first need to add the archived property, so that Terraform archives the repository and then, you'd need to remove the configuration from variables.tf and remove the state, so that it is ignored in the future. We don't need the second step if we just filter out archived repos. I'll send a PR soonish.

sprankhub added a commit to sprankhub/terraform that referenced this issue Jun 17, 2024
@sprankhub sprankhub linked a pull request Jun 17, 2024 that will close this issue
@Vinai Vinai closed this as completed in #89 Jun 18, 2024
Vinai added a commit that referenced this issue Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants