-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.gitlab-ci.yml
130 lines (114 loc) · 2.85 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#----------------------------------------------
# Start Pipeline GilabCI
#----------------------------------------------
image:
name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
variables:
TF_ROOT: ${CI_PROJECT_DIR}/infraestrutura
TF_SCRIPTS: ${CI_PROJECT_DIR}/scripts
TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}-${CI_COMMIT_BRANCH}
TF_STAGE: ""
cache:
key: ${CI_PROJECT_NAME}-${CI_COMMIT_BRANCH}
paths:
- ${TF_ROOT}/.terraform
before_script:
- export TF_VAR_private_key=${private_key}
- export TF_VAR_ssh_public_key=${ssh_public_key}
- export TF_VAR_fingerprint=${fingerprint}
- export TF_VAR_user_ocid=${user_ocid}
- export TF_VAR_compartment_ocid=${compartment_ocid}
- export TF_VAR_tenancy_ocid=${tenancy_ocid}
- export TF_VAR_region=${region}
- cd ${TF_ROOT}
- terraform --version
stages:
- prepare
- validate
- build
- deploy
- notificacao
- cleanup
#----------------------------------------------
# terraform init
#----------------------------------------------
init:
stage: prepare
script:
- gitlab-terraform init
#----------------------------------------------
# terraform validate
#----------------------------------------------
validate:
stage: validate
needs: [init]
script:
- gitlab-terraform validate
- gitlab-terraform fmt -check=true
dependencies:
- init
#----------------------------------------------
# terraform plan
#----------------------------------------------
plan:
stage: build
needs: [validate]
script:
- gitlab-terraform plan
- gitlab-terraform plan-json
dependencies:
- validate
artifacts:
name: plan
paths:
- ${TF_ROOT}/plan.cache
reports:
terraform: ${TF_ROOT}/plan.json
#----------------------------------------------
# terraform apply
#----------------------------------------------
apply:
stage: deploy
needs: [plan]
script:
- gitlab-terraform apply
dependencies:
- plan
when: manual
only:
variables:
- $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
#----------------------------------------------
# Notificações Stages Sucesso ou Falha
#----------------------------------------------
notificacao-sucesso:
stage: notificacao
needs: [plan]
when: on_success
script:
- cd ${TF_SCRIPTS}
- sh notificacaoStageSucesso.sh
dependencies:
- plan
notificacao-falha:
stage: notificacao
when: on_failure
script:
- cd ${TF_SCRIPTS}
- sh notificacaoStageFalha.sh
#----------------------------------------------
# terraform destroy
#----------------------------------------------
destroy:
stage: cleanup
needs: [apply]
script:
- gitlab-terraform destroy
- cd ${TF_SCRIPTS}
- sh notificacaoDestroySucesso.sh
dependencies:
- apply
when: manual
only:
variables:
- $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH