Skip to content

Conversation

@kad-hollac1
Copy link
Contributor

No description provided.

@kad-hollac1 kad-hollac1 requested a review from acch as a code owner January 15, 2026 20:38
@kad-hollac1
Copy link
Contributor Author

Similarly to https://gitea.com/gitea/terraform-provider-gitea/commit/8d483a8a8df956a026defed92f313258197a4858.
I'm not (yet) sure how to test this. How to delete a resource explicitly?

@kad-hollac1 kad-hollac1 force-pushed the feat/archive-on-destroy branch 2 times, most recently from 5545d8c to f42b597 Compare January 20, 2026 15:01
@acch
Copy link
Member

acch commented Jan 24, 2026

Hi @kad-hollac1, thanks for opening this PR! Can you describe the specific scenario you're addressing with this change?

Also, please take a look at the linter errors.

@kad-hollac1 kad-hollac1 force-pushed the feat/archive-on-destroy branch from f42b597 to 66f11d5 Compare January 26, 2026 10:23
@kad-hollac1
Copy link
Contributor Author

Sure! In our organisation, we're moving towards managing our Forgejo instance from code, including the repositories. As our developers are human, we want to prevent them from (accidentally) deleting data. As such we want to preserve a repository when it is removed from state by Terraform.

We can set a lifecycle tag to prevent destroy, but that means that that teams keep unused repositories in their configuration. Hence we've taken the GitHub route to implement [0].

[0] https://github.com/integrations/terraform-provider-github/blob/main/github/resource_github_repository.go#L326

@kad-hollac1 kad-hollac1 force-pushed the feat/archive-on-destroy branch from 66f11d5 to badc067 Compare January 26, 2026 11:25
@acch acch added enhancement New feature or request go Pull requests that update Go code labels Jan 30, 2026
@acch
Copy link
Member

acch commented Feb 1, 2026

Hi @kad-hollac1, many thanks for the explanation. This looks like an interesting approach - thank you very much for the contribution!

We should add some testing for the behavior, though. I'd suggest the following approach:

  1. Add a test step to create a repo with archive_on_destroy = true.
  2. Add a test step without the repo configuration. This will cause terraform apply to destroy/archive the resource, and remove it from state.
  3. Add a test step with an import block. This will cause terraform apply to re-import the resource. All attributes should remain unchanged; except for archived, which should now be true.

Does this make sense?

@kad-hollac1 kad-hollac1 force-pushed the feat/archive-on-destroy branch from badc067 to f459411 Compare February 2, 2026 05:14
@kad-hollac1
Copy link
Contributor Author

kad-hollac1 commented Feb 2, 2026

I've put it in two steps, the second step has only the data source of the repo. Thanks for the suggestion! :)

[EDIT]
The import step is still needed to be able to delete the testing org afterwards, so I still added it.

@kad-hollac1 kad-hollac1 force-pushed the feat/archive-on-destroy branch 12 times, most recently from c08472a to 9d9389e Compare February 2, 2026 10:30
@kad-hollac1 kad-hollac1 force-pushed the feat/archive-on-destroy branch from 9d9389e to 4d8d3e8 Compare February 2, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants