Terraform Provider Flux

repository·main·Indexed 19 days ago

https://github.com/fluxcd/terraform-provider-flux

A 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).

Tokens
6.7K
Snippets
11
Records
56
Agent score
65%

What's inside terraform-provider-flux

  1. Bootstrap Flux using the flux_bootstrap_git resource

    main
    The flux_bootstrap_git resource 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.
  2. Available bootstrapping guides

    main

    The 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_git resource. This is the recommended approach if you do not want to perform initial flux bootstrapping via the provider.
  3. Bootstrap a KinD cluster with Flux using GitHub via PAT

    main

    This 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.this
  4. Install Flux with Helm via Terraform

    main

    This example demonstrates how to install Flux using the upstream Flux Helm chart instead of the recommended flux_bootstrap_git method. This approach is useful when Flux needs to be installed without any bootstrap configuration.

    The workflow involves:

    1. Bootstrapping a KinD cluster.
    2. Installing the upstream Flux helm chart.
    3. Leveraging the flux2-sync helm chart to construct a GitRepository and Kustomization to sync manifests into the cluster.
  5. Configure the Flux provider

    main

    The Flux provider installs and configures Flux in a Kubernetes cluster. It requires a kubernetes configuration block for cluster access and a git configuration 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"
      }
    }