Skip to content

Commit

Permalink
Merge pull request #1 from tinnightcap/master
Browse files Browse the repository at this point in the history
Updates for region detection for app-state-bucket
  • Loading branch information
limed authored Aug 29, 2017
2 parents 4c53422 + d9142cd commit cf0e2b9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions nubis-deploy-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ setup-deploy-dir () {
}

setup-terraform () {
ACCOUNT=$(grep "^account = " "${WORKING_PATH}/nubis/terraform/terraform.tfvars" | sed "s/^account\ =\ \"//g"); ACCOUNT=${ACCOUNT%%\"}
REGION=$(grep "^region = " "${WORKING_PATH}/nubis/terraform/terraform.tfvars" | sed "s/^region\ =\ \"//g"); REGION=${REGION%%\"}
ENVIRONMENT=$(grep "^environment = " "${WORKING_PATH}/nubis/terraform/terraform.tfvars" | sed "s/^environment\ =\ \"//g"); ENVIRONMENT=${ENVIRONMENT%%\"}
ACCOUNT=$(grep "^account = " "${WORKING_PATH}/nubis/terraform/terraform.tfvars" | sed "s/^account\ =\ \"//g")
ACCOUNT=${ACCOUNT%%\"}
ENVIRONMENT=$(grep "^environment = " "${WORKING_PATH}/nubis/terraform/terraform.tfvars" | sed "s/^environment\ =\ \"//g")
ENVIRONMENT=${ENVIRONMENT%%\"}
DEPLOYMENT_REGION=$(grep "^region = " "${WORKING_PATH}/nubis/terraform/terraform.tfvars" | sed "s/^region\ =\ \"//g")
DEPLOYMENT_REGION=${DEPLOYMENT_REGION%%\"}
SERVICE_NAME=$(grep "^service_name = " "${WORKING_PATH}/nubis/terraform/terraform.tfvars" | sed "s/^service_name\ =\ \"//g"); SERVICE_NAME=${SERVICE_NAME%%\"}
STATE_BUCKET=$(curl -s "http://state.nubis.${ACCOUNT}.nubis.allizom.org/aws/${REGION}/${ENVIRONMENT}.tfstate" | \
STATE_BUCKET=$(curl -s "http://state.nubis.${ACCOUNT}.nubis.allizom.org/aws/${DEPLOYMENT_REGION}/${ENVIRONMENT}.tfstate" | \
jq -r ' .modules[] | select(.path == ["root"]) | .outputs.apps_state_bucket')
BUCKET_REGION=$(aws s3api get-bucket-location --bucket "${STATE_BUCKET}" | jq -r '.LocationConstraint')

cd "${WORKING_PATH}" && terraform init \
-input=true \
-upgrade=false \
-backend-config="region=us-east-1" \
-backend-config="region=${BUCKET_REGION}" \
-backend-config="key=terraform/${SERVICE_NAME}" \
-backend-config="bucket=${STATE_BUCKET}" \
"${WORKING_PATH}/nubis/terraform/"
Expand Down

0 comments on commit cf0e2b9

Please sign in to comment.