-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
.gitlab-ci.yml
53 lines (48 loc) · 1.28 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
image:
name: amazon/aws-cli:latest
entrypoint:
- "/usr/bin/env"
variables:
TF_LOG_PATH: ./terraform.log
TF_DATA_DIR: ./.terraform
ROLE_ARN: "arn:aws:iam::$SECRET_AWS_ACCOUNT_ID:role/gitlab-runner"
AWS_REGION: "$SECRET_AWS_REGION"
stages:
- validate
- aws-test
.assume-role:
id_tokens:
AWS_ID_TOKEN:
aud: https://oidc.provider.com
before_script:
- >
STS=($(aws sts assume-role-with-web-identity
--role-arn $ROLE_ARN
--region $AWS_REGION
--role-session-name "GitLabRunner-${CI_PROJECT_ID}-${CI_PIPELINE_ID}"
--web-identity-token $AWS_ID_TOKEN
--duration-seconds 3600
--query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]'
--output text))
- export AWS_ACCESS_KEY_ID="${STS[0]}"
- export AWS_SECRET_ACCESS_KEY="${STS[1]}"
- export AWS_SESSION_TOKEN="${STS[2]}"
validate:
stage: validate
needs: []
image:
name: hashicorp/terraform:latest
entrypoint:
- "/usr/bin/env"
- "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
interruptible: true
script:
- terraform init -backend=false
- terraform fmt -check -recursive
- terraform validate
aws:
stage: aws-test
needs: [validate]
extends: .assume-role
script:
- aws sts get-caller-identity