forked from alphagov/govuk-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins.sh
executable file
·62 lines (46 loc) · 1.82 KB
/
jenkins.sh
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
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
#
# This script invokes the build-terraform-project.sh tool to deploy the code.
#
set -e
if [[ ! $(command -v sops) ]]; then
echo "sops not installed, exiting"
exit 1
fi
# Set the Terraform version to enable testing new versions.
if [[ $TERRAFORM_VERSION != '' ]]; then
BIN='tmp-bin'
echo "Creating temporary bin directory"
rm -rf $BIN && mkdir $BIN && cd $BIN
echo "Downloading Terraform ${TERRAFORM_VERSION}"
wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS
SHASUM256=$(shasum -a 256 terraform_${TERRAFORM_VERSION}_linux_amd64.zip |cut -d ' ' -f1)
echo "Checking integrity of file"
grep -q $SHASUM256 terraform_${TERRAFORM_VERSION}_SHA256SUMS || (echo "SHASUM256 does not match, exiting"; exit 1)
echo "Checked, unpacking"
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip
cd ..
echo "Setting path:"
PATH=$(pwd)/$BIN:$PATH
echo $PATH
echo "Terraform binary: $(command -v terraform)"
fi
rm -rf govuk-aws-data
if [[ "$GOVUK_AWS_DATA_BRANCH" == "" ]]; then
GOVUK_AWS_DATA_BRANCH="main"
fi
echo "Cloning govuk-aws-data"
git clone --single-branch --branch "$GOVUK_AWS_DATA_BRANCH" [email protected]:alphagov/govuk-aws-data.git
case $COMMAND in
'apply') EXTRA='-auto-approve';;
'plan (destroy)') COMMAND='plan'; EXTRA='-detailed-exitcode -destroy';;
'destroy') EXTRA='-force';;
'plan') EXTRA='-detailed-exitcode';;
esac
tools/build-terraform-project.sh -d './govuk-aws-data/data' \
-c $COMMAND \
-p $PROJECT \
-s $STACKNAME \
-e $ENVIRONMENT \
-- $EXTRA