-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathdeploy-bluegreen.yml
49 lines (41 loc) · 1.35 KB
/
deploy-bluegreen.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
---
platform: linux
image_resource:
type: docker-image
source:
repository: "python"
tag: "2.7.13-alpine"
params:
TF_PROJECT_FOLDER:
TF_VERSION: "0.12.0"
AWS_DEFAULT_REGION: eu-west-1
TF_ENVIRONMENT:
ASSUME_ROLE_ARN:
inputs:
- name: terraform-repo
- name: terraform-bluegreen
- name: ami
run:
path: sh
args:
- -exc
- |
# Install dependencies
apk add --update unzip curl jq git
# Install terraform
curl -s -o "terraform.zip" "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip"
unzip terraform.zip
export PATH=$PATH:$PWD
# Install dependencies of the deployment script
pip install -r terraform-bluegreen/requirements.txt
# Install awscli
pip install awscli
# Extract AMI id from packer manifest
AMI_ID=$(cat ami/packer_manifest.json | jq -r ".last_run_uuid as \$last_run_uuid | .builds | map(select(.packer_run_uuid == \$last_run_uuid))[0].artifact_id" | cut -d: -f2)
WORKDIR=$PWD
cd terraform-repo/$TF_PROJECT_FOLDER
# Init terraform
terraform init
terraform workspace select $TF_ENVIRONMENT
# Deploy
$WORKDIR/terraform-bluegreen/bluegreen.py -f $WORKDIR/terraform-repo/$TF_PROJECT_FOLDER -a $AMI_ID -c "apply -auto-approve" -t 500 -e $WORKDIR/terraform-repo/$TF_PROJECT_FOLDER/$TF_ENVIRONMENT.tfvars -r $ASSUME_ROLE_ARN