coinbase / terraform-landscape

Improve Terraform's plan output to be easier to read and understand
Apache License 2.0
1.59k stars 114 forks source link

Suppress some output of 'terraform init' #93

Closed tdmalone closed 4 years ago

tdmalone commented 5 years ago

Hey guys, love what you've done with this - especially with the much simpler terraform plan output when there's no changes:

$ terraform plan | landscape
No changes.

:tada:

I was wondering whether it might be possible to expand landscape to handle additional terraform commands, such as init?

$ terraform init | landscape
Terraform Landscape: a parsing error occured. Falling back to original Terraform output...
Initializing modules...
- module.test_image_0_0_1
- module.test_image_0_0_2
- module.test1_eks
- module.test2_eks
- module.ingress_controller_policy
- module.worker_nodes_instance_role

Initializing the backend...

Initializing provider plugins...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Setting TF_IN_AUTOMATION=true cuts out the last two paragraphs (that's a built-in Terraform feature), but it would be cool if Landscape could perhaps cut this out by default, as well as cut out the list of modules (which are often much longer than the list I have included above)?

Related at the official Terraform repo: https://github.com/hashicorp/terraform/issues/18467)

sds commented 5 years ago

Thanks for the suggestion, @tdmalone.

Not opposed to your suggestion, though adding support for other commands will make the parser potentially more difficult to maintain.

As long as we add test, happy to accept a pull request!

tdmalone commented 5 years ago

FYI, my current workaround for this in CI (to avoid all the module output) is:

terraform init .... | grep --invert --extended-regexp '^(\- module\.|\s+Getting source\s)'"
sds commented 4 years ago

Closing this as this is a nice-to-have and has a workaround via grep. Would welcome a pull request with tests if someone is interested. Thanks!