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

Commit

Permalink
Merge pull request #422 from rebuy-de/introduce-feature-flags
Browse files Browse the repository at this point in the history
introduce feature flags
  • Loading branch information
svenwltr authored Oct 25, 2019
2 parents 9344665 + 64d3fff commit 498111e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,21 @@ If an exclude is used, then all its resource types will not be deleted.
aws-nuke resource-types
```


### Feature Flags

There are some features, which are quite opinionated. To make those work for
everyone, *aws-nuke* has flags to manually enable those features. These can be
configured on the root-level of the config, like this:

```yaml
---
feature-flags:
disable-deletion-protection:
RDSInstance: true
```
### Filtering Resources
It is possible to filter this is important for not deleting the current user
Expand Down
5 changes: 5 additions & 0 deletions cmd/nuke.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func (n *Nuke) Scan() error {

items := Scan(region, resourceTypes)
for item := range items {
ffGetter, ok := item.Resource.(resources.FeatureFlagGetter)
if ok {
ffGetter.FeatureFlags(n.Config.FeatureFlags)
}

queue = append(queue, item)
err := n.Filter(item)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
7 changes: 7 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ type Nuke struct {
Accounts map[string]Account `yaml:"accounts"`
ResourceTypes ResourceTypes `yaml:"resource-types"`
Presets map[string]PresetDefinitions `yaml:"presets"`
FeatureFlags FeatureFlags `yaml:"feature-flags"`
}

type FeatureFlags struct {
DisableDeletionProtection struct {
RDSInstance bool `yaml:"RDSInstance"`
} `yaml:"disable-deletion-protection"`
}

type PresetDefinitions struct {
Expand Down
6 changes: 6 additions & 0 deletions resources/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/rebuy-de/aws-nuke/pkg/config"
"github.com/rebuy-de/aws-nuke/pkg/types"
)

Expand All @@ -30,6 +31,11 @@ type ResourcePropertyGetter interface {
Properties() types.Properties
}

type FeatureFlagGetter interface {
Resource
FeatureFlags(config.FeatureFlags)
}

var resourceListers = make(ResourceListers)

func register(name string, lister ResourceLister) {
Expand Down
39 changes: 25 additions & 14 deletions resources/rds-instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/rebuy-de/aws-nuke/pkg/config"
"github.com/rebuy-de/aws-nuke/pkg/types"
)

type RDSInstance struct {
svc *rds.RDS
id string
deletionProtection bool
tags []*rds.Tag
svc *rds.RDS
instance *rds.DBInstance
tags []*rds.Tag

featureFlags config.FeatureFlags
}

func init() {
Expand All @@ -38,20 +40,23 @@ func ListRDSInstances(sess *session.Session) ([]Resource, error) {
}

resources = append(resources, &RDSInstance{
svc: svc,
id: *instance.DBInstanceIdentifier,
deletionProtection: *instance.DeletionProtection,
tags: tags.TagList,
svc: svc,
instance: instance,
tags: tags.TagList,
})
}

return resources, nil
}

func (i *RDSInstance) FeatureFlags(ff config.FeatureFlags) {
i.featureFlags = ff
}

func (i *RDSInstance) Remove() error {
if (i.deletionProtection) {
if aws.BoolValue(i.instance.DeletionProtection) && i.featureFlags.DisableDeletionProtection.RDSInstance {
modifyParams := &rds.ModifyDBInstanceInput{
DBInstanceIdentifier: &i.id,
DBInstanceIdentifier: i.instance.DBInstanceIdentifier,
DeletionProtection: aws.Bool(false),
}
_, err := i.svc.ModifyDBInstance(modifyParams)
Expand All @@ -61,7 +66,7 @@ func (i *RDSInstance) Remove() error {
}

params := &rds.DeleteDBInstanceInput{
DBInstanceIdentifier: &i.id,
DBInstanceIdentifier: i.instance.DBInstanceIdentifier,
SkipFinalSnapshot: aws.Bool(true),
}

Expand All @@ -75,8 +80,14 @@ func (i *RDSInstance) Remove() error {

func (i *RDSInstance) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Identifier", i.id)
properties.Set("Deletion Protection", i.deletionProtection)
properties.Set("Identifier", i.instance.DBInstanceIdentifier)
properties.Set("DeletionProtection", i.instance.DeletionProtection)
properties.Set("AvailabilityZone", i.instance.AvailabilityZone)
properties.Set("InstanceClass", i.instance.DBInstanceClass)
properties.Set("Engine", i.instance.Engine)
properties.Set("EngineVersion", i.instance.EngineVersion)
properties.Set("MultiAZ", i.instance.MultiAZ)
properties.Set("PubliclyAccessible", i.instance.PubliclyAccessible)

for _, tag := range i.tags {
properties.SetTag(tag.Key, tag.Value)
Expand All @@ -86,5 +97,5 @@ func (i *RDSInstance) Properties() types.Properties {
}

func (i *RDSInstance) String() string {
return i.id
return aws.StringValue(i.instance.DBInstanceIdentifier)
}

0 comments on commit 498111e

Please sign in to comment.