terraform-provider-flux: 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://git@mybitbucket.org/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://git@mybitbucket.org/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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 15 (5 by maintainers)
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.
@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.
@patkinson01 Unfortunately, the BitBucket terraform provider doesn’t have the
auto_initfunctionality that the GitHub provider does. I think it would be a good idea to open an issue on that provider to enable that functionality. Theflux_bootstrap_gitresource here expects an initialised repository to begin bootstrapping.