From b190ddf5c63a581a2579eb0597396ded71c58db4 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Thu, 26 Dec 2024 14:00:33 -0700 Subject: [PATCH 1/2] feat: expand resource names using globs --- pkg/commands/list/list.go | 10 ++++++---- pkg/commands/nuke/nuke.go | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/commands/list/list.go b/pkg/commands/list/list.go index 7f4a580b..7bfa0633 100644 --- a/pkg/commands/list/list.go +++ b/pkg/commands/list/list.go @@ -1,7 +1,6 @@ package list import ( - "sort" "strings" "github.com/fatih/color" @@ -15,9 +14,12 @@ import ( ) func execute(c *cli.Context) error { - ls := registry.GetNames() - - sort.Strings(ls) + var ls []string + if c.Args().Len() > 0 { + ls = registry.ExpandNames(c.Args().Slice()) + } else { + ls = registry.GetNames() + } for _, name := range ls { if strings.HasPrefix(name, "AWS::") { diff --git a/pkg/commands/nuke/nuke.go b/pkg/commands/nuke/nuke.go index 69ec1b90..63d21954 100644 --- a/pkg/commands/nuke/nuke.go +++ b/pkg/commands/nuke/nuke.go @@ -141,17 +141,17 @@ func execute(c *cli.Context) error { //nolint:funlen,gocyclo resourceTypes := types.ResolveResourceTypes( registry.GetNames(), []types.Collection{ - n.Parameters.Includes, + registry.ExpandNames(n.Parameters.Includes), parsedConfig.ResourceTypes.GetIncludes(), accountConfig.ResourceTypes.GetIncludes(), }, []types.Collection{ - n.Parameters.Excludes, + registry.ExpandNames(n.Parameters.Excludes), parsedConfig.ResourceTypes.Excludes, accountConfig.ResourceTypes.Excludes, }, []types.Collection{ - n.Parameters.Alternatives, + registry.ExpandNames(n.Parameters.Alternatives), parsedConfig.ResourceTypes.GetAlternatives(), accountConfig.ResourceTypes.GetAlternatives(), }, From 9876f61f60d24247e77cb6ec162d779879a7beb8 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Thu, 26 Dec 2024 14:09:22 -0700 Subject: [PATCH 2/2] docs: add docs about name expansion --- docs/features/name-expansion.md | 51 +++++++++++++++++++++++++++++++++ docs/features/overview.md | 2 ++ docs/index.md | 1 + mkdocs.yml | 1 + 4 files changed, 55 insertions(+) create mode 100644 docs/features/name-expansion.md diff --git a/docs/features/name-expansion.md b/docs/features/name-expansion.md new file mode 100644 index 00000000..1e142357 --- /dev/null +++ b/docs/features/name-expansion.md @@ -0,0 +1,51 @@ +# Name Expansion + +This allows you to use wildcards in the resource names to match multiple resources. This is primarily useful when you +want to target a group of resource type for either inclusion or exclusion. + +Resource Name expansion is valid for use in the following areas: + +!!! warning +This feature is currently **NOT** supported in filters. + +- cli includes/excludes +- config resource types includes/excludes +- account resource types includes/excludes + +## Examples + +### CLI + +```console +aws-nuke run --config config.yaml --include "Cognito*" +``` + +This can also be used with `resource-types` subcommand to see what resource types are available, and you can specify +multiple wildcard arguments. + +```console +aws-nuke resource-types "Cognito*" "IAM*" +``` + +### Config + +```yaml +resource-types: + includes: + - "Cognito*" + excludes: + - "OpsWorks*" +``` + +### Account Config + +```yaml +accounts: + '012345678912': + resource-types: + includes: + - "Cognito*" + excludes: + - "OpsWorks*" +``` + diff --git a/docs/features/overview.md b/docs/features/overview.md index 95aa6a6d..305fb16e 100644 --- a/docs/features/overview.md +++ b/docs/features/overview.md @@ -6,6 +6,8 @@ Some of the new features include: - [Run Against All Enabled Regions](enabled-regions.md) - [Bypass Alias Check - Allow the skip of an alias on an account](bypass-alias-check.md) - [Signed Binaries](signed-binaries.md) +- [Filter Groups (Experimental)](filter-groups.md) +- [Name Expansion](name-expansion.md) Additionally, there are a few new sub commands to the tool to help with setup and debugging purposes: diff --git a/docs/index.md b/docs/index.md index 9f6499bc..6930e3b1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -18,6 +18,7 @@ This is not a comprehensive list, but here are some of the highlights: * New Feature: [Run Against All Enabled Regions](features/enabled-regions.md) * New Feature: [Bypass Alias Check - Allow the skip of an alias on an account](features/bypass-alias-check.md) * New Feature: [Filter Groups (Experimental)](features/filter-groups.md) +* New Feature: [Name Expansion](features/name-expansion.md) * Breaking Change: `root` command no longer triggers the run, must use subcommand `run` (alias: `nuke`) * Completely rewrote the core of the tool as a dedicated library [libnuke](https://github.com/ekristen/libnuke) * This library has over 95% test coverage which makes iteration and new features easier to implement. diff --git a/mkdocs.yml b/mkdocs.yml index af4bdb8a..668c7bf7 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -79,6 +79,7 @@ nav: - Global Filters: features/global-filters.md - Filter Groups: features/filter-groups.md - Enabled Regions: features/enabled-regions.md + - Name Expansion: features/name-expansion.md - Signed Binaries: features/signed-binaries.md - CLI: - Usage: cli-usage.md