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

New support for Application Migration Service (MGN) resources #1024 #1025

Merged
merged 9 commits into from
Jun 28, 2023
76 changes: 76 additions & 0 deletions resources/mgn-jobs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/mgn"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type MGNJob struct {
svc *mgn.Mgn
jobID *string
arn *string
tags map[string]*string
}

func init() {
register("MGNJob", ListMGNJobs)
}

func ListMGNJobs(sess *session.Session) ([]Resource, error) {
svc := mgn.New(sess)
resources := []Resource{}

params := &mgn.DescribeJobsInput{
MaxResults: aws.Int64(50),
}

for {
output, err := svc.DescribeJobs(params)
if err != nil {
return nil, err
}

for _, job := range output.Items {
resources = append(resources, &MGNJob{
svc: svc,
jobID: job.JobID,
arn: job.Arn,
tags: job.Tags,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *MGNJob) Remove() error {

_, err := f.svc.DeleteJob(&mgn.DeleteJobInput{
JobID: f.jobID,
})

return err
}

func (f *MGNJob) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("JobID", f.jobID)
properties.Set("Arn", f.arn)
joelee marked this conversation as resolved.
Show resolved Hide resolved

for key, val := range f.tags {
properties.SetTag(&key, val)
}
return properties
}

func (f *MGNJob) String() string {
return *f.jobID
}
76 changes: 76 additions & 0 deletions resources/mgn-source_servers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/mgn"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type MGNSourceServer struct {
svc *mgn.Mgn
sourceServerID *string
arn *string
tags map[string]*string
}

func init() {
register("MGNSourceServer", ListMGNSourceServers)
}

func ListMGNSourceServers(sess *session.Session) ([]Resource, error) {
svc := mgn.New(sess)
resources := []Resource{}

params := &mgn.DescribeSourceServersInput{
MaxResults: aws.Int64(50),
}

for {
output, err := svc.DescribeSourceServers(params)
if err != nil {
return nil, err
}

for _, sourceServer := range output.Items {
resources = append(resources, &MGNSourceServer{
svc: svc,
sourceServerID: sourceServer.SourceServerID,
arn: sourceServer.Arn,
tags: sourceServer.Tags,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *MGNSourceServer) Remove() error {

_, err := f.svc.DeleteSourceServer(&mgn.DeleteSourceServerInput{
SourceServerID: f.sourceServerID,
})

return err
}

func (f *MGNSourceServer) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("SourceServerID", f.sourceServerID)
properties.Set("Arn", f.arn)
joelee marked this conversation as resolved.
Show resolved Hide resolved

for key, val := range f.tags {
properties.SetTag(&key, val)
}
return properties
}

func (f *MGNSourceServer) String() string {
return *f.sourceServerID
}