-
Notifications
You must be signed in to change notification settings - Fork 170
Description
I'd like to generate my own rendered plan with the branch planner, and provide a custom github status check that links to the rendered plan. I was hoping to just hook into the tfplan secret that gets created and I'd write something for the rest of it.
My original intent was to create an argo-events resource event-source that watches for secrets created with the correct annotations and trigger an argo workflow that runs against that plan and pushes the result somewhere that can serve it. I had found Rover and wanted to use it as a starting off point (as it looks out of date), but then found that the Terraform resource created with the branch planner is hard coded to be a human-readable plan.
https://github.com/flux-iac/tofu-controller/blob/main/internal/server/polling/terraform.go#L109
I've also tried to actually read the generated plan in the base Terraform resource's tfplan-* secret to poc the flow, but I was unable to decode the tfplan file, I was expecting to see a tfplan.json or similar in the archive because I've got humanReadablePlan: json. I want to believe that this is my mistake because if it were, I'd be able to make some minor code changes to the controller to poc the result I'm after.
I've stopped my discovery here.
It would take a new CRD version to add everything I'd want to implement my solution. I'd want to have a way to add custom labels/annotations so I can filter for the relevant secrets, a way to disable the pull request comments on the branch planner runs, and optionally a way to write multiple secret objects. The multiple objects only makes sense to maintain the controller's functionality, or maybe you'd still want to output the pr comments. It could also be that disabling PR comments will enable the json plan.
Something like this:
apiVersion: infra.contrib.fluxcd.io/v1alpha2
kind: Terraform
metadata:
name: branch-planner-demo
namespace: flux-system
spec:
approvePlan: auto
path: ./cluster/flux/apps/tf-demo/
interval: 1m
sourceRef:
kind: GitRepository
name: flux-system
namespace: flux-system
# storeReadablePlan: 'json'
storePlan:
- type: human
target:
kind: ConfigMap
# defaults to this .metadata.namespace
# namespace: flux-system
labels: {}
annotations: {}
- type: json
target:
kind: ConfigMap
namespace: rover-render
labels:
# should this metadata would be default?
github.com/sha: '$sha'
github.com/branch: '$branch'
github.com/repo: '$repo'
github.com/owner: '$owner'
planned-at: '$plannedAt'
annotations:
rover.io/branch-planner: 'true'
branchPlanner:
enablePathScope: true
disablePullRequestComment: true
useParentStorePlanConfig: true
runnerPodTemplate:
spec:
envFrom: []