LaunchTemplate - support for deletion of instance group which using launch template

This commit is contained in:
Pavlo Kutishchev 2019-05-13 16:24:43 +02:00
parent 1703962472
commit 7a40da5016
1 changed files with 23 additions and 7 deletions

View File

@ -350,6 +350,7 @@ func deleteGroup(c AWSCloud, g *cloudinstances.CloudInstanceGroup) error {
name := aws.StringValue(asg.AutoScalingGroupName)
template := aws.StringValue(asg.LaunchConfigurationName)
launchTemplate := aws.StringValue(asg.LaunchTemplate.LaunchTemplateName)
// Delete ASG
{
@ -365,14 +366,29 @@ func deleteGroup(c AWSCloud, g *cloudinstances.CloudInstanceGroup) error {
}
// Delete LaunchConfig
{
klog.V(2).Infof("Deleting autoscaling launch configuration %q", template)
request := &autoscaling.DeleteLaunchConfigurationInput{
LaunchConfigurationName: aws.String(template),
if launchTemplate != "" {
// Delete launchTemplate
{
klog.V(2).Infof("Deleting autoscaling launch template %q", launchTemplate)
req := &ec2.DeleteLaunchTemplateInput{
LaunchTemplateName: aws.String(launchTemplate),
}
_, err := c.EC2().DeleteLaunchTemplate(req)
if err != nil {
return fmt.Errorf("error deleting autoscaling launch template %q: %v", launchTemplate, err)
}
}
_, err := c.Autoscaling().DeleteLaunchConfiguration(request)
if err != nil {
return fmt.Errorf("error deleting autoscaling launch configuration %q: %v", template, err)
} else if template != "" {
// Delete LaunchConfig
{
klog.V(2).Infof("Deleting autoscaling launch configuration %q", template)
request := &autoscaling.DeleteLaunchConfigurationInput{
LaunchConfigurationName: aws.String(template),
}
_, err := c.Autoscaling().DeleteLaunchConfiguration(request)
if err != nil {
return fmt.Errorf("error deleting autoscaling launch configuration %q: %v", template, err)
}
}
}