Skip to content

Commit

Permalink
Merge pull request #492 from ekristen/feat-ssm
Browse files Browse the repository at this point in the history
feat: ssm quick setup resources
  • Loading branch information
ekristen authored Jan 3, 2025
2 parents f82fbbc + 03086f4 commit 51e7c33
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 7 deletions.
31 changes: 31 additions & 0 deletions docs/resources/ssm-quick-setup-configuration-manager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
generated: true
---

# SSMQuickSetupConfigurationManager


## Resource

```text
SSMQuickSetupConfigurationManager
```

## Properties


- `ARN`: No Description
- `Name`: No Description

!!! note - Using Properties
Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property
names to write filters for what you want to **keep** and omit from the nuke process.

### String Property

The string representation of a resource is generally the value of the Name, ID or ARN field of the resource. Not all
resources support properties. To write a filter against the string representation, simply omit the `property` field in
the filter.

The string value is always what is used in the output of the log format when a resource is identified.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7 // indirect
github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.24.8 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.7 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7 h1:Hi0KGbrnr57bEH
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7/go.mod h1:wKNgWgExdjjrm4qvfbTorkvocEstaoDl4WCvGfeCy9c=
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1 h1:aOVVZJgWbaH+EJYPvEgkNhCEbXXvH7+oML36oaPK3zE=
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1/go.mod h1:r+xl5yzMk9083rMR+sJ5TYj9Tihvf/l1oxzZXDgGj2Q=
github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2 h1:4siT1z3nEVxJq1jZYu1SRoct5xgbKen+ammCuZBZ2zI=
github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2/go.mod h1:KSO1+erW2SUB6Mw/Qamu1fOT5fn/mzd9G79ENbYqyRQ=
github.com/aws/aws-sdk-go-v2/service/sso v1.24.8 h1:CvuUmnXI7ebaUAhbJcDy9YQx8wHR69eZ9I7q5hszt/g=
github.com/aws/aws-sdk-go-v2/service/sso v1.24.8/go.mod h1:XDeGv1opzwm8ubxddF0cgqkZWsyOtw4lr6dxwmb6YQg=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.7 h1:F2rBfNAL5UyswqoeWv9zs74N/NanhK16ydHW1pahX6E=
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ nav:
- SSM Maintenance Window: resources/ssm-maintenance-window.md
- SSM Parameter: resources/ssm-parameter.md
- SSM Patch Baseline: resources/ssm-patch-baseline.md
- SSM Quick Setup Configuration Manager: resources/ssm-quick-setup-configuration-manager.md
- SSM Resource Data Sync: resources/ssm-resource-data-sync.md
- Sage Maker App: resources/sage-maker-app.md
- Sage Maker Domain: resources/sage-maker-domain.md
Expand Down
2 changes: 2 additions & 0 deletions pkg/commands/nuke/nuke.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nuke
import (
"context"
"fmt"
"os"
"slices"
"strings"
"time"
Expand Down Expand Up @@ -75,6 +76,7 @@ func execute(c *cli.Context) error { //nolint:funlen,gocyclo
}

logger := logrus.StandardLogger()
logger.SetOutput(os.Stdout)

// Parse the user supplied configuration file to pass in part to configure the nuke process.
parsedConfig, err := config.New(libconfig.Options{
Expand Down
82 changes: 82 additions & 0 deletions resources/ssmquicksetup-configuration-manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package resources

import (
"context"
"strings"

"github.com/gotidy/ptr"

"github.com/aws/aws-sdk-go-v2/service/ssmquicksetup"

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)

const SSMQuickSetupConfigurationManagerResource = "SSMQuickSetupConfigurationManager"

func init() {
registry.Register(&registry.Registration{
Name: SSMQuickSetupConfigurationManagerResource,
Scope: nuke.Account,
Resource: &SSMQuickSetupConfigurationManager{},
Lister: &SSMQuickSetupConfigurationManagerLister{},
})
}

type SSMQuickSetupConfigurationManagerLister struct{}

func (l *SSMQuickSetupConfigurationManagerLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)
svc := ssmquicksetup.NewFromConfig(*opts.Config)
var resources []resource.Resource

res, err := svc.ListConfigurationManagers(ctx, &ssmquicksetup.ListConfigurationManagersInput{})
if err != nil {
return nil, err
}

for _, p := range res.ConfigurationManagersList {
resources = append(resources, &SSMQuickSetupConfigurationManager{
svc: svc,
ARN: p.ManagerArn,
Name: p.Name,
})
}

return resources, nil
}

type SSMQuickSetupConfigurationManager struct {
svc *ssmquicksetup.Client
ARN *string
Name *string
}

// GetName returns the name of the resource or the last part of the ARN if not set so that the stringer resource has
// a value to display
func (r *SSMQuickSetupConfigurationManager) GetName() string {
if ptr.ToString(r.Name) != "" {
return ptr.ToString(r.Name)
}

parts := strings.Split(ptr.ToString(r.ARN), "/")
return parts[len(parts)-1]
}

func (r *SSMQuickSetupConfigurationManager) Remove(ctx context.Context) error {
_, err := r.svc.DeleteConfigurationManager(ctx, &ssmquicksetup.DeleteConfigurationManagerInput{
ManagerArn: r.ARN,
})
return err
}

func (r *SSMQuickSetupConfigurationManager) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *SSMQuickSetupConfigurationManager) String() string {
return r.GetName()
}
13 changes: 6 additions & 7 deletions tools/create-resource/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const resourceTemplate = `package resources
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/{{.Service}}"
"github.com/aws/aws-sdk-go-v2/service/{{.Service}}"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/registry"
Expand All @@ -41,12 +40,12 @@ type {{.Combined}}Lister struct{}
func (l *{{.Combined}}Lister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)
svc := {{.Service}}.New(opts.Session)
svc := {{.Service}}.NewFromConfig(*opts.Config)
var resources []resource.Resource
// NOTE: you might have to modify the code below to actually work, this currently does not
// inspect the aws sdk instead is a jumping off point
res, err := svc.List{{.ResourceTypeTitle}}s(&{{.Service}}.List{{.ResourceTypeTitle}}sInput{})
res, err := svc.List{{.ResourceTypeTitle}}s(ctx, &{{.Service}}.List{{.ResourceTypeTitle}}sInput{})
if err != nil {
return nil, err
}
Expand All @@ -63,13 +62,13 @@ func (l *{{.Combined}}Lister) List(_ context.Context, o interface{}) ([]resource
}
type {{.Combined}} struct {
svc *{{.Service}}.{{.ServiceTitle}}
svc *{{.Service}}.Client
ID *string
Tags []*{{.Service}}.Tag
}
func (r *{{.Combined}}) Remove(_ context.Context) error {
_, err := r.svc.Delete{{.ResourceTypeTitle}}(&{{.Service}}.Delete{{.ResourceTypeTitle}}Input{
func (r *{{.Combined}}) Remove(ctx context.Context) error {
_, err := r.svc.Delete{{.ResourceTypeTitle}}(ctx, &{{.Service}}.Delete{{.ResourceTypeTitle}}Input{
{{.ResourceTypeTitle}}Id: r.id,
})
return err
Expand Down

0 comments on commit 51e7c33

Please sign in to comment.