-
Notifications
You must be signed in to change notification settings - Fork 4
/
step-assume-role-arn.yml
59 lines (58 loc) · 2.73 KB
/
step-assume-role-arn.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
# Version 1.2
# Maintainer: Dariusz Dwornikowski
# Parameters:
# version sets the downloaded version of assume role arn
# role is required; default: uses $(DEPLOYMENT_ROLE) variable
# external_id is optional; default: uses $(DEPLOYMENT_EXTERNAL_ID) variable
# src_aws_access_key_id is required; default: uses $(SRC-AWS-ACCESS-KEY-ID) variable
# src_aws_secret_access_key is required; default: uses $(SRC-AWS-SECRET-ACCESS-KEY) variable
parameters:
version: 0.3.4
role: $(DEPLOYMENT_ROLE)
external_id: $(DEPLOYMENT_EXTERNAL_ID)
src_aws_access_key_id: $(SRC-AWS-ACCESS-KEY-ID)
src_aws_secret_access_key: $(SRC-AWS-SECRET-ACCESS-KEY)
steps:
- bash: |
if [ -z "$ROLE" ]; then
echo "##vso[task.logissue type=error;]Missing role parameter"
echo "##vso[task.complete result=Failed;]"
fi
if [ -z "$SRC_AWS_ACCESS_KEY_ID" ]; then
echo "##vso[task.logissue type=error;]Missing src_aws_access_key_id parameter"
echo "##vso[task.complete result=Failed;]"
fi
if [ -z "$SRC_AWS_SECRET_ACCESS_KEY" ]; then
echo "##vso[task.logissue type=error;]Missing src_aws_secret_access_key parameter"
echo "##vso[task.complete result=Failed;]"
fi
env:
ROLE: ${{ parameters.role }}
SRC_AWS_ACCESS_KEY_ID: ${{ parameters.src_aws_access_key_id }}
SRC_AWS_SECRET_ACCESS_KEY: ${{ parameters.src_aws_secret_access_key }}
displayName: Check parameters
- script: |
wget https://github.com/nordcloud/assume-role-arn/releases/download/v${{ parameters.version }}/assume-role-arn-linux -O ./assume-role-arn
chmod +x ./assume-role-arn
displayName: Download assume-role-arn v${{ parameters.version }}
- script: |
set -e
if [ -n "$EXTERNAL_ID" ]; then
eval $(AWS_ACCESS_KEY_ID=$SRC_AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$SRC_AWS_SECRET_ACCESS_KEY ./assume-role-arn -r ${{ parameters.role }} -e ${{ parameters.external_id }})
else
eval $(AWS_ACCESS_KEY_ID=$SRC_AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$SRC_AWS_SECRET_ACCESS_KEY ./assume-role-arn -r ${{ parameters.role }})
fi
if [ -n "$AWS_ACCESS_KEY_ID" ]; then
echo "Setting variables"
echo "##vso[task.setvariable variable=AWS_ACCESS_KEY_ID;issecret=true]$AWS_ACCESS_KEY_ID"
echo "##vso[task.setvariable variable=AWS_SECRET_ACCESS_KEY;issecret=true]$AWS_SECRET_ACCESS_KEY"
echo "##vso[task.setvariable variable=AWS_SESSION_TOKEN;issecret=true]$AWS_SESSION_TOKEN"
else
echo "##vso[task.logissue type=error;]AWS_ACCESS_KEY_ID not set"
echo "##vso[task.complete result=Failed;]"
fi
displayName: Assume role
env:
SRC_AWS_ACCESS_KEY_ID: ${{ parameters.src_aws_access_key_id }}
SRC_AWS_SECRET_ACCESS_KEY: ${{ parameters.src_aws_secret_access_key }}
EXTERNAL_ID: ${{ parameters.external_id }}