Skip to content

Commit

Permalink
Merge pull request #178 from ekristen/conformation-packs
Browse files Browse the repository at this point in the history
feat: support config conformance pack removal
  • Loading branch information
ekristen authored May 21, 2024
2 parents c9e8d90 + 6953a97 commit 7a31dac
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
8 changes: 8 additions & 0 deletions resources/cloudformation-stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resources
import (
"context"
"errors"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -74,6 +75,13 @@ type CloudFormationStack struct {
settings *settings.Setting
}

func (cfs *CloudFormationStack) Filter() error {
if *cfs.stack.Description == "DO NOT MODIFY THIS STACK! This stack is managed by Config Conformance Packs." {
return fmt.Errorf("stack is managed by Config Conformance Packs")
}
return nil
}

func (cfs *CloudFormationStack) Settings(setting *settings.Setting) {
cfs.settings = setting
}
Expand Down
82 changes: 82 additions & 0 deletions resources/configservice-conformance-pack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package resources

import (
"context"

"github.com/aws/aws-sdk-go/service/configservice"

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

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

const ConfigServiceConformancePackResource = "ConfigServiceConformancePack"

func init() {
registry.Register(&registry.Registration{
Name: ConfigServiceConformancePackResource,
Scope: nuke.Account,
Lister: &ConfigServiceConformancePackLister{},
})
}

type ConfigServiceConformancePackLister struct{}

func (l *ConfigServiceConformancePackLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)
svc := configservice.New(opts.Session)
var resources []resource.Resource

var nextToken *string

for {
res, err := svc.DescribeConformancePacks(&configservice.DescribeConformancePacksInput{
NextToken: nextToken,
})
if err != nil {
return nil, err
}

for _, p := range res.ConformancePackDetails {
resources = append(resources, &ConfigServiceConformancePack{
svc: svc,
id: p.ConformancePackId,
name: p.ConformancePackName,
})
}

if res.NextToken == nil {
break
}

nextToken = res.NextToken
}

return resources, nil
}

type ConfigServiceConformancePack struct {
svc *configservice.ConfigService
id *string
name *string
}

func (r *ConfigServiceConformancePack) Remove(_ context.Context) error {
_, err := r.svc.DeleteConformancePack(&configservice.DeleteConformancePackInput{
ConformancePackName: r.name,
})
return err
}

func (r *ConfigServiceConformancePack) Properties() types.Properties {
props := types.NewProperties()
props.Set("ID", r.id)
props.Set("Name", r.name)
return props
}

func (r *ConfigServiceConformancePack) String() string {
return *r.id
}

0 comments on commit 7a31dac

Please sign in to comment.