coinbase / terraform-landscape

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

Error on 'No changes' in TF 0.10.6 #37

Closed s-maj closed 7 years ago

s-maj commented 7 years ago

Hi there,

If there is no changes to apply landscape fails.

Terraform (v0.10.6):


------------------------------------------------------------------------

No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.

Landscape (0.1.13):

error: Expected [ ] at line 2, column 2 (byte 3) after
-. Use --trace to view backtrace

Trace:

/usr/local/lib/ruby/gems/2.4.0/gems/terraform_landscape-0.1.13/lib/terraform_landscape/terraform_plan.rb:36:in `from_output': Expected [ ] at line 2, column 2 (byte 3) after  (TerraformLandscape::TerraformPlan::ParseError)
-
    from /usr/local/lib/ruby/gems/2.4.0/gems/terraform_landscape-0.1.13/lib/terraform_landscape/printer.rb:61:in `process_string'
    from /usr/local/lib/ruby/gems/2.4.0/gems/terraform_landscape-0.1.13/lib/terraform_landscape/printer.rb:35:in `process_stream'
    from /usr/local/lib/ruby/gems/2.4.0/gems/terraform_landscape-0.1.13/lib/terraform_landscape/cli.rb:48:in `print'
    from /usr/local/lib/ruby/gems/2.4.0/gems/terraform_landscape-0.1.13/lib/terraform_landscape/cli.rb:34:in `block (2 levels) in define_commands'
    from /usr/local/lib/ruby/gems/2.4.0/gems/commander-4.4.3/lib/commander/command.rb:178:in `call'
    from /usr/local/lib/ruby/gems/2.4.0/gems/commander-4.4.3/lib/commander/command.rb:153:in `run'
    from /usr/local/lib/ruby/gems/2.4.0/gems/commander-4.4.3/lib/commander/runner.rb:446:in `run_active_command'
    from /usr/local/lib/ruby/gems/2.4.0/gems/commander-4.4.3/lib/commander/runner.rb:68:in `run!'
    from /usr/local/lib/ruby/gems/2.4.0/gems/commander-4.4.3/lib/commander/delegates.rb:15:in `run!'
    from /usr/local/lib/ruby/gems/2.4.0/gems/terraform_landscape-0.1.13/lib/terraform_landscape/cli.rb:25:in `run'
    from /usr/local/lib/ruby/gems/2.4.0/gems/terraform_landscape-0.1.13/bin/landscape:7:in `<top (required)>'
    from /usr/local/bin/landscape:22:in `load'
    from /usr/local/bin/landscape:22:in `<main>'
sds commented 7 years ago

Hey @s-maj, I can't reproduce this with Terraform 0.10.6.

The example output you give has a number of hyphens at the start (-------... etc). Where are those coming from?

sds commented 7 years ago

It's possible this was fixed in landscape 0.1.14. Can you confirm it's still a problem?

stephencoe commented 7 years ago

I was experiencing a similar issue to this with TF 0.10.7

terraform plan | bundle exec landscape
error: Expected [ ] at line 1, column 2 (byte 2) after -. Use --trace to view backtrace
make: *** [plan] Error 1

upgrading from landscape 0.1.6 > 0.1.14 seems to have fixed it for me

s-maj commented 7 years ago

All fine, cheers!

mikeflisher commented 7 years ago

I'm seeing this in Terraform 0.10.5 (at least) 72 dashes and two new lines to the top of the plan output.

https://github.com/hashicorp/terraform/blob/master/backend/local/backend_plan.go#L100 https://github.com/hashicorp/terraform/blob/master/backend/local/backend_plan.go#L152

Also related to environment variable TF_IN_AUTOMATION.

In terraform_landscape printer.rb, the dashes get caught by:

      elsif (match = scrubbed_output.match(/^\s*(~|\+|\-)/))
        scrubbed_output = scrubbed_output[match.begin(0)..-1]

So this never reaches the regexp that checks for "No changes".

My solution is to scrub the output of the 72 dashes and 2 \n's then parse as normal.

Also move the "no change" code above the parsing section so we don't match a parse before no changes.