I have a module that creates GitHub Repos. This is working fine. I am trying to add to now so we can update the CODEOWNER file. Using Terraform I have:
Created a Branch using github_branch
Created a CODEOWNERS file using github_repository_file
Created a Pull Request using github_repository_pull_request
When I run it once it works great. Then if I run it for another repo it failes. Does not seem to get paste refreshing state.
Error: unexpected status code: 404 Not Found
│
│ with module.fusionoperate_github_repository.github_repository_file.codeowners,
│ on …\terraform-github-fusionoperate_repository\main.tf line 37, in resource “github_repository_file” “codeowners”:
│ 37: resource “github_repository_file” “codeowners” {
What happens in the state file for a Branch and PR that get approved and are now gone the next time it runs?
I have not used the GitHub Terraform provider - however, if I try to reason about this using general Terraform knowledge, I would expect the only way this approach would work, would be if the branch created with github_branch was never deleted - otherwise, Terraform is just going to end up either erroring or trying to recreate resources that you no longer want recreated, depending on the design of the provider.
For the use-case of performing one-time initial setup, it is probably better to do this from an external script invoked as a provisioner, so that it can do the initial setup after the repository is created, in a way which doesn’t get tracked in Terraform’s state.
No. Terraform is designed to describe the state you are trying to achieve. There is no concept of “one time” or ordering of process steps. If you are wanting to be able to do more programmatic things you might be better off using a different tool, such as Ansible.