-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
114 lines (98 loc) · 3.7 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
######### >> Gitlab-CI for Terraform ------------------------------------------
# This file aims to configure Gitlab-Ci to work with terraform for GCP Resources
## Environment Variables:
# GOOGLE_APPLICATION_CREDENTIALS - Path to the JSON file with the credentials to be used by the google provider in terraform.
# SERVICEACCOUNT - Content of the JSON file with the credentials to be used by the gcloud CLI. Necessary to configure in the repository
# GITLAB_TOKEN - Access Token for Gitlab. Necessary to configure in the repository
---
######### >> Global Settings ------------------------------------------
image:
name: hashicorp/terraform:0.15.3 # https://hub.docker.com/r/hashicorp/terraform/tags
entrypoint:
- "/usr/bin/env"
- "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
variables:
GOOGLE_APPLICATION_CREDENTIALS: "creds/serviceaccount.json"
before_script:
- mkdir -p creds && echo $SERVICEACCOUNT | base64 -d > ./creds/serviceaccount.json
stages:
- init_validate
- plan
- publish
- deploy
######### >> Terraform Init & Validate ------------------------------------------
# This job initializes the backend and validates the code syntax.
# Docs: https://www.terraform.io/docs/commands/validate.html
init_validate:
stage: init_validate
script:
- terraform --version
- terraform init
- terraform validate
except:
- tags
cache:
paths:
- .terraform
- files
key: “$CI_BUILD_REPO”
# ######### >> Terraform Plan ------------------------------------------
# # The terraform plan command is used to create an execution plan. Terraform performs a refresh, unless explicitly disabled,
# # and then determines what actions are necessary to achieve the desired state specified in the configuration files.
# # Docs: https://www.terraform.io/docs/commands/plan.html
# plan:
# stage: plan
# dependencies:
# - init_validate
# script:
# - terraform --version
# - terraform plan -input=false -var-file=files/terraform_tfvars.tfvars
# only:
# - master
# except:
# - tags
# cache:
# paths:
# - .terraform
# - files
# key: “$CI_BUILD_REPO”
# ######### >> Terraform Apply ------------------------------------------
# # The terraform apply command is used to apply the changes required to reach the desired state of the configuration,
# # or the pre-determined set of actions generated by a terraform Apply execution Apply.
# # Docs: https://www.terraform.io/docs/commands/apply.html
# apply:
# stage: deploy
# dependencies:
# - plan
# script:
# - terraform --version
# - terraform apply -auto-approve -input=false -var-file=files/terraform_tfvars.tfvars
# when: manual
# only:
# - master
# except:
# - tags
# cache:
# paths:
# - .terraform
# - files
# key: “$CI_BUILD_REPO”
######### >> Tag & Release ------------------------------------------
# The semantic-release uses the commit messages to determine the type of changes in the codebase.
# Following formalized conventions for commit messages, semantic-release automatically determines
# the next semantic version number, generates a changelog and publishes the release.
# By default semantic-release uses Angular Commit Message Conventions.
# Source: https://github.com/semantic-release/semantic-release
# Docs: https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines
tag_release:
stage: publish
image: brunosb/semantic-delivery-gitlab:latest
dependencies:
- init_validate
before_script:
- git fetch --tags -f
script:
- semantic-delivery-gitlab --token $GITLAB_TOKEN
only:
- master
# TODO: Criar Job para a exclusão da infra - visando ambientes de testes dinâmicos