Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to have an empty output #6

Open
xocasdashdash opened this issue Sep 29, 2022 · 3 comments
Open

Add an option to have an empty output #6

xocasdashdash opened this issue Sep 29, 2022 · 3 comments
Labels
question Further information is requested

Comments

@xocasdashdash
Copy link

Loving the tool,

I'm looking to add an option in order to know if the plan is empty and either output a preset message (no changes in current plan), putting out an empty plan or exiting with a specific error code (terraform already does this with the -detailed-exitcode flag).

What do you think?

@dineshba
Copy link
Owner

dineshba commented Oct 5, 2022

Thanks for trying out the tool @xocasdashdash .

Today, we have to run terraform plan -out=tfplan and use the output to tf-summarize. We can use the -detailed-exitcode for terraform plan and not continue if there is no diff exit code.

Thoughts ?

@dineshba dineshba added the question Further information is requested label Oct 15, 2022
@nitrocode
Copy link

Is the command something like this?

terraform plan -detailed-exitcode -out planfile
status=$?
if [[ "$status" == "0" ]]; then
  echo "no changes"
elif [[ "$status" == "1" ]]; then
  echo "terraform threw an error"
elif [[ "$status" == "2" ]]; then
  echo "diff detected, running tf-summarizer"
  status=0
  tf-summarizer planfile
else
  echo "terraform threw an unknown error"
fi
rm -f planfile
exit $status

@aquam8
Copy link

aquam8 commented Aug 1, 2023

I also have the same query. I use Terragrunt which generates lot of Terraform plans. After the json plans are generated, I iterate through all the json files, and print the path to reference the terraform module/source (see below PATH:) and call tf-summarize for each plan. However when the plan are empty, then tf-summarize will return nothing but I am still display the module path with no changes (example PATH: components/worker/event-bus/). It would be much better if I could test tf-summarize invocation to know if it has detected changes so I can avoid print the path when there are no detected changes.

Example:

TERRAFORM SUMMARY
------------------------

PATH: components/worker/event-bus/

PATH: components/worker/kinesis-to-s3/
|---aws_kinesis_firehose_delivery_stream
|	|---extended_s3_stream(~)

PATH: components/worker/sqs/eventbus-dlq/

PATH: components/worker/sqs/mpgs-transactions/

PATH: components/org-service/sqs/external-merchant-provisioner/

PATH: components/provisioning-api/acm/v2/

PATH: components/provisioning-api/ssm/

PATH: components/shared/rds/groups/postgres13/

PATH: components/shared/rds/groups/postgres15/
|---aws_db_parameter_group
|	|---main(~)

PATH: components/shared/rds/instance/

PATH: components/shared/redis/cluster/

Desired output:

TERRAFORM SUMMARY
------------------------
PATH: components/worker/kinesis-to-s3/
|---aws_kinesis_firehose_delivery_stream
|	|---extended_s3_stream(~)

PATH: components/shared/rds/groups/postgres15/
|---aws_db_parameter_group
|	|---main(~)

Thank you very much for your assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants