Skip to content
Open
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/textract v1.40.22
github.com/aws/aws-sdk-go-v2/service/timestreaminfluxdb v1.20.6
github.com/aws/aws-sdk-go-v2/service/transfer v1.55.5
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.22.2
github.com/aws/smithy-go v1.27.2
github.com/ekristen/libnuke v1.3.0
github.com/fatih/color v1.19.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ github.com/aws/aws-sdk-go-v2/service/timestreaminfluxdb v1.20.6 h1:Cjn8vN7HcVipJ
github.com/aws/aws-sdk-go-v2/service/timestreaminfluxdb v1.20.6/go.mod h1:obaEZourm+uDHiBOTkxJ1y/RF1WU8GtywWBee2hxm6k=
github.com/aws/aws-sdk-go-v2/service/transfer v1.55.5 h1:3CgAcyZciL7KG/8LCEWWoMJfZvgZV2xUzjtNGDlaBVQ=
github.com/aws/aws-sdk-go-v2/service/transfer v1.55.5/go.mod h1:NJBUE6GjnjqSvexXpU0pj/2w+VEhRk5XPL5rRZpj7bI=
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.22.2 h1:q9xVCezxBqFAv/sJakd63MZ564MxOY8CDfWuiih9awM=
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.22.2/go.mod h1:iMZnTuSYmfTgpqnzEni1JqeO0Ar/ZItPumptLBMb8/A=
github.com/aws/smithy-go v1.27.2 h1:y9NPmSE6am6LjEFPfqHqG/jJk7AauQvhCJONKh7kpzk=
github.com/aws/smithy-go v1.27.2/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
Expand Down
111 changes: 111 additions & 0 deletions resources/vpclattice-resource-configuration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package resources

import (
"context"
"fmt"
"time"

"github.com/aws/aws-sdk-go-v2/service/vpclattice"
vpclatticeTypes "github.com/aws/aws-sdk-go-v2/service/vpclattice/types"

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

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

const VPCLatticeResourceConfigurationResource = "VPCLatticeResourceConfiguration"

func init() {
registry.Register(&registry.Registration{
Name: VPCLatticeResourceConfigurationResource,
Scope: nuke.Account,
Resource: &VPCLatticeResourceConfiguration{},
Lister: &VPCLatticeResourceConfigurationLister{},
DependsOn: []string{
"VPCLatticeServiceNetworkResourceAssociation",
},
})
}

type VPCLatticeResourceConfigurationLister struct{}

func (l *VPCLatticeResourceConfigurationLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)
svc := vpclattice.NewFromConfig(*opts.Config)
var resources []resource.Resource

params := &vpclattice.ListResourceConfigurationsInput{}
paginator := vpclattice.NewListResourceConfigurationsPaginator(svc, params)

for paginator.HasMorePages() {
resp, err := paginator.NextPage(ctx)
if err != nil {
return nil, err
}

for i := range resp.Items {
tagResp, err := svc.ListTagsForResource(ctx, &vpclattice.ListTagsForResourceInput{
ResourceArn: resp.Items[i].Arn,
})
if err != nil {
return nil, err
}

resources = append(resources, &VPCLatticeResourceConfiguration{
svc: svc,
ID: resp.Items[i].Id,
Name: resp.Items[i].Name,
ARN: resp.Items[i].Arn,
Status: string(resp.Items[i].Status),
Type: string(resp.Items[i].Type),
AmazonManaged: resp.Items[i].AmazonManaged,
CreatedAt: resp.Items[i].CreatedAt,
Tags: tagResp.Tags,
})
}
}

return resources, nil
}

type VPCLatticeResourceConfiguration struct {
svc *vpclattice.Client
ID *string
Name *string
ARN *string
Status string
Type string
AmazonManaged *bool
CreatedAt *time.Time
Tags map[string]string
}

func (r *VPCLatticeResourceConfiguration) Filter() error {
if r.AmazonManaged != nil && *r.AmazonManaged {
return fmt.Errorf("cannot delete Amazon managed resource")
}
switch vpclatticeTypes.ResourceConfigurationStatus(r.Status) {
case vpclatticeTypes.ResourceConfigurationStatusDeleteInProgress,
vpclatticeTypes.ResourceConfigurationStatusCreateInProgress,
vpclatticeTypes.ResourceConfigurationStatusUpdateInProgress:
return fmt.Errorf("resource configuration is in %s state", r.Status)
}
return nil
}

func (r *VPCLatticeResourceConfiguration) Remove(ctx context.Context) error {
_, err := r.svc.DeleteResourceConfiguration(ctx, &vpclattice.DeleteResourceConfigurationInput{
ResourceConfigurationIdentifier: r.ID,
})
return err
}

func (r *VPCLatticeResourceConfiguration) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *VPCLatticeResourceConfiguration) String() string {
return *r.Name
}
106 changes: 106 additions & 0 deletions resources/vpclattice-resource-gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package resources

