File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 18
18
- name : Build AMI
19
19
run : |
20
20
GIT_SHA=$(git rev-parse HEAD)
21
- packer build -var "git-head-version=${GIT_SHA}" -var-file="development-arm.vars.pkr.hcl" -var-file="common.vars.pkr.hcl" amazon-arm64.pkr.hcl
21
+ packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var -file="development-arm.vars.pkr.hcl" -var-file="common.vars.pkr.hcl" amazon-arm64.pkr.hcl
22
22
23
- - name : Slack Notification
23
+ - name : Slack Notification on Failure
24
24
if : ${{ failure() }}
25
25
uses : rtCamp/action-slack-notify@v2
26
26
env :
29
29
SLACK_COLOR : ' danger'
30
30
SLACK_MESSAGE : ' Building Postgres AMI failed'
31
31
SLACK_FOOTER : ' '
32
+
33
+ - name : Cleanup resources on build cancellation
34
+ if : ${{ cancelled() }}
35
+ run : |
36
+ aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -I {} aws ec2 terminate-instances --instance-ids {}
Original file line number Diff line number Diff line change @@ -82,6 +82,11 @@ variable "git-head-version" {
82
82
default = " unknown"
83
83
}
84
84
85
+ variable "packer-execution-id" {
86
+ type = string
87
+ default = " unknown"
88
+ }
89
+
85
90
# source block
86
91
source "amazon-ebssurrogate" "source" {
87
92
profile = " ${ var . profile } "
@@ -129,8 +134,9 @@ source "amazon-ebssurrogate" "source" {
129
134
}
130
135
131
136
run_tags = {
132
- creator = " packer"
133
- appType = " postgres"
137
+ creator = " packer"
138
+ appType = " postgres"
139
+ packerExecutionId = " ${ var . packer-execution-id } "
134
140
}
135
141
run_volume_tags = {
136
142
creator = " packer"
You can’t perform that action at this time.
0 commit comments