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

Add `tag` to `git` settings within the flux provider

Open jamiezieziula opened this issue 1 year ago • 8 comments

Similar to how the provider supports specifying a branch, allow for a tag to be specified:

provider "flux" {
  kubernetes = {
    ...
  }
  git = {
    url = "some_url"
    tag = "1.0.0"
    ssh = {
      username    = "git"
      private_key = tls_private_key.flux.private_key_pem
    }
  }
}

jamiezieziula avatar Mar 28 '23 20:03 jamiezieziula

The issue with the current resource is that it applies the manifests and commits them to the repository. Could you explain your use case why you would need this?

phillebaba avatar Mar 29 '23 18:03 phillebaba

Hi @phillebaba sorry I missed your response from March - In our production clusters, we have flux syncing with a tag from a git repo, not a branch. We accomplished this in the "legacy" terraform setup by specifying a tag in the flux_sync data source. There is not way to currently do this in the new terraform resource flux_bootstrap_git. It seems to me that the flux provider specification is defining where flux should watch to sync from, and therefore we would need a tag parameter defined there. If there is another way to accomplish this - please let me know.

jamiezieziula avatar May 08 '23 18:05 jamiezieziula

The issue is that the new resource is not only bootstrapping the cluster but also committing the files to the Git repository. Meaning that the commit hash is is syncing from is fluid. If support for a tag were to be added the tag would have to be moved every time the resource makes a change in git. I don't see why you could just not use the resource as is and have it sync from the main branch?

phillebaba avatar May 09 '23 10:05 phillebaba

Creating extra GitRepos after bootstrap is not in scope for Flux TF provider. Use the Helm TF Provider with https://artifacthub.io/packages/helm/fluxcd-community/flux2-sync

stefanprodan avatar May 09 '23 11:05 stefanprodan

@phillebaba we can't just have it sync from main because we safeguard our code release to production with a tag - i have to imagine that this is a common use case among flux users

jamiezieziula avatar May 16 '23 22:05 jamiezieziula

@stefanprodan do you have a recommended install pattern documented somewhere?

Is the recommended approach to use this resource to bootstrap the cluster & and only use the gitrepo that is created to maintain the flux resources itself?

jamiezieziula avatar May 16 '23 22:05 jamiezieziula

I do not know of any documentation for the CLI bootstrap that would solve this. The goal of the provider is to support the same features that the CLI does for the bootstrap feature. Anything that false outside of that would be very difficult for us to support.

phillebaba avatar May 17 '23 20:05 phillebaba

@stefanprodan do you have a recommended install pattern documented somewhere?

Is the recommended approach to use this resource to bootstrap the cluster & and only use the gitrepo that is created to maintain the flux resources itself?

Hi @jamiezieziula , Terraform bootstrap resource is an IaC equivalent of this - https://fluxcd.io/flux/installation/bootstrap/generic-git-server/#ssh-private-key as it will update Git repository in specified branch with GitOps ToolKit (gotk) manifests (similar to this content https://github.com/fluxcd/flux2-kustomize-helm-example/tree/main/clusters/staging/flux-system ) - tags just won't work.

Once flux-system namespace manifests will be configured and FluxCD controllers running - you are free to extend the configuration with Kustomisations and GitRepository (pointing to whatever repo with your app definition and any reflink needed) resources stored in same folder you specified in the path parameter of flux_bootstrap_git Terraform resource, see docs here https://fluxcd.io/flux/guides/repository-structure/#repository-structure-2 and good examples provided here : https://github.com/fluxcd/flux2-kustomize-helm-example/tree/main/clusters/staging

babinkos avatar Feb 22 '24 10:02 babinkos

@stefanprodan I feel like this issue can be closed.

swade1987 avatar Mar 29 '24 13:03 swade1987