terraform/examples/azure-vm-simple-linux/deploy.sh

63 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/bash
set -o errexit -o nounset
# generate a unique string for CI deployment
2017-04-20 20:44:23 +02:00
# KEY=$(cat /dev/urandom | tr -cd 'a-z' | head -c 12)
# PASSWORD=$KEY$(cat /dev/urandom | tr -cd 'A-Z' | head -c 2)$(cat /dev/urandom | tr -cd '0-9' | head -c 2)
2017-04-20 20:44:23 +02:00
KEY=$1
PASSWORD=$2
2017-04-20 20:52:15 +02:00
docker run --rm -it -v \
$(pwd):/data -w /data \
hashicorp/terraform:light \
get
2017-04-20 21:02:12 +02:00
docker run
-e ARM_CLIENT_ID="$ARM_CLIENT_ID" \
-e ARM_CLIENT_SECRET="$ARM_CLIENT_SECRET" \
-e ARM_SUBSCRIPTION_ID="$ARM_SUBSCRIPTION_ID" \
-e ARM_TENANT_ID="$ARM_SUBSCRIPTION_ID" \
2017-04-20 20:52:15 +02:00
$(pwd):/data -w /data \
hashicorp/terraform:light \
plan -var dns_name=$KEY -var resource_group=$KEY -var admin_username=$KEY -var admin_password=$PASSWORD -out=out.tfplan
docker run --rm -it -v \
2017-04-20 21:02:12 +02:00
-e ARM_CLIENT_ID="$ARM_CLIENT_ID" \
-e ARM_CLIENT_SECRET="$ARM_CLIENT_SECRET" \
-e ARM_SUBSCRIPTION_ID="$ARM_SUBSCRIPTION_ID" \
-e ARM_TENANT_ID="$ARM_SUBSCRIPTION_ID" \
2017-04-20 20:52:15 +02:00
$(pwd):/data -w /data \
hashicorp/terraform:light \
apply out.tfplan
2017-04-20 20:44:23 +02:00
# terraform get
#
# terraform plan -var 'dns_name='$KEY -var 'admin_password='$PASSWORD -var 'admin_username='$KEY -var 'resource_group='$KEY -out=out.tfplan
#
# terraform apply out.tfplan
# TODO: determine external validation, possibly Azure CLI
# echo "Setting git user name"
# git config user.name $GH_USER_NAME
#
# echo "Setting git user email"
# git config user.email $GH_USER_EMAIL
#
# echo "Adding git upstream remote"
# git remote add upstream "https://$GH_TOKEN@github.com/$GH_REPO.git"
#
# git checkout master
#
# NOW=$(TZ=America/Chicago date)
#
# git commit -m "tfstate: $NOW [ci skip]"
#
# echo "Pushing changes to upstream master"
# git push upstream master