Skip to content

Commit

Permalink
Merge pull request #2 from paulRbr/fixes
Browse files Browse the repository at this point in the history
Getting ready for 0.1.0
  • Loading branch information
paulRbr authored Sep 9, 2017
2 parents 544eef7 + 8ed131b commit 3b3f88f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 22 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Paul B.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# This MAKEFILE is maintained open-source on Github.com
# If you make any modification to this file please open a Pull Request
# with your changes on https://github.com/paulRbr/terraform-makefile
# ------------------
# TERRAFORM-MAKEFILE
# v0.1.0
# ------------------
#
# Thanks!
# - Paul(rbr)
# This Makefile is maintained on Github.com.
# Please contribute upstream any changes by opening pull requests:
# https://github.com/paulRbr/terraform-makefile/pull/new/master
# Thanks! - Paul(rbr)

##
# TERRAFORM INSTALL
Expand Down Expand Up @@ -56,27 +59,27 @@ endif

.PHONY: lint
lint: ## make lint # Rewrites config to canonical format
@terraform fmt $(opts)
@terraform fmt -diff=true $(opts)

.PHONY: validate
validate: ## make validate # Basic syntax check
@wd=$(wd) ./terraform.sh validate $(opts)

.PHONY: list
list: ## make list # List infra resources
@wd=$(wd) terraform.sh show $(opts)
@wd=$(wd) ./terraform.sh show $(opts)

.PHONY: dry-run
dry-run: ## make dry-run # Dry run resources changes
@wd=$(wd) terraform.sh plan $(opts)
@wd=$(wd) ./terraform.sh plan $(opts)

.PHONY: run
run: ## make run # Execute resources changes
@wd=$(wd) terraform.sh apply $(opts)
@wd=$(wd) ./terraform.sh apply $(opts)

.PHONY: destroy
destroy: ## make destroy # Destroy resources
@wd=$(wd) terraform.sh destroy $(opts)
@wd=$(wd) ./terraform.sh destroy $(opts)

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down
49 changes: 37 additions & 12 deletions terraform.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
# This MAKEFILE is maintained open-source on Github.com
# If you make any modification to this file please open a Pull Request
# with your changes on https://github.com/paulRbr/terraform-makefile
# ------------------
# TERRAFORM-MAKEFILE
# v0.1.0
# ------------------
#
# Thanks!
# - Paul(rbr)
# This Makefile is maintained on Github.com.
# Please contribute upstream any changes by opening pull requests:
# https://github.com/paulRbr/terraform-makefile/pull/new/master
# Thanks! - Paul(rbr)
#
#!/bin/bash -e

key="$(echo "${provider}" | tr '[:lower:]' '[:upper:]')_$(echo "${env}" | tr '[:lower:]' '[:upper:]')_KEY"
secret="$(echo "${provider}" | tr '[:lower:]' '[:upper:]')_$(echo "${env}" | tr '[:lower:]' '[:upper:]')_SECRET"

if (which pass >/dev/null 2>&1); then
provider_key="$(pass ${provider}/access_key)"
provider_token="$(pass ${provider}/token)"
declare "TF_VAR_${provider}_access_key"=$provider_key
declare "TF_VAR_${provider}_token"=$provider_token
pass_key="$(pass "terraform/${provider}/${env}/access_key")"
pass_secret="$(pass "terraform/${provider}/${env}/secret")"

declare "${key}"="${pass_key}"
declare "${secret}"="${pass_secret}"
fi

export TF_VAR_${provider}_access_key
export TF_VAR_${provider}_token
case $provider in
aws)
declare "AWS_ACCESS_KEY_ID=${!key}"
declare "AWS_SECRET_ACCESS_KEY=${!secret}"
;;
azurerm)
declare "ARM_CLIENT_ID=${!key}"
declare "ARM_CLIENT_SECRET=${!secret}"
:;;
"do")
declare "DIGITALOCEAN_TOKEN=${!secret}"
:;;
google)
declare "GOOGLE_CREDENTIALS=${!secret}"
:;;
scaleway)
declare "SCALEWAY_ORGANIZATION=${!key}"
declare "SCALEWAY_TOKEN=${!secret}"
:;;
esac

cd ${wd} && terraform $@
cd "${wd}" && terraform $@

0 comments on commit 3b3f88f

Please sign in to comment.