terraform-provider-flux icon indicating copy to clipboard operation
terraform-provider-flux copied to clipboard

terraform apply Resource flux_bootstrap_git: Bootstrap run error

Open ppodevlabs opened this issue 2 years ago • 9 comments

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

ppodevlabs avatar Feb 09 '23 15:02 ppodevlabs

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

ppodevlabs avatar Feb 11 '23 22:02 ppodevlabs

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.

phillebaba avatar Feb 14 '23 10:02 phillebaba

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!

ppodevlabs avatar Feb 14 '23 10:02 ppodevlabs

Acknowledged! I have now encountered a similar error

banschikovde avatar Feb 18 '23 03:02 banschikovde

Same issue here. Empty repository raise "reference not found"

Adding a README workaround fixes the issues

Thanks for the tips

jonesbusy avatar Mar 26 '23 09:03 jonesbusy

Any news regarding this issue?

yardenw-terasky avatar Jul 23 '23 14:07 yardenw-terasky

we're still experiencing the same issue.

ndrscodes avatar Nov 23 '23 09:11 ndrscodes

Any news on this? Still experiencing this issue.

MikeLamsma avatar Feb 22 '24 13:02 MikeLamsma

@jonesbusy @ppodevlabs @banschikovde @MikeLamsma is this still an issue when using the latest version of the provider?

swade1987 avatar Mar 27 '24 21:03 swade1987

It's been a long time on my side, I cannot garantee that I can test again anytime soon. Thanks

jonesbusy avatar Mar 28 '24 06:03 jonesbusy

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 avatar Mar 29 '24 10:03 patkinson01

@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.

swade1987 avatar Mar 29 '24 11:03 swade1987

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 avatar Mar 29 '24 11:03 patkinson01

@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.

swade1987 avatar Mar 29 '24 11:03 swade1987

@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.

swade1987 avatar Mar 29 '24 14:03 swade1987