import (
"context"
"fmt"
"time"

"github.com/aws/aws-sdk-go-v2/service/vpclattice"
vpclatticeTypes "github.com/aws/aws-sdk-go-v2/service/vpclattice/types"

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

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

const VPCLatticeResourceGatewayResource = "VPCLatticeResourceGateway"

func init() {
registry.Register(&registry.Registration{
Name: VPCLatticeResourceGatewayResource,
Scope: nuke.Account,
Resource: &VPCLatticeResourceGateway{},
Lister: &VPCLatticeResourceGatewayLister{},
DependsOn: []string{
"VPCLatticeResourceConfiguration",
},
})
}

type VPCLatticeResourceGatewayLister struct{}

func (l *VPCLatticeResourceGatewayLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)
svc := vpclattice.NewFromConfig(*opts.Config)
var resources []resource.Resource

params := &vpclattice.ListResourceGatewaysInput{}
paginator := vpclattice.NewListResourceGatewaysPaginator(svc, params)

for paginator.HasMorePages() {
resp, err := paginator.NextPage(ctx)
if err != nil {
return nil, err
}

for i := range resp.Items {
tagResp, err := svc.ListTagsForResource(ctx, &vpclattice.ListTagsForResourceInput{
ResourceArn: resp.Items[i].Arn,
})
if err != nil {
return nil, err
}

resources = append(resources, &VPCLatticeResourceGateway{
svc: svc,
ID: resp.Items[i].Id,
Name: resp.Items[i].Name,
ARN: resp.Items[i].Arn,
Status: string(resp.Items[i].Status),
IPAddressType: string(resp.Items[i].IpAddressType),
CreatedAt: resp.Items[i].CreatedAt,
Tags: tagResp.Tags,
})
}
}

return resources, nil
}

type VPCLatticeResourceGateway struct {
svc *vpclattice.Client
ID *string
Name *string
ARN *string
Status string
IPAddressType string
CreatedAt *time.Time
Tags map[string]string
}

func (r *VPCLatticeResourceGateway) Filter() error {
switch vpclatticeTypes.ResourceGatewayStatus(r.Status) {
case vpclatticeTypes.ResourceGatewayStatusDeleteInProgress,
vpclatticeTypes.ResourceGatewayStatusCreateInProgress,
vpclatticeTypes.ResourceGatewayStatusUpdateInProgress:
return fmt.Errorf("resource gateway is in %s state", r.Status)
}
return nil
}

func (r *VPCLatticeResourceGateway) Remove(ctx context.Context) error {
_, err := r.svc.DeleteResourceGateway(ctx, &vpclattice.DeleteResourceGatewayInput{
ResourceGatewayIdentifier: r.ID,
})
return err
}

func (r *VPCLatticeResourceGateway) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *VPCLatticeResourceGateway) String() string {
return *r.Name
}
107 changes: 107 additions & 0 deletions resources/vpclattice-service-network-resource-association.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package resources

import (
"context"
"fmt"
"time"

"github.com/aws/aws-sdk-go-v2/service/vpclattice"
vpclatticeTypes "github.com/aws/aws-sdk-go-v2/service/vpclattice/types"

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

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

const VPCLatticeServiceNetworkResourceAssociationResource = "VPCLatticeServiceNetworkResourceAssociation"

func init() {
registry.Register(&registry.Registration{
Name: VPCLatticeServiceNetworkResourceAssociationResource,
Scope: nuke.Account,
Resource: &VPCLatticeServiceNetworkResourceAssociation{},
Lister: &VPCLatticeServiceNetworkResourceAssociationLister{},
})
}

type VPCLatticeServiceNetworkResourceAssociationLister struct{}

func (l *VPCLatticeServiceNetworkResourceAssociationLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)
svc := vpclattice.NewFromConfig(*opts.Config)
var resources []resource.Resource

params := &vpclattice.ListServiceNetworkResourceAssociationsInput{}
paginator := vpclattice.NewListServiceNetworkResourceAssociationsPaginator(svc, params)

for paginator.HasMorePages() {
resp, err := paginator.NextPage(ctx)
if err != nil {
return nil, err
}

for i := range resp.Items {
tagResp, err := svc.ListTagsForResource(ctx, &vpclattice.ListTagsForResourceInput{
ResourceArn: resp.Items[i].Arn,
})
if err != nil {
return nil, err
}

resources = append(resources, &VPCLatticeServiceNetworkResourceAssociation{
svc: svc,
ID: resp.Items[i].Id,
ARN: resp.Items[i].Arn,
Status: string(resp.Items[i].Status),
ServiceNetworkName: resp.Items[i].ServiceNetworkName,
ResourceConfigurationName: resp.Items[i].ResourceConfigurationName,
IsManagedAssociation: resp.Items[i].IsManagedAssociation,
CreatedAt: resp.Items[i].CreatedAt,
Tags: tagResp.Tags,
})
}
}

return resources, nil
}

type VPCLatticeServiceNetworkResourceAssociation struct {
svc *vpclattice.Client
ID *string
ARN *string
Status string
ServiceNetworkName *string
ResourceConfigurationName *string
IsManagedAssociation *bool
CreatedAt *time.Time
Tags map[string]string
}

func (r *VPCLatticeServiceNetworkResourceAssociation) Filter() error {
if r.IsManagedAssociation != nil && *r.IsManagedAssociation {
return fmt.Errorf("cannot delete managed association")
}
switch vpclatticeTypes.ServiceNetworkResourceAssociationStatus(r.Status) {
case vpclatticeTypes.ServiceNetworkResourceAssociationStatusDeleteInProgress,
vpclatticeTypes.ServiceNetworkResourceAssociationStatusCreateInProgress:
return fmt.Errorf("service network resource association is in %s state", r.Status)
}
return nil
}

func (r *VPCLatticeServiceNetworkResourceAssociation) Remove(ctx context.Context) error {
_, err := r.svc.DeleteServiceNetworkResourceAssociation(ctx, &vpclattice.DeleteServiceNetworkResourceAssociationInput{
ServiceNetworkResourceAssociationIdentifier: r.ID,
})
return err
}

func (r *VPCLatticeServiceNetworkResourceAssociation) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *VPCLatticeServiceNetworkResourceAssociation) String() string {
return *r.ID
}