terraform-provider-flux
terraform-provider-flux copied to clipboard
terraform apply Resource flux_bootstrap_git: Bootstrap run error
Description
Hi,
we are testing the terraform provider in version 0.23.0 with the new resource flux_bootstrap_git
and we are facing some issues.
Configuration
###variables.tf
k8s_apps_flux_version = "v0.39.0"
k8s_apps_flux_git_repository_ssh_url = "ssh://[email protected]/project/repo.git"
k8s_apps_flux_git_branch = "main"
main.tf
resource "flux_bootstrap_git" "flux" {
url = var.k8s_apps_flux_git_repository_ssh_url
path = "clusters/test"
branch = var.k8s_apps_flux_git_branch
version = var.k8s_apps_flux_version
ssh = {
username = "git"
private_key = var.private_key
}
}
So when i execute the plan i do see the resource being ready to be applied:
Terraform will perform the following actions:
# flux_bootstrap_git.flux will be created
+ resource "flux_bootstrap_git" "flux" {
+ author_name = "Flux"
+ branch = "main"
+ cluster_domain = "cluster.local"
+ components = [
+ "helm-controller",
+ "kustomize-controller",
+ "notification-controller",
+ "source-controller",
]
+ id = (known after apply)
+ interval = "1m0s"
+ log_level = "info"
+ namespace = "flux-system"
+ network_policy = true
+ path = "clusters/test"
+ registry = "ghcr.io/fluxcd"
+ repository_files = (known after apply)
+ secret_name = "flux-system"
+ ssh = {
+ private_key = (sensitive value)
+ username = "git"
}
+ url = "ssh://[email protected]/project/repo.git"
+ version = "v0.39.0"
+ watch_all_namespaces = true
}
but when i run the apply i do get the following error
flux_bootstrap_git.flux: Creating...
╷
│ Error: Bootstrap run error
│
│ with flux_bootstrap_git.flux,
│ on k8s.tf line 120, in resource "flux_bootstrap_git" "flux":
│ 120: resource "flux_bootstrap_git" "flux" {
│
│ reference not found
the git repository was empty, just initialized and it seems like flux did not like it. just by pushing a readme.md file to the repo did the trick. Closing
I think that this should still be an issue right? If I remember correctly the Flux CLI can deal with empty repositories so the Terraform Provider should be able to do the same.
I think that this should still be an issue right? If I remember correctly the Flux CLI can deal with empty repositories so the Terraform Provider should be able to do the same.
sounds good to me!
Acknowledged! I have now encountered a similar error
Same issue here. Empty repository raise "reference not found"
Adding a README workaround fixes the issues
Thanks for the tips
Any news regarding this issue?
we're still experiencing the same issue.
Any news on this? Still experiencing this issue.
@jonesbusy @ppodevlabs @banschikovde @MikeLamsma is this still an issue when using the latest version of the provider?
It's been a long time on my side, I cannot garantee that I can test again anytime soon. Thanks
Yes, confirmed it's still an issue with v1.2.3 on a new (uninitialised) ADO Git repo. As soon as I committed README.md and retried, the apply worked as expected.
@patkinson01 Unfortunately, the BitBucket terraform provider doesn't have the auto_init
functionality that the GitHub provider does. I think it would be a good idea to open an issue on that provider to enable that functionality. The flux_bootstrap_git
resource here expects an initialised repository to begin bootstrapping.
Hi @swade1987, I'm using an Azure DevOps repo for this but not managing it through Terraform as per guidance on https://registry.terraform.io/providers/fluxcd/flux/latest/docs/guides/github
Creating GitHub repositories with Terraform is generally not a good idea as they could easily be removed.
For me it's not a showstopper but maybe worth a note in the guides so people are aware. Admittedly, I've not scoured the docs, I'll do that first and if there's nothing there, raise a PR.
@patkinson01 A pull request on README files within https://github.com/fluxcd/terraform-provider-flux/tree/main/examples would be ideal and much appreciated. We could add the auto_init
to the examples with a comment next to the line.
@patkinson01
I understand the guide advises caution when managing GitHub repositories through Terraform, primarily because of the risk of accidental deletions. However, based on my own experiences, I'd like to share a different perspective that has worked well for me and previous organisations I've been part of.
I've successfully managed GitHub repositories using Terraform by segregating them into a dedicated Terraform project, named tf-github
. This approach allows for a clear demarcation of repository management tasks, keeping them isolated from other infrastructure as code endeavours. Additionally, utilising Terraform's remote state functionality helps in maintaining up-to-date configurations and mitigates the risks associated with direct management.
Given this, managing repositories in Terraform can be done effectively and safely with the right strategies in place, such as the one I described. It’s about creating a robust framework that anticipates and guards against potential mishaps.