Skip to content

Commit d5c6a0d

Browse files
authored
New support for Application Migration Service (MGN) resources rebuy-de#1024 (rebuy-de#1025)
* Initial fix for issue rebuy-de#1024 * Remove buggy mgn-jobs.go * Remove buggy mgn-jobs.go * Add nuking of all MGN jobs: * rebuy-de#1025 - Correction of naming convention 'Arn' to 'ARN'
1 parent 902732b commit d5c6a0d

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed

resources/mgn-jobs.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws"
5+
"github.com/aws/aws-sdk-go/aws/session"
6+
"github.com/aws/aws-sdk-go/service/mgn"
7+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
8+
)
9+
10+
type MGNJob struct {
11+
svc *mgn.Mgn
12+
jobID *string
13+
arn *string
14+
tags map[string]*string
15+
}
16+
17+
func init() {
18+
register("MGNJob", ListMGNJobs)
19+
}
20+
21+
func ListMGNJobs(sess *session.Session) ([]Resource, error) {
22+
svc := mgn.New(sess)
23+
resources := []Resource{}
24+
25+
params := &mgn.DescribeJobsInput{
26+
MaxResults: aws.Int64(50),
27+
}
28+
29+
for {
30+
output, err := svc.DescribeJobs(params)
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
for _, job := range output.Items {
36+
resources = append(resources, &MGNJob{
37+
svc: svc,
38+
jobID: job.JobID,
39+
arn: job.Arn,
40+
tags: job.Tags,
41+
})
42+
}
43+
44+
if output.NextToken == nil {
45+
break
46+
}
47+
48+
params.NextToken = output.NextToken
49+
}
50+
51+
return resources, nil
52+
}
53+
54+
func (f *MGNJob) Remove() error {
55+
56+
_, err := f.svc.DeleteJob(&mgn.DeleteJobInput{
57+
JobID: f.jobID,
58+
})
59+
60+
return err
61+
}
62+
63+
func (f *MGNJob) Properties() types.Properties {
64+
properties := types.NewProperties()
65+
properties.Set("JobID", f.jobID)
66+
properties.Set("ARN", f.arn)
67+
68+
for key, val := range f.tags {
69+
properties.SetTag(&key, val)
70+
}
71+
return properties
72+
}
73+
74+
func (f *MGNJob) String() string {
75+
return *f.jobID
76+
}

resources/mgn-source_servers.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws"
5+
"github.com/aws/aws-sdk-go/aws/session"
6+
"github.com/aws/aws-sdk-go/service/mgn"
7+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
8+
)
9+
10+
type MGNSourceServer struct {
11+
svc *mgn.Mgn
12+
sourceServerID *string
13+
arn *string
14+
tags map[string]*string
15+
}
16+
17+
func init() {
18+
register("MGNSourceServer", ListMGNSourceServers)
19+
}
20+
21+
func ListMGNSourceServers(sess *session.Session) ([]Resource, error) {
22+
svc := mgn.New(sess)
23+
resources := []Resource{}
24+
25+
params := &mgn.DescribeSourceServersInput{
26+
MaxResults: aws.Int64(50),
27+
}
28+
29+
for {
30+
output, err := svc.DescribeSourceServers(params)
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
for _, sourceServer := range output.Items {
36+
resources = append(resources, &MGNSourceServer{
37+
svc: svc,
38+
sourceServerID: sourceServer.SourceServerID,
39+
arn: sourceServer.Arn,
40+
tags: sourceServer.Tags,
41+
})
42+
}
43+
44+
if output.NextToken == nil {
45+
break
46+
}
47+
48+
params.NextToken = output.NextToken
49+
}
50+
51+
return resources, nil
52+
}
53+
54+
func (f *MGNSourceServer) Remove() error {
55+
56+
_, err := f.svc.DeleteSourceServer(&mgn.DeleteSourceServerInput{
57+
SourceServerID: f.sourceServerID,
58+
})
59+
60+
return err
61+
}
62+
63+
func (f *MGNSourceServer) Properties() types.Properties {
64+
properties := types.NewProperties()
65+
properties.Set("SourceServerID", f.sourceServerID)
66+
properties.Set("ARN", f.arn)
67+
68+
for key, val := range f.tags {
69+
properties.SetTag(&key, val)
70+
}
71+
return properties
72+
}
73+
74+
func (f *MGNSourceServer) String() string {
75+
return *f.sourceServerID
76+
}

0 commit comments

Comments
 (0)