Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Adds ASG lifecycle hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanlindauer committed Oct 16, 2018
1 parent 5fbd2cb commit 1c3885a
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions resources/autoscaling-lifecyclehooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/autoscaling"
)

func init() {
register("LifecycleHook", ListLifecycleHooks)
}

func ListLifecycleHooks(s *session.Session) ([]Resource, error) {
svc := autoscaling.New(s)

asgResp, err := svc.DescribeAutoScalingGroups(&autoscaling.DescribeAutoScalingGroupsInput{})
if err != nil {
return nil, err
}

resources := make([]Resource, 0)
for _, asg := range asgResp.AutoScalingGroups {
lchResp, err := svc.DescribeLifecycleHooks(&autoscaling.DescribeLifecycleHooksInput{
AutoScalingGroupName: asg.AutoScalingGroupName,
})
if err != nil {
return nil, err
}

for _, lch := range lchResp.LifecycleHooks {
resources = append(resources, &LifecycleHook{
svc: svc,
lifecycleHookName: lch.LifecycleHookName,
autoScalingGroupName: lch.AutoScalingGroupName,
})
}
}

return resources, nil
}

type LifecycleHook struct {
svc *autoscaling.AutoScaling
lifecycleHookName *string
autoScalingGroupName *string
}

func (lch *LifecycleHook) Remove() error {
params := &autoscaling.DeleteLifecycleHookInput{
AutoScalingGroupName: lch.autoScalingGroupName,
LifecycleHookName: lch.lifecycleHookName,
}

_, err := lch.svc.DeleteLifecycleHook(params)
if err != nil {
return err
}

return nil
}

func (lch *LifecycleHook) String() string {
return *lch.lifecycleHookName
}

0 comments on commit 1c3885a

Please sign in to comment.