Skip to content

Instantly share code, notes, and snippets.

@davidlu1001
Last active November 24, 2021 16:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save davidlu1001/e832038299fff99d4a4b2c6a75d71b78 to your computer and use it in GitHub Desktop.
Save davidlu1001/e832038299fff99d4a4b2c6a75d71b78 to your computer and use it in GitHub Desktop.
Makefile for Terraform to support include/exclude
PLAN_OPTIONS ?=
APPLY_OPTIONS ?=
EXCLUDE ?=
INCLUDE ?=
# For Terraform 0.12 (using `-no-color` to avoid dealing with terminal color)
define PLAN_OPTIONS_EXCLUDE
$(shell terraform show -no-color current.plan | perl -nle 'if (/\s# (.*?)\s/) {print $$1}' | grep -E -v '$(1)' | sed -e 's/^/-target="/g' -e 's/$$/"/g' | xargs)
endef
define PLAN_OPTIONS_INCLUDE
$(shell terraform show -no-color current.plan | perl -nle 'if (/\s# (.*?)\s/) {print $$1}' | grep -E '$(1)' | sed -e 's/^/-target="/g' -e 's/$$/"/g' | xargs)
endef
plan_exclude:
terraform plan -out current.plan $(strip $(call PLAN_OPTIONS_EXCLUDE,$(EXCLUDE))
plan_include:
terraform plan -out current.plan $(strip $(call PLAN_OPTIONS_INCLUDE,$(INCLUDE)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment