Last active
October 10, 2018 14:02
-
-
Save Gabelbombe/72b31b7df024a853915d00527c5eeec7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export TF_VAR_aws_profile TF_VAR_aws_vpc TF_VAR_aws_net | |
# An implicit guard target, used by other targets to ensure | |
# that environment variables are set before beginning tasks | |
assert-%: | |
@ if [ "${${*}}" = "" ] ; then \ | |
echo "Environment variable $* not set" ; \ | |
exit 1 ; \ | |
fi | |
vault: | |
## This is the problem section here.... | |
@ read -p "Enter AWS Profile Name: " profile ; \ | |
vpc=$(shell aws --profile "$${profile}" --region us-west-2 ec2 describe-vpcs |jq -r '.[] | first | .VpcId') ; \ | |
net=$(shell aws --profile "$${profile}" --region us-west-2 ec2 describe-subnets --filters "Name=vpc-id,Values=$${vpc}" |jq -r '.[] | first | .SubnetId') ; \ | |
TF_VAR_aws_profile=$$profile TF_VAR_aws_vpc=$$vpc TF_VAR_aws_net=$$net make build && \ | |
TF_VAR_aws_profile=$$profile make keypair && \ | |
TF_VAR_aws_profile=$$profile make plan && \ | |
TF_VAR_aws_profile=$$profile make apply | |
build: require-packer | |
aws-vault exec $(TF_VAR_aws_profile) --assume-role-ttl=60m -- \ | |
"/usr/local/bin/packer" "build" "packer/vault.json" \ | |
"-var" "builder_subnet_id=$(TF_VAR_aws_net)" \ | |
"-var" "builder_vpc_id=$(TF_VAR_aws_vpc)" | |
require-packer: assert-TF_VAR_aws_vpc assert-TF_VAR_aws_net | |
@ echo "[info] VPC: $(TF_VAR_aws_vpc)" ## Not set | |
@ echo "[info] NET: $(TF_VAR_aws_net)" ## Not set | |
packer --version &> /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment