-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
43 lines (40 loc) · 1.71 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
default:
image:
name: hashicorp/terraform:0.12.26
entrypoint: [""]
tags:
- schism-testing
variables:
section_mark: "${CI_PROJECT_DIR}/.ci/section_mark"
stages:
- test
testing:
stage: test
before_script:
- ${section_mark} start package_installation "Package Installaion"
- apk add -U pwgen python3 jq
- pip3 install awscli boto3
- ${section_mark} end package_installation
- ${section_mark} start terraform_setup "Terraform Setup"
- aws configure set region us-west-2
- export TF_VAR_prefix="${CI_COMMIT_REF_SLUG}-$(pwgen -AB 8 1)"
- cd .ci
- terraform init
- terraform plan -out tf.plan
- ${section_mark} end terraform_setup
script:
- ${section_mark} start terraform_apply "Terraform Apply"
- terraform apply tf.plan
- ${section_mark} end terraform_apply
- ${section_mark} start lambda_testing "Testing Lambda Invocation"
- aws lambda invoke --function "${TF_VAR_prefix}-controller" --log-type Tail --payload '{}' result.json
- jq . result.json
- aws ssm describe-parameters --parameter-filters "Key=Name,Option=Contains,Values='${TF_VAR_prefix}-'"
- ${section_mark} end lambda_testing
- ${section_mark} start teardown "Tearing Down Test Resources"
- to_delete=$(aws ssm describe-parameters --parameter-filters "Key=Name,Option=Contains,Values='${TF_VAR_prefix}-'" --query "Parameters[*].Name" --output text)
- aws ssm delete-parameters --names ${to_delete}
- aws logs describe-log-groups --log-group-name-prefix "/aws/lambda/${TF_VAR_prefix}" | jq '.logGroups[].logGroupName' -r | xargs -I % aws logs delete-log-group --log-group-name %
- python3 cleanup.py
- terraform destroy -force
- ${section_mark} end teardown