This repository was archived by the owner on Feb 6, 2026. It is now read-only.
Repository navigation
93 lines (82 loc) · 3.17 KB
/
Copy pathinstance-refresh.yml
File metadata and controls
93 lines (82 loc) · 3.17 KB
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
name: Instance refresh
run-name: Replacing instances for ${{ inputs.service }}
# Required for IDP JWT and actions/checkout
permissions:
id-token: write
contents: read
on:
workflow_call:
inputs:
environment:
type: string
required: true
description: "where to deploy"
service:
type: string
required: true
description: "service to deploy"
jobs:
replace:
environment: ${{ inputs.environment }}
concurrency:
group: instance-refresh-${{ inputs.environment }}-${{ inputs.service }}
cancel-in-progress: true
name: Instance refresh
runs-on: ubuntu-latest
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.AWS_ASSUME_ROLE_ARN }}
role-session-name: GitHub_to_AWS_via_FederatedOIDC
aws-region: us-east-1
- name: Instance refresh
run: |
poll_instance_refresh() {
local environment
local service
local id
environment="$1"
service="$2"
id="$3"
while true; do
status=$(aws autoscaling describe-instance-refreshes \
--auto-scaling-group-name "${environment}-${service}" \
--query "InstanceRefreshes[?InstanceRefreshId=='${id}'].Status" \
--output text)
if [ -z "$status" ]; then
echo "No instance refresh found with ID ${id} for ${environment}-${service}."
break
fi
echo "Instance refresh status: $status"
if [[ "$status" == "Successful" ]]; then
echo "Instance refresh completed successfully."
break
elif [[ "$status" == "Failed" || "$status" == "Cancelled" ]]; then
echo "Instance refresh failed or was cancelled."
exit 1
else
echo "Instance refresh is still in progress. Waiting..."
sleep 15
fi
done
}
check_existing_refresh() {
local environment
local service
environment="$1"
service="$2"
id=$(aws autoscaling describe-instance-refreshes \
--auto-scaling-group-name "${environment}-${service}"\
--query "InstanceRefreshes[?Status=='InProgress'].[InstanceRefreshId]"\
--output text)
poll_instance_refresh "$environment" "$service" "$id"
}
ENVIRONMENT="${{ inputs.environment }}"
SERVICE="${{ inputs.service }}"
echo "Checking if an instance refresh is already underway..."
check_existing_refresh "$ENVIRONMENT" "$SERVICE"
id=$(aws autoscaling start-instance-refresh \
--auto-scaling-group-name "${ENVIRONMENT}-${SERVICE}" \
--query 'InstanceRefreshId' --output text)
poll_instance_refresh "$ENVIRONMENT" "$SERVICE" "$id"