-
Notifications
You must be signed in to change notification settings - Fork 18
/
.gitlab-ci.yml
70 lines (61 loc) · 1.38 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
65
66
67
68
69
70
image:
name: dmitrijsf/ci-docker:latest
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
variables:
PACKER_DIR: packer
TF_DIR: terraform
PLAN: plan.tfplan
S3_BUCKET: terraform-remote-state-defo
cache:
paths:
- .terraform
before_script:
- packer --version
- terraform --version
- cd $TF_DIR && terraform init -input=false
stages:
- validate
- build
- plan
- deploy
packer validate:
stage: validate
script:
- cd ../$PACKER_DIR && find . -maxdepth 1 -name '*.json' -print0 | xargs -t0n1 packer validate
terraform validate:
stage: validate
script:
- cd ../$TF_DIR && terraform validate -var-file=aws-demo.tfvars
build-ami:
stage: build
environment:
name: production
script:
- cd ../$PACKER_DIR && find . -maxdepth 1 -name '*.json' -print0 | xargs -t0n1 packer build
when: manual
only:
- master
plan:
stage: plan
script:
- cd ../$TF_DIR && terraform plan -var-file=aws-demo.tfvars -out=$PLAN
- cd ../$TF_DIR && aws s3 cp $PLAN s3://$S3_BUCKET/$PLAN
artifacts:
name: plan
paths:
- $PLAN
deploy:
stage: deploy
environment:
name: production
script:
- cd ../$TF_DIR && aws s3 cp s3://$S3_BUCKET/$PLAN $PLAN
- cd ../$TF_DIR && terraform apply -input=false $PLAN
dependencies:
- plan
- build-ami
when: manual
only:
- master