idoavrah / terraform-tui

Terraform textual UI
https://pypi.org/project/tftui/
Apache License 2.0
1.03k stars 30 forks source link

visualization tfplan created outside tftui #62

Open Mykhailo-Roit opened 8 months ago

Mykhailo-Roit commented 8 months ago

Does it possible to visualization tfplan created outside tftui (e.g. by terragrunt with extra options like several dynamic generated links to vars files)?

idoavrah commented 8 months ago

Hi Mykhailo,

I'm not a terragrunt user myself, so I'll need more input.

  1. Does the plan output look exactly like a standard terraform plan, so that it'll parse the same way?

  2. Can you give me an example of such a terragrunt command? Maybe I'll add the option to manually edit the plan command on-screen, or get it from an environment variable / command parameter, etc.

Mykhailo-Roit commented 8 months ago

Hi @idoavrah terragrunt is a wrapper for a terraform. It only makes easy terraform execution. Terragrunt as terraform wrapper generate plan: terragrunt plan -out tfplan can execute command like this terraform plan -var-file=../configs/identity-prd.tfvars -var-file=../configs/resources-prd.tfvars -var-file=../configs/subnets-prd.tfvars -out tfplan

So you can use only terraform to generate tfplan file terraform plan -out tfplan

FYI my today pain is analyze a huge list after terraform plan: "Plan: 476 to add, 0 to change, 38 to destroy."

idoavrah commented 8 months ago

I can't use an existing plan file, because I'm parsing the OUTPUT text, not the binary file itself.

Is the only difference between a "regular" plan command and the one you've written is the number of var-files? If I add support for multiple varfiles, will it suffice? (assuming you're running terragrunt as the executable).

Mykhailo-Roit commented 8 months ago
  1. I can run terraform show tfplan -no-color >tfplan.txt to convert plan to the plain text format or generate json using terraform show -json tfplan > tfplan.json. This is not a problem

  2. What terraform command do you use for getting plan to analyze?

  3. I'm parsing the OUTPUT text, not the binary file itself.

But here I see that you use binary format https://github.com/idoavrah/terraform-tui/blob/main/tftui/plan.py#L36

  1. Is the only difference between a "regular" plan command and the one you've written is the number of var-files?

yes, but names for these vars file generated based on execution directory name Here part of the terragrunt config with generating var-file names

    arguments = [
      "-var-file=./resources-${local.env}.json",
      "-var-file=./subnets-${local.env}.json",
      "-var-file=./../tf-configs/${local.zone}/terraform-${local.env}.tfvars"
    ]