Terraform Provider Flux
repository·main·Indexed 19 days ago
https://github.com/fluxcd/terraform-provider-fluxA Terraform and OpenTofu plugin that enables the bootstrapping of Kubernetes clusters using Flux v2. It allows users to manage GitOps infrastructure, featuring resources like flux_bootstrap_git to initialize Flux via Git repositories such as GitHub and Forgejo using SSH or Personal Access Tokens (PAT).
What's inside terraform-provider-flux
- The Flux provider for Terraform is a plugin designed to enable the bootstrapping of Kubernetes clusters using Flux v2. It allows you to manage Flux installation and configuration through Terraform or OpenTofu workflows.
Bootstrap Flux using the flux_bootstrap_git resource
mainTheflux_bootstrap_gitresource automates the bootstrapping process of Flux. It commits Flux component manifests to a specified Git repository and configures a Kubernetes cluster to synchronize with that same repository. This ensures that your Git repository becomes the single source of truth for your Flux installation and subsequent GitOps workflows.Available bootstrapping guides
mainThe provider supports various bootstrapping patterns depending on your Git provider and authentication method. Available examples include:
GitHub Bootstrapping
- Using a Personal Access Token (PAT)
- Using SSH
- Using SSH with GPG
- Self-managing the SSH keypair secret
- Using SSH with Flux customizations
- Using SSH and GPG with inline Flux customizations
GitLab & Forgejo Bootstrapping
- GitLab via SSH
- GitLab via SSH and GPG
- Forgejo via SSH
Alternative Installation
- Helm Release: Using a Helm Release instead of the
flux_bootstrap_gitresource. This is the recommended approach if you do not want to perform initial flux bootstrapping via the provider.
Bootstrap a KinD cluster with Flux using GitHub via PAT
mainThis example demonstrates how to automate the bootstrapping of a KinD (Kubernetes in Docker) cluster with Flux using a GitHub repository. Authentication to GitHub is handled via a Personal Access Token (PAT).
To ensure security, it is recommended to use a fine-grained PAT and a dedicated Flux user. The workflow involves creating a GitHub repository, initializing it, and then using the Flux provider to bootstrap the cluster.
# This is a conceptual guide based on the example structure. # It uses the following resources: # - flux_bootstrap_git.this # - github_repository.this # - kind_cluster.thisInstall Flux with Helm via Terraform
mainThis example demonstrates how to install Flux using the upstream Flux Helm chart instead of the recommended
flux_bootstrap_gitmethod. This approach is useful when Flux needs to be installed without any bootstrap configuration.The workflow involves:
- Bootstrapping a KinD cluster.
- Installing the upstream Flux helm chart.
- Leveraging the flux2-sync helm chart to construct a
GitRepositoryandKustomizationto sync manifests into the cluster.
Requirements for Helm-based Flux installation
mainTo use the Helm-based installation example, ensure the following versions are met:
Name Version terraform >= 1.7.0 github >= 6.1 helm >= 2.12 kind >= 0.4 kubernetes >= 2.27 tls >= 4.0 Requirements for GitHub via SSH Flux Bootstrap
mainTo use this bootstrap configuration, ensure the following software and provider versions are installed or configured:
Tools/Software:
terraform>= 1.7.0flux>= 1.2github(CLI/API context) >= 6.1kind>= 0.4tls(context) >= 4.0
Terraform Providers:
flux>= 1.2github>= 6.1kind>= 0.4tls>= 4.0
Requirements for GitLab via SSH bootstrap example
mainRequirements for GitHub via PAT bootstrapping
mainConfigure the Flux provider
mainThe Flux provider installs and configures Flux in a Kubernetes cluster. It requires a
kubernetesconfiguration block for cluster access and agitconfiguration block specifying the repository to bootstrap from.Basic configuration example:
provider "flux" { kubernetes = { config_path = "~/.kube/config" } git = { url = "https://example.com" } }provider "flux" { kubernetes = { config_path = "~/.kube/config" } git = { url = "https://example.com" } }Requirements for GitHub via SSH bootstrap example
mainImport an existing Flux installation
mainIf Flux is already installed in a cluster, you can import it into your Terraform state by providing the namespace where Flux is installed.
terraform import flux_bootstrap_git.this flux-system