-
Notifications
You must be signed in to change notification settings - Fork 1.4k
184 lines (160 loc) · 6.54 KB
/
e2e-parallel-full.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: e2e-parallel-full
on:
workflow_dispatch:
inputs:
TFDestroy:
description: 'Destroy TF Automatically (false/true) - Default: true'
required: true
default: 'true'
concurrency: e2e-parallel-full
env:
IAMLIVE_VERSION: v0.48.0
BUCKET_NAME: terraform-eks-blueprints-iam-policies-examples
permissions:
contents: read
jobs:
prereq-cleanup:
name: Prerequisite Cleanup
runs-on: ubuntu-latest
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Auth AWS
uses: aws-actions/[email protected]
with:
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
aws-region: us-west-2
role-duration-seconds: 3600
role-session-name: GithubActions-Session
- name: Ensure log groups are removed
run: |
pip3 install boto3
python3 .github/scripts/delete-log-groups.py
deploy:
name: Run e2e test
runs-on: ubuntu-latest
needs: prereq-cleanup
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
include:
- example_path: patterns/agones-game-controller
- example_path: patterns/fargate-serverless
- example_path: patterns/gitops/getting-started-argocd
- example_path: patterns/ipv6-eks-cluster
- example_path: patterns/karpenter
- example_path: patterns/multi-tenancy-with-teams
- example_path: patterns/stateful
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup backend
# Un-comment remote backend for use in workflow
run: sed -i "s/# //g" ${{ matrix.example_path }}/versions.tf
- name: Auth AWS
uses: aws-actions/[email protected]
with:
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
aws-region: us-west-2
role-duration-seconds: 3600
role-session-name: GithubActions-Session
- name: Iamlive Setup & Run
run: |
#!/bin/bash
set -eox pipefail
wget -O iamlive.tar.gz "https://github.com/iann0036/iamlive/releases/download/${{ env.IAMLIVE_VERSION }}/iamlive-${{ env.IAMLIVE_VERSION }}-linux-amd64.tar.gz"
tar -xzf iamlive.tar.gz
chmod +x iamlive
IAMLIVE_PID=$(./iamlive --mode csm --output-file ${HOME}/policy.json --refresh-rate 1 --sort-alphabetical --force-wildcard-resource --background)
echo "iamlive_pid=$IAMLIVE_PID" >> $GITHUB_ENV
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.3.10
- name: Terraform Apply
id: apply
working-directory: ${{ matrix.example_path }}
run: |
terraform init -upgrade=true
export AWS_CSM_ENABLED=true
export AWS_CSM_PORT=31000
export AWS_CSM_HOST=127.0.0.1
terraform apply -target=module.vpc -no-color -input=false -auto-approve
terraform apply -target=module.eks_blueprints -no-color -input=false -auto-approve
terraform apply -target=module.eks -no-color -input=false -auto-approve
terraform apply -target=module.eks_blueprints_kubernetes_addons -no-color -input=false -auto-approve
terraform apply -target=module.eks_blueprints_addons -no-color -input=false -auto-approve
terraform apply -no-color -input=false -auto-approve
- name: Terraform Destroy
if: github.event.inputs.TFDestroy == 'true' && (steps.apply.outcome == 'success' || steps.apply.outcome == 'failure')
working-directory: ${{ matrix.example_path }}
run: |
terraform init -upgrade=true
export AWS_CSM_ENABLED=true
export AWS_CSM_PORT=31000
export AWS_CSM_HOST=127.0.0.1
terraform destroy -target=module.eks_blueprints_kubernetes_addons -no-color -input=false -auto-approve
terraform destroy -target=module.eks_blueprints_addons -no-color -input=false -auto-approve
terraform destroy -target=module.eks_blueprints -no-color -input=false -auto-approve
terraform destroy -target=module.eks -no-color -input=false -auto-approve
terraform destroy -no-color -input=false -auto-approve
- name: Fail if TF apply failed
if: steps.apply.outcome == 'failure'
run: |
echo "Terraform Apply step failed...Please check the logs of the Terraform Apply step."
echo "Failing the job to avoid false positives."
kill ${{ env.iamlive_pid }}
while $(kill -0 ${{ env.iamlive_pid }} 2>/dev/null); do sleep 1; done;
cat ${HOME}/policy.json
exit 1
- name: Iamlive Print & Upload Policy
if: ${{ always() }}
run: |
kill ${{ env.iamlive_pid }}
while $(kill -0 ${{ env.iamlive_pid }} 2>/dev/null); do sleep 1; done;
cat ${HOME}/policy.json
aws s3 cp ${HOME}/policy.json s3://${{ env.BUCKET_NAME }}/${{ matrix.example_path }}.json
post_deploy:
if: ${{ always() }}
needs: [deploy]
permissions:
id-token: write
contents: read
name: Merge Policies and Print Final IAM Policy
runs-on: ubuntu-latest
steps:
# Be careful not to change this to explicit checkout from PR ref/code, as below we run a python code that may change from the PR code.
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Configure AWS credentials from Test account
uses: aws-actions/[email protected]
with:
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
aws-region: us-west-2
role-duration-seconds: 3600
role-session-name: GithubActions-Session
- name: Merge iamlive IAM policies and Print Final Policy
id: dirs
run: |
pip3 install boto3
python3 .github/scripts/iam-policy-generator.py