flux-iac / tofu-controller

A GitOps OpenTofu and Terraform controller for Flux
https://flux-iac.github.io/tofu-controller/
Apache License 2.0
1.29k stars 137 forks source link

Unnecessary Terraform Planning Object Creation in Branch Planner #899

Open chanwit opened 1 year ago

chanwit commented 1 year ago

The current behavior of the branch planner is that it creates a terraform object whenever a PR is created, regardless of the type or scope of the changes in the PR. This means even minor changes like updating a README.md (which isn't managed by Terraform) results in the creation of a terraform object, which the system then continues to reconcile.

The branch planner should be improved to check the nature of the changes in a PR. If the changes do not concern Terraform-managed code (.tf files) or objects (.yaml files), then there's no need to create a terraform object.

navpreet-securitas commented 1 year ago

additional possible bug:

when updating variable in terraform object like :

 path: ./terraform/stack/abc-test
  sourceRef:
    kind: GitRepository
    name: abckconfig
    namespace: flux-system
  vars:
    - name: env
      value: qa
    - name: backup_retention_days
      value: "7"
 path: ./terraform/stack/abc-test
  sourceRef:
    kind: GitRepository
    name: abckconfig
    namespace: flux-system
  vars:
    - name: env
      value: qa
    - name: backup_retention_days
      value: "15"

it does not get reflected in new terraform object created by branch planner. Hence it gives no changes in Infrastructure in PR comment.

abc-test-qa-trying-change-in-qa-73   True      No drift: trying-change-in-qa@sha1:02c6a013e5e74a3a6e8208147f4bf60bf09021bb   21m
cybercyst commented 1 year ago

@navpreet-securitas I have this exact issue and just created a bug about it!

chanwit commented 1 year ago

@navpreet-securitas @cybercyst Thanks for the addition.

I'll file it as a separate one.

lasomethingsomething commented 1 year ago

One proposed solution in #846 was to use labels to filter PRs when activating the branch planning mode.