osbuild-service-maintenance: implement removal on invalid parent
Add a safeguard to ensure secure instances without valid parent instances are terminated, as they are unnecessary to retain. Typically, the parent does not exist if the secure instance is older than 2 hours, but this check provides additional validation. HMS-3632
This commit is contained in:
parent
a7119a4d0f
commit
7ebe266d3c
2 changed files with 99 additions and 4 deletions
|
|
@ -84,6 +84,19 @@ func (a *AWS) DescribeInstancesByTag(tagKey, tagValue string) ([]ec2types.Reserv
|
|||
return res.Reservations, nil
|
||||
}
|
||||
|
||||
func (a *AWS) DescribeInstancesByInstanceID(instanceID string) ([]ec2types.Reservation, error) {
|
||||
res, err := a.ec2.DescribeInstances(
|
||||
context.Background(),
|
||||
&ec2.DescribeInstancesInput{
|
||||
InstanceIds: []string{instanceID},
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res.Reservations, nil
|
||||
}
|
||||
|
||||
func (a *AWS) TerminateInstances(instanceIDs []string) error {
|
||||
_, err := a.ec2.TerminateInstances(
|
||||
context.Background(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue