-
Notifications
You must be signed in to change notification settings - Fork 0
179 lines (157 loc) · 6.34 KB
/
test-gha-aurora-manage-cluster.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
name: Aurora Cluster creation and destruction test
on:
schedule:
- cron: '0 2 * * 1' # At 02:00 on Monday.
workflow_dispatch:
inputs:
cluster_name:
description: "Aurora Cluster name."
required: false
type: string
delete_cluster:
description: "Whether to delete the Aurora cluster."
required: false
type: boolean
default: true
db_username:
description: "Database username."
required: false
type: string
db_password:
description: "Database password."
required: false
type: string
vpc-id:
description: "VPC ID to create the cluster in."
required: false
type: string
default: ''
subnet-ids:
description: "List of subnet IDs to create the cluster in."
required: false
type: string
default: ''
cidr-blocks:
description: "CIDR blocks to allow access from and to."
required: false
type: string
default: ''
pull_request:
paths:
- modules/fixtures/backend.tf
- modules/fixtures/fixtures.default.aurora.tfvars
- modules/aurora/**.tf
- .tool-versions
- .github/workflows/test-gha-aurora-manage-cluster.yml
- .github/actions/aurora-manage-cluster/*.yml
- justfile
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
env:
AWS_PROFILE: "infex"
AWS_REGION: "eu-west-2"
# please keep those synced with tests.yml
TF_STATE_BUCKET: "tests-eks-tf-state-eu-central-1"
TF_STATE_BUCKET_REGION: "eu-central-1"
jobs:
action-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Install tooling using asdf
uses: asdf-vm/actions/install@05e0d2ed97b598bfce82fd30daf324ae0c4570e6 # v3
- name: Import Secrets
id: secrets
uses: hashicorp/vault-action@v3
with:
url: ${{ secrets.VAULT_ADDR }}
method: approle
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}
exportEnv: false
secrets: |
secret/data/products/infrastructure-experience/ci/common AWS_ACCESS_KEY;
secret/data/products/infrastructure-experience/ci/common AWS_SECRET_KEY;
- name: Add profile credentials to ~/.aws/credentials
run: |
aws configure set aws_access_key_id ${{ steps.secrets.outputs.AWS_ACCESS_KEY }} --profile ${{ env.AWS_PROFILE }}
aws configure set aws_secret_access_key ${{ steps.secrets.outputs.AWS_SECRET_KEY }} --profile ${{ env.AWS_PROFILE }}
aws configure set region ${{ env.AWS_REGION }} --profile ${{ env.AWS_PROFILE }}
- name: Get Cluster Info
id: commit_info
run: |
if [[ -n "${{ inputs.cluster_name }}" ]]; then
cluster_name="${{ inputs.cluster_name }}"
else
cluster_name="aurora-$(git rev-parse --short HEAD)"
fi
if [[ -n "${{ inputs.db_username }}" ]]; then
db_username="${{ inputs.db_username }}"
else
db_username="user$(openssl rand -hex 4)"
fi
if [[ -n "${{ inputs.db_password }}" ]]; then
db_password="${{ inputs.db_password }}"
else
db_password="$(openssl rand -base64 12)"
fi
if [[ -n "${{ inputs.vpc-id }}" ]]; then
vpc_id="${{ inputs.vpc-id }}"
else
vpc_id="$(aws ec2 describe-vpcs --query 'Vpcs[?IsDefault].VpcId' --output text --profile ${{ env.AWS_PROFILE }})"
fi
if [[ -n "${{ inputs.subnet-ids }}" ]]; then
subnet_ids="${{ inputs.subnet-ids }}"
else
subnet_ids=$(aws ec2 describe-subnets --filters "Name=vpc-id,Values=${vpc_id}" --query "Subnets[*].SubnetId" --output json --profile "${{ env.AWS_PROFILE }}")
fi
if [[ -n "${{ inputs.cidr-blocks }}" ]]; then
cidr_blocks="${{ inputs.cidr-blocks }}"
else
cidr_blocks='["0.0.0.0/0"]' # Default CIDR to allow access from anywhere
fi
echo "cluster_name=$cluster_name" | tee -a "$GITHUB_OUTPUT"
echo "db_username=$db_username" | tee -a "$GITHUB_OUTPUT"
echo "db_password=$db_password" | tee -a "$GITHUB_OUTPUT"
echo "vpc_id=$vpc_id" | tee -a "$GITHUB_OUTPUT"
echo "subnet_ids=$subnet_ids" | tee -a "$GITHUB_OUTPUT"
echo "cidr_blocks=$cidr_blocks" | tee -a "$GITHUB_OUTPUT"
tf_modules_revision=$(git rev-parse HEAD)
echo "tf_modules_revision=$tf_modules_revision" | tee -a "$GITHUB_OUTPUT"
- name: Create Aurora Cluster
timeout-minutes: 125
uses: ./.github/actions/aurora-manage-cluster
id: create_cluster
with:
cluster-name: ${{ steps.commit_info.outputs.cluster_name }}
username: ${{ steps.commit_info.outputs.db_username }}
password: ${{ steps.commit_info.outputs.db_password }}
aws-region: ${{ env.AWS_REGION }}
s3-backend-bucket: ${{ env.TF_STATE_BUCKET }}
s3-bucket-region: ${{ env.TF_STATE_BUCKET_REGION }}
tf-modules-revision: ${{ steps.commit_info.outputs.tf_modules_revision }}
vpc-id: ${{ steps.commit_info.outputs.vpc_id }}
subnet-ids: ${{ steps.commit_info.outputs.subnet_ids }}
cidr-blocks: ${{ steps.commit_info.outputs.cidr_blocks }}
- name: Delete Aurora Cluster
timeout-minutes: 125
if: always() && !(github.event_name == 'workflow_dispatch' && github.event.inputs.delete_cluster == 'false')
uses: ./.github/actions/eks-cleanup-resources
with:
tf-bucket: ${{ env.TF_STATE_BUCKET }}
tf-bucket-region: ${{ env.TF_STATE_BUCKET_REGION }}
max-age-hours: 0
target: ${{ steps.commit_info.outputs.cluster_name }}
- name: Notify in Slack in case of failure
id: slack-notification
if: failure() && github.event_name == 'schedule'
uses: camunda/infraex-common-config/.github/actions/report-failure-on-slack@main
with:
vault_addr: ${{ secrets.VAULT_ADDR }}
vault_role_id: ${{ secrets.VAULT_ROLE_ID }}
vault_secret_id: ${{ secrets.VAULT_SECRET_ID }}