-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
78 lines (72 loc) · 1.73 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
variables:
ENV:
value: dev
options:
- dev
- prod
description: Environment level
REGION:
value: eu-central-1
options:
- eu-central-1
- eu-north-1
description: AWS region
stages:
- mvn-package
- terraform-plan
- terraform-apply
- terraform-destroy
mvn-package:
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/maven:3.9.5-amazoncorretto-17
stage: mvn-package
cache:
key: ${REGION}-${ENV}-mvn
paths:
- java/.m2/repository
variables:
MAVEN_OPTS: -Dmaven.repo.local=.m2/repository
script:
- cd java
- mvn package
artifacts:
paths:
- java/target/java-function-1.0.jar
.terraform-template:
image:
name: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/hashicorp/terraform:1.6.3
entrypoint:
- ""
before_script:
- cd terraform
- terraform init -backend-config=backends/${REGION}/${ENV}.s3.tfbackend
cache:
key: ${REGION}-${ENV}-terraform
paths:
- terraform/.terraform
terraform-plan:
extends: .terraform-template
stage: terraform-plan
script:
- terraform plan -var-file=variables/${REGION}/${ENV}.tfvars
terraform-apply:
extends: .terraform-template
stage: terraform-apply
environment:
name: ${REGION}-${ENV}
action: start
script:
- terraform apply -var-file=variables/${REGION}/${ENV}.tfvars -auto-approve
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
terraform-destroy:
extends: .terraform-template
stage: terraform-destroy
environment:
name: ${REGION}-${ENV}
action: stop
script:
- terraform destroy -var-file=variables/${REGION}/${ENV}.tfvars -auto-approve
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual