Skip to content

Commit 7a31dac

Browse files
authored
Merge pull request ekristen#178 from ekristen/conformation-packs
feat: support config conformance pack removal
2 parents c9e8d90 + 6953a97 commit 7a31dac

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

resources/cloudformation-stack.go

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package resources
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"strings"
78
"time"
89

@@ -74,6 +75,13 @@ type CloudFormationStack struct {
7475
settings *settings.Setting
7576
}
7677

78+
func (cfs *CloudFormationStack) Filter() error {
79+
if *cfs.stack.Description == "DO NOT MODIFY THIS STACK! This stack is managed by Config Conformance Packs." {
80+
return fmt.Errorf("stack is managed by Config Conformance Packs")
81+
}
82+
return nil
83+
}
84+
7785
func (cfs *CloudFormationStack) Settings(setting *settings.Setting) {
7886
cfs.settings = setting
7987
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package resources
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go/service/configservice"
7+
8+
"github.com/ekristen/libnuke/pkg/registry"
9+
"github.com/ekristen/libnuke/pkg/resource"
10+
"github.com/ekristen/libnuke/pkg/types"
11+
12+
"github.com/ekristen/aws-nuke/pkg/nuke"
13+
)
14+
15+
const ConfigServiceConformancePackResource = "ConfigServiceConformancePack"
16+
17+
func init() {
18+
registry.Register(&registry.Registration{
19+
Name: ConfigServiceConformancePackResource,
20+
Scope: nuke.Account,
21+
Lister: &ConfigServiceConformancePackLister{},
22+
})
23+
}
24+
25+
type ConfigServiceConformancePackLister struct{}
26+
27+
func (l *ConfigServiceConformancePackLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
28+
opts := o.(*nuke.ListerOpts)
29+
svc := configservice.New(opts.Session)
30+
var resources []resource.Resource
31+
32+
var nextToken *string
33+
34+
for {
35+
res, err := svc.DescribeConformancePacks(&configservice.DescribeConformancePacksInput{
36+
NextToken: nextToken,
37+
})
38+
if err != nil {
39+
return nil, err
40+
}
41+
42+
for _, p := range res.ConformancePackDetails {
43+
resources = append(resources, &ConfigServiceConformancePack{
44+
svc: svc,
45+
id: p.ConformancePackId,
46+
name: p.ConformancePackName,
47+
})
48+
}
49+
50+
if res.NextToken == nil {
51+
break
52+
}
53+
54+
nextToken = res.NextToken
55+
}
56+
57+
return resources, nil
58+
}
59+
60+
type ConfigServiceConformancePack struct {
61+
svc *configservice.ConfigService
62+
id *string
63+
name *string
64+
}
65+
66+
func (r *ConfigServiceConformancePack) Remove(_ context.Context) error {
67+
_, err := r.svc.DeleteConformancePack(&configservice.DeleteConformancePackInput{
68+
ConformancePackName: r.name,
69+
})
70+
return err
71+
}
72+
73+
func (r *ConfigServiceConformancePack) Properties() types.Properties {
74+
props := types.NewProperties()
75+
props.Set("ID", r.id)
76+
props.Set("Name", r.name)
77+
return props
78+
}
79+
80+
func (r *ConfigServiceConformancePack) String() string {
81+
return *r.id
82+
}

0 commit comments

Comments
 (0)