Skip to content

Commit

Permalink
fix(cloud-control): properly execute cloud control resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Jan 10, 2025
1 parent c2c26b3 commit abbe053
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
20 changes: 19 additions & 1 deletion pkg/commands/nuke/nuke.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/ekristen/aws-nuke/v3/pkg/common"
"github.com/ekristen/aws-nuke/v3/pkg/config"
"github.com/ekristen/aws-nuke/v3/pkg/nuke"

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

// ConfigureCreds is a helper function to configure the awsutil.Credentials object from the cli.Context
Expand Down Expand Up @@ -138,10 +140,26 @@ func execute(c *cli.Context) error { //nolint:funlen,gocyclo
// Get any specific account level configuration
accountConfig := parsedConfig.Accounts[account.ID()]

// Get current registered resource names
resourceNames := registry.GetNames()

// Combine all the places where alternative resource types can be defined and then dynamically
// register them as a Cloud Control resource type.
altResourceTypes := types.Collection(registry.ExpandNames(n.Parameters.Alternatives))
altResourceTypes = altResourceTypes.Union(parsedConfig.ResourceTypes.GetAlternatives())
altResourceTypes = altResourceTypes.Union(accountConfig.ResourceTypes.GetAlternatives())
for _, rt := range altResourceTypes {
if slices.Contains(resourceNames, rt) {
continue
}

resources.RegisterCloudControl(rt)
}

// Resolve the resource types to be used for the nuke process based on the parameters, global configuration, and
// account level configuration.
resourceTypes := types.ResolveResourceTypes(
registry.GetNames(),
registry.GetNames(), // note: we want to re-pull the registry here due to the dynamic registration above
[]types.Collection{
registry.ExpandNames(n.Parameters.Includes),
parsedConfig.ResourceTypes.GetIncludes(),
Expand Down
42 changes: 21 additions & 21 deletions resources/cloudcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,36 @@ func init() {
// go run ./tools/list-cloudcontrol
//
// If there's a resource definition for the resource type, then there's no
// need to define it here as well, you should use the MapCloudControl func
// see ecr-public-repository.go for an example.
registerCloudControl("AWS::AppFlow::ConnectorProfile")
registerCloudControl("AWS::AppFlow::Flow")
registerCloudControl("AWS::AppRunner::Service")
registerCloudControl("AWS::ApplicationInsights::Application")
registerCloudControl("AWS::Backup::Framework")
registerCloudControl("AWS::ECR::PullThroughCacheRule")
registerCloudControl("AWS::ECR::RegistryPolicy")
registerCloudControl("AWS::ECR::ReplicationConfiguration")
registerCloudControl("AWS::MWAA::Environment")
registerCloudControl("AWS::Synthetics::Canary")
registerCloudControl("AWS::Timestream::Database")
registerCloudControl("AWS::Timestream::ScheduledQuery")
registerCloudControl("AWS::Timestream::Table")
registerCloudControl("AWS::Transfer::Workflow")
registerCloudControl("AWS::NetworkFirewall::Firewall")
registerCloudControl("AWS::NetworkFirewall::FirewallPolicy")
registerCloudControl("AWS::NetworkFirewall::RuleGroup")
// need to define it here as well, you should use the AlternativeResource
// property of the resource registration, see ecr-public-repository.go
// for an example.
RegisterCloudControl("AWS::AppFlow::ConnectorProfile")
RegisterCloudControl("AWS::AppFlow::Flow")
RegisterCloudControl("AWS::AppRunner::Service")
RegisterCloudControl("AWS::ApplicationInsights::Application")
RegisterCloudControl("AWS::Backup::Framework")
RegisterCloudControl("AWS::ECR::PullThroughCacheRule")
RegisterCloudControl("AWS::ECR::RegistryPolicy")
RegisterCloudControl("AWS::ECR::ReplicationConfiguration")
RegisterCloudControl("AWS::MWAA::Environment")
RegisterCloudControl("AWS::Synthetics::Canary")
RegisterCloudControl("AWS::Timestream::Database")
RegisterCloudControl("AWS::Timestream::ScheduledQuery")
RegisterCloudControl("AWS::Timestream::Table")
RegisterCloudControl("AWS::Transfer::Workflow")
RegisterCloudControl("AWS::NetworkFirewall::Firewall")
RegisterCloudControl("AWS::NetworkFirewall::FirewallPolicy")
RegisterCloudControl("AWS::NetworkFirewall::RuleGroup")
}

func registerCloudControl(typeName string) {
func RegisterCloudControl(typeName string) {
registry.Register(&registry.Registration{
Name: typeName,
Scope: nuke.Account,
Resource: &CloudControlResource{},
Lister: &CloudControlResourceLister{
TypeName: typeName,
},
AlternativeResource: typeName,
})
}

Expand Down

0 comments on commit abbe053

Please sign in to comment.