Skip to content

Instantly share code, notes, and snippets.

@k-kinzal
Last active May 15, 2016 14:38
Show Gist options
  • Save k-kinzal/b77c47fdcbfeba7b6f93ec980b226b04 to your computer and use it in GitHub Desktop.
Save k-kinzal/b77c47fdcbfeba7b6f93ec980b226b04 to your computer and use it in GitHub Desktop.
Terraform
.PHONY: apply plan destroy clean
UNAME_S := $(shell uname -s)
TMP_DIR := $(shell mktemp -d -t '')
profile ?= default
target ?= imiew-com kinzal-net logn-in other
apply:
find base ${target} -name '*.tf' | xargs -J% cp -n % ${TMP_DIR}
cp -n *.tf *.tfstate ${TMP_DIR}
terraform apply -var "profile=${profile}" ${TMP_DIR}
plan:
find base ${target} -name '*.tf' | xargs -J% cp -n % ${TMP_DIR}
cp -n *.tf *.tfstate ${TMP_DIR}
terraform plan -var "profile=${profile}" ${TMP_DIR}
destroy:
find base ${target} -name '*.tf' | xargs -J% cp -n % ${TMP_DIR}
cp -n *.tf *.tfstate ${TMP_DIR}
terraform destroy -var "profile=${profile}" -var 'destroy_protection=false' ${TMP_DIR}
clean:
rm -f terraform.tfstate
rm -f terraform.tfstate.backup
rm -fR .terraform/
provider "aws" {
region = "${var.region}"
profile = "${var.profile}"
}
variable "profile" {
default = "default"
}
variable "region" {
default = "ap-northeast-1"
}
variable "prefix" {
default = ""
}
variable "suffix" {
default = ""
}
variable "shell" {
default = false
}
variable "destroy_protection" {
default = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment