Skip to content

Instantly share code, notes, and snippets.

@clairvy
Last active November 5, 2015 03:04
Show Gist options
  • Save clairvy/0d6a00e9901eb6f25007 to your computer and use it in GitHub Desktop.
Save clairvy/0d6a00e9901eb6f25007 to your computer and use it in GitHub Desktop.
/local.env
/tf/*.tf
/tf/*.tfstate*

use terraforming and terraform

Prepare

if you use assume role, you can do,

$ head -1 local.env.sample > local.env
$ vi local.env
$ ( cd .. && git clone https://github.com/clairvy/assume_role.git )   # you can modify your .aws setting
$ ( cd ../assume_role && docker-compose run --rm app ruby -I lib bin/assume_role ) >> local.env

Run

$ mkdir tf
$ docker-compose run --rm app sh -x /mnt/terraforming.sh /mnt/tf
$ docker-compose run --rm tf plan
app:
image: quay.io/dtan4/terraforming:latest
volumes:
- .:/mnt
env_file:
- ./local.env
tf:
image: uzyexe/terraform
volumes:
- ./tf:/data
env_file:
- ./local.env
AWS_REGION=<your region ex. ap-northeast-1>
AWS_ACCESS_KEY_ID=<your access key>
AWS_SECRET_ACCESS_KEY=<your secret key>
AWS_SESSION_TOKEN=<your session token>
#!/bin/sh
outdir=$1
if [ x"$outdir" = x"" ]; then
outdir='tf'
fi
tfing='terraforming'
target='()$'
tfstate="$outdir/terraform.tfstate"
ignore='(help|dbpg)$'
if [ ! -f $tfstate ]; then
# terraform init
cat <<EOL > $tfstate
{
"version": 1,
"serial": 0,
"modules": [
{
"path": [
"root"
],
"outputs": {},
"resources": {}
}
]
}
EOL
fi
$tfing | awk '/terraforming /{print $2}' | egrep -v "$ignore" | egrep $target | xargs -I {} sh -c "$tfing {} > $outdir/{}.tf 2> $outdir/{}.tferr"
$tfing | awk '/terraforming /{print $2}' | egrep -v "$ignore" | egrep $target | xargs -I {} sh -c "$tfing {} --tfstate --merge $tfstate --overwrite 2> $outdir/{}.tfserr"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment