Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nukable check + nukable check implementation for transit gateway #635

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
orbs:
go: circleci/go@1.7.3
go: circleci/go@1.11.0

# The "sign binary" runs in a MacOS environment, so it's necessary to download GW's binaries
env: &env
Expand Down
5 changes: 3 additions & 2 deletions aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package aws
import (
"context"
"fmt"
"github.com/gruntwork-io/cloud-nuke/util"
"github.com/pterm/pterm"
"sort"
"strings"
"time"

"github.com/gruntwork-io/cloud-nuke/util"
"github.com/pterm/pterm"

commonTelemetry "github.com/gruntwork-io/go-commons/telemetry"

"github.com/gruntwork-io/cloud-nuke/config"
Expand Down
4 changes: 3 additions & 1 deletion aws/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package aws

import (
"context"
"strings"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/gruntwork-io/cloud-nuke/config"
"strings"
)

// AwsResource is an interface that represents a single AWS resource
Expand All @@ -15,6 +16,7 @@ type AwsResource interface {
MaxBatchSize() int
Nuke(identifiers []string) error
GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error)
IsNukable(string) (bool, error)
}

// AwsResources is a struct to hold multiple instances of AwsResource.
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/access_analyzer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/accessanalyzer"
Expand All @@ -12,6 +13,7 @@ import (

// AccessAnalyzer - represents all AWS secrets manager secrets that should be deleted.
type AccessAnalyzer struct {
BaseAwsResource
Client accessanalyzeriface.AccessAnalyzerAPI
Region string
AnalyzerNames []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/acm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/acm"
Expand All @@ -12,6 +13,7 @@ import (

// ACMPA - represents all ACMPA
type ACM struct {
BaseAwsResource
Client acmiface.ACMAPI
Region string
ARNs []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/acmpca_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/acmpca"
Expand All @@ -12,6 +13,7 @@ import (

// ACMPA - represents all ACMPA
type ACMPCA struct {
BaseAwsResource
Client acmpcaiface.ACMPCAAPI
Region string
ARNs []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/ami_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
Expand All @@ -12,6 +13,7 @@ import (

// AMIs - represents all user owned AMIs
type AMIs struct {
BaseAwsResource
Client ec2iface.EC2API
Region string
ImageIds []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/apigateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/apigateway"
Expand All @@ -11,6 +12,7 @@ import (
)

type ApiGateway struct {
BaseAwsResource
Client apigatewayiface.APIGatewayAPI
Region string
Ids []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/apigatewayv2_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/apigatewayv2"
Expand All @@ -11,6 +12,7 @@ import (
)

type ApiGatewayV2 struct {
BaseAwsResource
Client apigatewayv2iface.ApiGatewayV2API
Region string
Ids []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/asg_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/autoscaling"
Expand All @@ -12,6 +13,7 @@ import (

// ASGroups - represents all auto scaling groups
type ASGroups struct {
BaseAwsResource
Client autoscalingiface.AutoScalingAPI
Region string
GroupNames []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/backup_vault_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/backup"
Expand All @@ -11,6 +12,7 @@ import (
)

type BackupVault struct {
BaseAwsResource
Client backupiface.BackupAPI
Region string
Names []string
Expand Down
35 changes: 35 additions & 0 deletions aws/resources/base_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package resources

import (
"context"
"errors"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/gruntwork-io/cloud-nuke/config"
)

// BaseAwsResource This BaseAwsResource struct and its associated methods to serve as a placeholder or template for a resource
// that is not yet fully implemented within a system or framework.
// Its purpose is to provide a skeleton structure that adheres to a specific interface or contract expected by the
// system without containing the actual implementation details.
type BaseAwsResource struct{}

func (umpl *BaseAwsResource) Init(_ *session.Session) {}
func (umpl *BaseAwsResource) ResourceName() string {
return "not implemented: ResourceName"
}
func (umpl *BaseAwsResource) ResourceIdentifiers() []string {
return nil
}
func (umpl *BaseAwsResource) MaxBatchSize() int {
return 0
}
func (umpl *BaseAwsResource) Nuke(_ []string) error {
return errors.New("not implemented: Nuke")
}
func (umpl *BaseAwsResource) GetAndSetIdentifiers(_ context.Context, _ config.Config) ([]string, error) {
return nil, errors.New("not implemented: GetAndSetIdentifiers")
}
func (umpl *BaseAwsResource) IsNukable(_ string) (bool, error) {
return false, errors.New("not implemented yet.")
}
2 changes: 2 additions & 0 deletions aws/resources/cloudtrail_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudtrail"
Expand All @@ -12,6 +13,7 @@ import (

// CloudWatchLogGroup - represents all ec2 instances
type CloudtrailTrail struct {
BaseAwsResource
Client cloudtrailiface.CloudTrailAPI
Region string
Arns []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/cloudwatch_alarm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
Expand All @@ -12,6 +13,7 @@ import (

// CloudWatchAlarms - represents all CloudWatchAlarms that should be deleted.
type CloudWatchAlarms struct {
BaseAwsResource
Client cloudwatchiface.CloudWatchAPI
Region string
AlarmNames []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/cloudwatch_dashboard_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
Expand All @@ -12,6 +13,7 @@ import (

// CloudWatchDashboards - represents all CloudWatch Dashboards that should be deleted.
type CloudWatchDashboards struct {
BaseAwsResource
Client cloudwatchiface.CloudWatchAPI
Region string
DashboardNames []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/cloudwatch_loggroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
Expand All @@ -12,6 +13,7 @@ import (

// CloudWatchLogGroup - represents all ec2 instances
type CloudWatchLogGroups struct {
BaseAwsResource
Client cloudwatchlogsiface.CloudWatchLogsAPI
Region string
Names []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/codedeploy_application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codedeploy"
Expand All @@ -12,6 +13,7 @@ import (

// CodeDeployApplications - represents all codedeploy applications
type CodeDeployApplications struct {
BaseAwsResource
Client codedeployiface.CodeDeployAPI
Region string
AppNames []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/config_recorder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/configservice"
Expand All @@ -11,6 +12,7 @@ import (
)

type ConfigServiceRecorders struct {
BaseAwsResource
Client configserviceiface.ConfigServiceAPI
Region string
RecorderNames []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/config_service_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/configservice"
Expand All @@ -11,6 +12,7 @@ import (
)

type ConfigServiceRule struct {
BaseAwsResource
Client configserviceiface.ConfigServiceAPI
Region string
RuleNames []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/dynamodb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
Expand All @@ -11,6 +12,7 @@ import (
)

type DynamoDB struct {
BaseAwsResource
Client dynamodbiface.DynamoDBAPI
Region string
DynamoTableNames []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/ebs_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
Expand All @@ -12,6 +13,7 @@ import (

// EBSVolumes - represents all ebs volumes
type EBSVolumes struct {
BaseAwsResource
Client ec2iface.EC2API
Region string
VolumeIds []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/ec2_dedicated_host_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
Expand All @@ -12,6 +13,7 @@ import (

// EC2DedicatedHosts - represents all host allocation IDs
type EC2DedicatedHosts struct {
BaseAwsResource
Client ec2iface.EC2API
Region string
HostIds []string
Expand Down
2 changes: 2 additions & 0 deletions aws/resources/ec2_dhcp_option_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"

awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
Expand All @@ -11,6 +12,7 @@ import (
)

type EC2DhcpOption struct {
BaseAwsResource
Client ec2iface.EC2API
Region string
VPCIds []string
Expand Down
1 change: 1 addition & 0 deletions aws/resources/ec2_ipam_byoasn_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

// IPAM Byoasn- represents all IPAMs
type EC2IPAMByoasn struct {
BaseAwsResource
Client ec2iface.EC2API
Region string
Pools []string
Expand Down
1 change: 1 addition & 0 deletions aws/resources/ec2_ipam_custom_allocation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

// IPAM Byoasn- represents all IPAMs
type EC2IPAMCustomAllocation struct {
BaseAwsResource
Client ec2iface.EC2API
Region string
Allocations []string
Expand Down
Loading