terraform-landscape
terraform-landscape copied to clipboard
Support landscaping of `terraform apply` output
Would be great to use that feature also to parse apply output into nice format
Open to a pull request adding support for this!
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.
Or simply bypass any landscape logic completely when "apply" is detected. It's a fairly common mistake to "plan|landscape" then "apply|landscape".