flux-iac/tofu-controller

No plan output using Terraform Cloud 'local' execution mode

Opened this issue · 5 comments

I use Terraform Cloud only to store TF backend state files, still use TF controller to plan and apply Terraform changes.

Screenshot 2023-09-14 at 20 11 26

When I deploy a Terraform CR, manual approval is configured so that I can confirm the plan. It looks good that Terraform CR is created successfully and plan ID is also provided. But if I check the plan output which is created as a Kubernetes secret, there is no actual plan. I base64 decoded this secret and unzip it, the contents of this file is dummy plan.

Meanwhile, the runner pod logs this:

Screenshot 2023-09-14 at 20 18 30

You can see the Terraform Cloud backend is correctly initiated, it seems that TF controller didn't run terraform plan at all.

For another test, I enabled storeReadablePlan: human in Terraform CR. Then it failed to create the Terraform CR. The runner log gives the error:

{"level":"error","ts":"2023-09-14T14:33:10.849Z","logger":"runner.terraform","msg":"unable to get the plan output for json","instance-id":"cd68b59d-ebe6-4b61-90ce-1793ab33cb6a","error":"\nError: Failed to read the given file as a state or plan file\n\nState read error: Error loading statefile: open tfplan: no such file or\ndirectory\n\nPlan read error: open tfplan: no such file or directory\n"}

This makes me believe there was no plan generated at all.

Can you please check this? If this is a bug, can you please fix it? Thanks!

Sorry but we support only the "Remote" Execution Mode for Terraform Cloud at the moment.

But we support the mix mode by using Remote execution mode with spec.approvePlan: auto together wtih the Branch Planner. With Branch Planner + Terraform Cloud, you will get the same manual concept similar to the manual approve workflow.

We'll have a tutorial on this very soon after ironing out the new RC.

@chanwit Thank you for the information. Unfortunately, I want the TFC Local execution mode, not just manual approval. Do you have any plan to support TFC Local execution mode?

Yep, we planned to support it and other Terraform Cloud feature, but our priority now is the Branch Planner system.