-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate apprunner resources from upstream to libnuke format (#38)
* Adding support for AppRunner services (#1060) * adding code for removing custom origin request policies * rename resource * test for replication * revert secretsmanager change * undo this * revert mod and sum changes * add resources for redshift scheduled actions * remove cloudfront resource * clean up * cloudwatch rum app * first attempt at apprunner-service * first attempt at apprunner-service * add apprunner connection as well * clean up * chore: migrate resources to libnuke format --------- Co-authored-by: Mike Schouw <[email protected]>
- Loading branch information
1 parent
ad7ddd9
commit 7f00937
Showing
2 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/service/apprunner" | ||
|
||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
type AppRunnerConnection struct { | ||
svc *apprunner.AppRunner | ||
ConnectionArn *string | ||
ConnectionName *string | ||
} | ||
|
||
const AppRunnerConnectionResource = "AppRunnerConnection" | ||
|
||
func init() { | ||
resource.Register(&resource.Registration{ | ||
Name: AppRunnerConnectionResource, | ||
Scope: nuke.Account, | ||
Lister: &AppRunnerConnectionLister{}, | ||
}) | ||
} | ||
|
||
type AppRunnerConnectionLister struct{} | ||
|
||
func (l *AppRunnerConnectionLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := apprunner.New(opts.Session) | ||
resources := make([]resource.Resource, 0) | ||
|
||
params := &apprunner.ListConnectionsInput{} | ||
|
||
for { | ||
resp, err := svc.ListConnections(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, item := range resp.ConnectionSummaryList { | ||
resources = append(resources, &AppRunnerConnection{ | ||
svc: svc, | ||
ConnectionArn: item.ConnectionArn, | ||
ConnectionName: item.ConnectionName, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *AppRunnerConnection) Remove(_ context.Context) error { | ||
_, err := f.svc.DeleteConnection(&apprunner.DeleteConnectionInput{ | ||
ConnectionArn: f.ConnectionArn, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *AppRunnerConnection) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("ConnectionArn", f.ConnectionArn) | ||
properties.Set("ConnectionName", f.ConnectionName) | ||
return properties | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/service/apprunner" | ||
|
||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
type AppRunnerService struct { | ||
svc *apprunner.AppRunner | ||
ServiceArn *string | ||
ServiceId *string | ||
ServiceName *string | ||
} | ||
|
||
const AppRunnerServiceResource = "AppRunnerService" | ||
|
||
func init() { | ||
resource.Register(&resource.Registration{ | ||
Name: AppRunnerServiceResource, | ||
Scope: nuke.Account, | ||
Lister: &AppRunnerServiceLister{}, | ||
}) | ||
} | ||
|
||
type AppRunnerServiceLister struct{} | ||
|
||
func (l *AppRunnerServiceLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := apprunner.New(opts.Session) | ||
resources := make([]resource.Resource, 0) | ||
|
||
params := &apprunner.ListServicesInput{} | ||
|
||
for { | ||
resp, err := svc.ListServices(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, item := range resp.ServiceSummaryList { | ||
resources = append(resources, &AppRunnerService{ | ||
svc: svc, | ||
ServiceArn: item.ServiceArn, | ||
ServiceId: item.ServiceId, | ||
ServiceName: item.ServiceName, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *AppRunnerService) Remove(_ context.Context) error { | ||
_, err := f.svc.DeleteService(&apprunner.DeleteServiceInput{ | ||
ServiceArn: f.ServiceArn, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *AppRunnerService) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("ServiceArn", f.ServiceArn) | ||
properties.Set("ServiceId", f.ServiceId) | ||
properties.Set("ServiceName", f.ServiceName) | ||
return properties | ||
} |