Skip to content

Instantly share code, notes, and snippets.

@theherk
Created November 25, 2021 13:51
Show Gist options
  • Save theherk/fd28a9f2b7270b556dde25bb67b89e09 to your computer and use it in GitHub Desktop.
Save theherk/fd28a9f2b7270b556dde25bb67b89e09 to your computer and use it in GitHub Desktop.
Install the latest version of terraform locally with GNU Make.
OS := linux
ifeq (${shell uname},Darwin)
OS := darwin
endif
ARCH := amd64
help: ## show help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z./_-]+:.*?##/ { printf " \033[36m%-16s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
bin:
mkdir -p $@
bin/terraform: LATEST := ${shell curl --silent "https://api.github.com/repos/hashicorp/terraform/releases/latest" | jq ".. .tag_name? // empty" | tr -d '"v'}
bin/terraform: URL := https://releases.hashicorp.com/terraform/${LATEST}/terraform_${LATEST}_${OS}_${ARCH}.zip
bin/terraform: bin ## install terraform
curl -L ${URL} --output $@.zip
unzip -o $@.zip -d ${@D}
rm -f $@.zip
@echo 'export PATH=${@D}:$$PATH # remember to add to your PATH'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment