Skip to content

Commit e4f7919

Browse files
committed
feat(ci): test CF templates when published
1 parent bc966e4 commit e4f7919

File tree

4 files changed

+182
-8
lines changed

4 files changed

+182
-8
lines changed

.github/workflows/npm-publish-all-packages-canary.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
DD_TESTS_APP_KEY: ${{ secrets.DD_TESTS_APP_KEY }}
9494
AWS_TEST_EXECUTION_ROLE_ARN_TEST5: ${{ secrets.AWS_TEST_EXECUTION_ROLE_ARN_TEST5 }}
9595

96-
publish-cloudformation-templates-canary-to-s3:
96+
run-cloudformation-iam-setup-tests:
9797
uses: ./.github/workflows/s3-publish-cf-templates.yml
9898
needs: run-distributed-tests
9999
with:
@@ -103,3 +103,8 @@ jobs:
103103
id-token: write
104104
secrets:
105105
AWS_ASSET_UPLOAD_ROLE_ARN: ${{ secrets.AWS_ASSET_UPLOAD_ROLE_ARN }}
106+
ARTILLERY_CLOUD_ENDPOINT_TEST: ${{ secrets.ARTILLERY_CLOUD_ENDPOINT_TEST }}
107+
ARTILLERY_CLOUD_API_KEY_TEST: ${{ secrets.ARTILLERY_CLOUD_API_KEY_TEST }}
108+
AWS_ACCOUNT_ID_FRESH_SETUP_TESTS: ${{ secrets.AWS_ACCOUNT_ID_FRESH_SETUP_TESTS }}
109+
DD_TESTS_API_KEY: ${{ secrets.DD_TESTS_API_KEY }}
110+
DD_TESTS_APP_KEY: ${{ secrets.DD_TESTS_APP_KEY }}

.github/workflows/npm-publish-all-packages.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ jobs:
109109
publish-cloudformation-templates-to-s3:
110110
uses: ./.github/workflows/s3-publish-cf-templates.yml
111111
needs: run-distributed-tests
112-
with:
113-
canary: true
114112
permissions:
115113
contents: read
116114
id-token: write
117115
secrets:
118116
AWS_ASSET_UPLOAD_ROLE_ARN: ${{ secrets.AWS_ASSET_UPLOAD_ROLE_ARN }}
117+
ARTILLERY_CLOUD_ENDPOINT_TEST: ${{ secrets.ARTILLERY_CLOUD_ENDPOINT_TEST }}
118+
ARTILLERY_CLOUD_API_KEY_TEST: ${{ secrets.ARTILLERY_CLOUD_API_KEY_TEST }}
119+
AWS_ACCOUNT_ID_FRESH_SETUP_TESTS: ${{ secrets.AWS_ACCOUNT_ID_FRESH_SETUP_TESTS }}
120+
DD_TESTS_API_KEY: ${{ secrets.DD_TESTS_API_KEY }}
121+
DD_TESTS_APP_KEY: ${{ secrets.DD_TESTS_APP_KEY }}

.github/workflows/s3-publish-cf-templates.yml

+170-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ on:
1111
AWS_ASSET_UPLOAD_ROLE_ARN:
1212
description: 'ARN of the IAM role to assume to upload assets to S3'
1313
required: true
14+
AWS_ACCOUNT_ID_FRESH_SETUP_TESTS:
15+
description: 'AWS Account ID to use for setting up IAM permissions and running tests'
16+
required: true
17+
ARTILLERY_CLOUD_ENDPOINT_TEST:
18+
description: 'Artillery Cloud endpoint for running tests'
19+
required: true
20+
ARTILLERY_CLOUD_API_KEY_TEST:
21+
description: 'Artillery Cloud API Key for running tests'
22+
required: true
23+
DD_TESTS_API_KEY:
24+
description: 'Datadog API Key for running tests'
25+
required: true
26+
DD_TESTS_APP_KEY:
27+
description: 'Datadog App Key for running tests'
28+
required: true
1429

1530
workflow_dispatch:
1631
inputs:
@@ -22,9 +37,10 @@ on:
2237
env:
2338
CF_LAMBDA_TEMPLATE: ${{ inputs.canary && 'aws-iam-lambda-cf-template-canary.yml' || 'aws-iam-lambda-cf-template.yml' }}
2439
CF_FARGATE_TEMPLATE: ${{ inputs.canary && 'aws-iam-fargate-cf-template-canary.yml' || 'aws-iam-fargate-cf-template.yml' }}
25-
GH_OIDC_LAMBDA_TEMPLATE: ${{ inputs.canary && 'gh-oidc-lambda-canary.yml' || 'gh-oidc-lambda.yml' }}
26-
GH_OIDC_FARGATE_TEMPLATE: ${{ inputs.canary && 'gh-oidc-fargate-canary.yml' || 'gh-oidc-fargate.yml' }}
40+
GH_OIDC_TEMPLATE: ${{ inputs.canary && 'github-oidc-canary.yml' || 'github-oidc.yml' }}
41+
2742
jobs:
43+
# Publish templates to AWS S3
2844
put-cloudformation-templates:
2945
runs-on: ubuntu-latest
3046

@@ -50,5 +66,155 @@ jobs:
5066
run: |
5167
aws s3 cp --acl public-read ./packages/artillery/lib/platform/aws/iam-cf-templates/aws-iam-fargate-cf-template.yml s3://artilleryio-cf-templates/${{ env.CF_FARGATE_TEMPLATE }}
5268
aws s3 cp --acl public-read ./packages/artillery/lib/platform/aws/iam-cf-templates/aws-iam-lambda-cf-template.yml s3://artilleryio-cf-templates/${{ env.CF_LAMBDA_TEMPLATE }}
53-
aws s3 cp --acl public-read ./packages/artillery/lib/platform/aws/iam-cf-templates/gh-oidc-lambda.yml s3://artilleryio-cf-templates/${{ env.GH_OIDC_LAMBDA_TEMPLATE }}
54-
aws s3 cp --acl public-read ./packages/artillery/lib/platform/aws/iam-cf-templates/gh-oidc-fargate.yml s3://artilleryio-cf-templates/${{ env.GH_OIDC_FARGATE_TEMPLATE }}
69+
aws s3 cp --acl public-read ./packages/artillery/lib/platform/aws/iam-cf-templates/github-oidc.yml s3://artilleryio-cf-templates/${{ env.GH_OIDC_TEMPLATE }}
70+
71+
# This job is used to test that the IAM role created from the `github-oidc.yml` CF template has the correct permissions to be able to run Artillery tests on Lambda and Fargate and that the OIDC is set correctly.
72+
set-up-and-run-artillery-test-on-aws:
73+
runs-on: ubuntu-latest
74+
75+
permissions:
76+
id-token: write
77+
contents: read
78+
needs: put-cloudformation-templates
79+
strategy:
80+
matrix:
81+
service: [lambda, fargate]
82+
include:
83+
- service: lambda
84+
test-file: 'test/cloud-e2e/lambda/lambda-smoke.test.js'
85+
- service: fargate
86+
test-file: 'test/cloud-e2e/fargate/dd-adot.test.js'
87+
max-parallel: 1
88+
89+
steps:
90+
- name: Checkout code
91+
uses: actions/checkout@v2
92+
93+
- name: Configure AWS Credentials
94+
uses: aws-actions/configure-aws-credentials@v2
95+
env:
96+
SHOW_STACK_TRACE: true
97+
with:
98+
aws-region: us-east-1
99+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID_FRESH_SETUP_TESTS }}:role/ResetAccountForRunningTests
100+
role-session-name: OIDCSession
101+
mask-aws-account-id: true
102+
103+
- name: Install aws-nuke
104+
run: |
105+
curl -sL https://github.com/rebuy-de/aws-nuke/releases/download/v2.25.0/aws-nuke-v2.25.0-linux-amd64.tar.gz | tar -xz
106+
sudo install aws-nuke-v2.25.0-linux-amd64 /usr/local/bin/aws-nuke
107+
108+
- name: Run aws-nuke
109+
run: |
110+
cat <<EOF > aws-nuke-config.yml
111+
regions:
112+
- "global"
113+
- "us-east-2"
114+
- "us-east-1"
115+
- "us-west-1"
116+
- "us-west-2"
117+
- "ap-south-1"
118+
- "ap-northeast-3"
119+
- "ap-northeast-2"
120+
- "ap-southeast-1"
121+
- "ap-southeast-2"
122+
- "ap-northeast-1"
123+
- "ca-central-1"
124+
- "eu-central-1"
125+
- "eu-west-1"
126+
- "eu-west-2"
127+
- "eu-west-3"
128+
- "eu-north-1"
129+
- "sa-east-1"
130+
131+
account-blocklist:
132+
- 111111111111
133+
134+
resource-types:
135+
targets:
136+
- IAMRole
137+
- IAMPolicy
138+
- IAMRolePolicyAttachment
139+
- IAMOpenIDConnectProvider
140+
- S3Bucket
141+
- S3Object
142+
- LambdaFunction
143+
- ECSTaskDefinition
144+
- ECSCluster
145+
- ECSContainerInstance
146+
- CloudFormationStack
147+
- SQSQueue
148+
- CloudWatchLogGroup
149+
- CloudWatchLogStream
150+
- SSMParameter
151+
152+
accounts:
153+
"${{ secrets.AWS_ACCOUNT_ID_FRESH_SETUP_TESTS }}":
154+
filters:
155+
IAMRole:
156+
- property: Name
157+
type: "glob"
158+
value: "AWS*"
159+
- property: Name
160+
type: "glob"
161+
value: "Organization*"
162+
- property: Name
163+
value: "ResetAccountForRunningTests"
164+
165+
IAMRolePolicyAttachment:
166+
- property: RoleName
167+
type: "glob"
168+
value: "AWS*"
169+
- property: RoleName
170+
value: "ResetAccountForRunningTests"
171+
- property: RoleName
172+
type: "glob"
173+
value: "Organization*"
174+
175+
IAMOpenIDConnectProvider:
176+
- property: Arn
177+
type: "contains"
178+
value: "oidc-provider/token.actions.githubusercontent.com"
179+
invert: true
180+
EOF
181+
182+
aws-nuke --config aws-nuke-config.yml --force --force-sleep 4 --no-dry-run
183+
184+
- name: Fetch CloudFormation Template
185+
run: |
186+
aws s3 cp s3://artilleryio-cf-templates/${{ env.GH_OIDC_TEMPLATE }} template.yml
187+
- name: Deploy CloudFormation Template
188+
run: |
189+
aws cloudformation create-stack \
190+
--stack-name iam-distributed-testing-setup \
191+
--template-body file://template.yml \
192+
--parameters ParameterKey=GitHubRepository,ParameterValue="artilleryio/artillery" \
193+
--capabilities CAPABILITY_NAMED_IAM
194+
aws cloudformation wait stack-create-complete --stack-name iam-distributed-testing-setup
195+
196+
- name: Configure AWS Credentials
197+
uses: aws-actions/configure-aws-credentials@v2
198+
env:
199+
SHOW_STACK_TRACE: true
200+
with:
201+
aws-region: us-east-1
202+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID_FRESH_SETUP_TESTS }}:role/ArtilleryGitHubOIDCRole
203+
role-session-name: OIDCSession
204+
mask-aws-account-id: true
205+
- name: Use Node.js 18.x
206+
uses: actions/setup-node@v2
207+
with:
208+
node-version: 18.x
209+
- run: .github/workflows/scripts/npm-command-retry.sh install
210+
- run: npm run build
211+
- name: Run Artillery Test
212+
env:
213+
ARTILLERY_CLOUD_ENDPOINT: ${{ secrets.ARTILLERY_CLOUD_ENDPOINT_TEST }}
214+
ARTILLERY_CLOUD_API_KEY: ${{ secrets.ARTILLERY_CLOUD_API_KEY_TEST }}
215+
FORCE_COLOR: 1
216+
DD_TESTS_API_KEY: ${{ secrets.DD_TESTS_API_KEY }}
217+
DD_TESTS_APP_KEY: ${{ secrets.DD_TESTS_APP_KEY }}
218+
run: |
219+
npm run test:aws:ci --workspace artillery -- --files ${{ matrix.test-file }}
220+

packages/artillery/lib/platform/aws/iam-cf-templates/gh-oidc-lambda.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Resources:
7474
Fn::If:
7575
- CreateOIDCProvider
7676
- !Ref GitHubOIDCProvider
77-
- !Ref GitHubOIDCProviderArn
77+
- !Sub "arn:aws:iam::${AWS::AccountId}:oidc-provider/token.actions.githubusercontent.com"
7878
Action: "sts:AssumeRoleWithWebIdentity"
7979
Condition: {
8080
StringEquals:

0 commit comments

Comments
 (0)