-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
64 lines (60 loc) · 2.02 KB
/
.gitlab-ci.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
stages:
- validate
- plan
- deploy
before_script:
- git submodule update --init --recursive
- docker info
- terraform -version
validate:
image: registry.gitlab.com/jarv/cmdchallenge/ci-image
stage: validate
# Validate every directory that contains terraform config
# (`terraform validate` does not do a full recurse)
script: |
#!/bin/bash
set -x
tf_opts="-check-variables=false"
cd terraform
/usr/local/bin/terraform init -backend=false
dirs_to_check=$(find . -name "*.tf" -type f -exec dirname {} \; | sort | uniq)
/bin/sh -e -c 'for d in $0; do echo "Checking $d " && /usr/local/bin/terraform validate $1 "$d"; done' "$dirs_to_check" "$tf_opts"
plan:
image: registry.gitlab.com/jarv/cmdchallenge/ci-image
stage: plan
script: |
#!/bin/bash
set -x
./bin/create-ssh-keys
mkdir -p private/google
echo $GCP_KEY | base64 -d > private/google/cmdchallenge.json
cd terraform
echo $(pwd)
/usr/local/bin/terraform init
/usr/local/bin/terraform workspace list
/usr/local/bin/terraform workspace select prod
/usr/local/bin/terraform plan -input=false
deploy:
image: registry.gitlab.com/jarv/cmdchallenge/ci-image
stage: deploy
script: |
#!/bin/bash
set -x
./bin/create-ssh-keys
mkdir -p private/google
mkdir -p private/ssh
mkdir -p private/ca
mkdir -p private/client
echo $GCP_KEY | base64 -d > private/google/cmdchallenge.json
echo $CMD_RSA | base64 -d > private/ssh/cmd_rsa
echo $CA_PEM | base64 -d > private/ca/ca.pem
echo $CA_KEY_PEM | base64 -d > private/ca/ca-key.pem
echo $CLIENT_CERT_PEM | base64 -d > private/client/cert.pem
echo $CLIENT_KEY_PEM | base64 -d > private/client/key.pem
cd terraform
echo $(pwd)
/usr/local/bin/terraform init
/usr/local/bin/terraform workspace list
/usr/local/bin/terraform workspace select prod
/usr/local/bin/terraform taint null_resource.pre_archive
/usr/local/bin/terraform apply -auto-approve -input=false -var=timestamp=$(date '+%Y%m%d%s')