/
ec2-launch-templates.go
56 lines (47 loc) · 1.23 KB
/
ec2-launch-templates.go
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
package resources
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)
type EC2LaunchTemplate struct {
svc *ec2.EC2
name *string
tag []*ec2.Tag
}
func init() {
register("EC2LaunchTemplate", ListEC2LaunchTemplates)
}
func ListEC2LaunchTemplates(sess *session.Session) ([]Resource, error) {
svc := ec2.New(sess)
resp, err := svc.DescribeLaunchTemplates(nil)
if err != nil {
return nil, err
}
resources := make([]Resource, 0)
for _, template := range resp.LaunchTemplates {
resources = append(resources, &EC2LaunchTemplate{
svc: svc,
name: template.LaunchTemplateName,
tag: template.Tags,
})
}
return resources, nil
}
func (template *EC2LaunchTemplate) Remove() error {
_, err := template.svc.DeleteLaunchTemplate(&ec2.DeleteLaunchTemplateInput{
LaunchTemplateName: template.name,
})
return err
}
func (template *EC2LaunchTemplate) Properties() types.Properties {
properties := types.NewProperties()
for _, tagValue := range template.tag {
properties.SetTag(tagValue.Key, tagValue.Value)
}
properties.Set("Name", template.name)
return properties
}
func (template *EC2LaunchTemplate) String() string {
return *template.name
}