Skip to content

[Bug]: tfstate issues lead to flux-system being deleted #740

@ionutleca

Description

@ionutleca

Describe the bug

We use the tf-controller to manage flux on multiple clusters via the tf-provider.
We had an issue when the tf-runner crashed before it got to write the state but after it managed to push the initial commits.

We missed the tf-runner crash and thought everything was good (as flux synced everything), but when terraform ran again it triggered the bootstrap process and this logic seems to have caused the entire flux-system namespace to go into Terminating.

Steps to reproduce

  1. Run the terraform (with a kustomization_override set).
  2. Delete the state.
  3. Rerun terraform.

Expected behavior

It would help if there was check for existing files in git before directly overwriting them with empty files.

Screenshots and recordings

No response

Terraform and provider versions

terraform {
  required_version = ">=1.1.5"

  required_providers {
    flux = {
      source = "fluxcd/flux"
      version = "1.3.0"
    }
    github = {
      source  = "integrations/github"
      version = "5.25.1"
    }
  }
}

Terraform provider configurations

provider "flux" {
  kubernetes = {
   ***
  }
  git = {
    url    = "ssh://[email protected]/${var.github_org}/${var.github_repository}.git"
    branch = var.github_branch
    ssh    = {
      username    = "git"
      private_key = tls_private_key.flux.private_key_pem
    }
  }

flux_bootstrap_git resource

resource "flux_bootstrap_git" "this" {
  depends_on = [github_repository_deploy_key.main]

  path                   = var.github_path
  version                = var.flux_version
  kustomization_override = templatefile("${path.module}/kustomization.yaml", {
                                             ***
                                         })
  registry               = var.registry
}

Flux version

v2.4.0

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions