coinbase / terraform-landscape

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

Support landscaping of `terraform apply` output #98

Open mkjmdski opened 5 years ago

mkjmdski commented 5 years ago

Would be great to use that feature also to parse apply output into nice format

sds commented 5 years ago

Open to a pull request adding support for this!

pgroudas commented 5 years ago

For what its worth, I wrap my terraform executions in a Makefile that does something like this:

# part of Makefile
now := $(shell date +"%s")
apply: 
    -@terraform plan -detailed-exitcode -input=false -out=.terraform/$(now).tfplan >.terraform/$(now).tfvisualization ; \
        ( case $$? in \
            0) \
                echo "No changes to apply" ;; \
            1) \
                cat .terraform/$(now).tfvisualization && \
                false ;; \
            2) \
                landscape <.terraform/$(now).tfvisualization && \
                read -r -p "Apply plan? (y/N): " CONFIRMATION && \
                if [ "$$CONFIRMATION" = "y" ]; then \
                    terraform apply -auto-approve .terraform/$(now).tfplan; \
                else \
                    echo "Not applying."; \
                fi \
            esac \
        )

    @rm -f .terraform/$(now).tfplan .terraform/$(now).tfvisualization

What this is doing is writing the plan to a file, then reading that with landscape before prompting the user to execute the plan or not and feeding the plan back into terraform apply.

This has the shortcoming in that it doesn't support running terraform apply with other arguments.

Quentin-M commented 5 years ago

Or simply bypass any landscape logic completely when "apply" is detected. It's a fairly common mistake to "plan|landscape" then "apply|landscape".