terraform-landscape icon indicating copy to clipboard operation
terraform-landscape copied to clipboard

Support landscaping of `terraform apply` output

Open mkjmdski opened this issue 6 years ago • 3 comments

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

mkjmdski avatar May 13 '19 14:05 mkjmdski

Open to a pull request adding support for this!

sds avatar May 15 '19 03:05 sds

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.

pgroudas avatar May 30 '19 01:05 pgroudas

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

Quentin-M avatar Aug 19 '19 23:08 Quentin-M