resources

package
v0.0.0-...-59dbd6c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NameTagKey = "Name"
)

Variables

Non-regional AWS resource types, in dependency order

AWS resource types known to this script, in dependency order.

Functions

func CleanAll

func CleanAll(opts Options, region string) error

CleanAll cleans all of the resources for all of the regions visible to the provided AWS session.

func IsManagedS3Bucket

func IsManagedS3Bucket(opts Options, region string, bucketName string) (bool, error)

IsManagedS3Bucket checks whether the bucket should be managed by janitor.

Types

type Addresses

type Addresses struct{}

func (Addresses) ListAll

func (Addresses) ListAll(opts Options) (*Set, error)

func (Addresses) MarkAndSweep

func (Addresses) MarkAndSweep(opts Options, set *Set) error

type AutoScalingGroups

type AutoScalingGroups struct{}

func (AutoScalingGroups) ListAll

func (AutoScalingGroups) ListAll(opts Options) (*Set, error)

func (AutoScalingGroups) MarkAndSweep

func (AutoScalingGroups) MarkAndSweep(opts Options, set *Set) error

type ClassicLoadBalancers

type ClassicLoadBalancers struct{}

func (ClassicLoadBalancers) ListAll

func (ClassicLoadBalancers) ListAll(opts Options) (*Set, error)

func (ClassicLoadBalancers) MarkAndSweep

func (ClassicLoadBalancers) MarkAndSweep(opts Options, set *Set) error

type CloudFormationStacks

type CloudFormationStacks struct{}

Cloud Formation Stacks

func (CloudFormationStacks) ListAll

func (CloudFormationStacks) ListAll(opts Options) (*Set, error)

func (CloudFormationStacks) MarkAndSweep

func (cfs CloudFormationStacks) MarkAndSweep(opts Options, set *Set) error

type DHCPOptions

type DHCPOptions struct{}

DHCPOptions: https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#EC2.DescribeDhcpOptions

func (DHCPOptions) ListAll

func (DHCPOptions) ListAll(opts Options) (*Set, error)

func (DHCPOptions) MarkAndSweep

func (DHCPOptions) MarkAndSweep(opts Options, set *Set) error

type EKS

type EKS struct{}

func (EKS) ListAll

func (e EKS) ListAll(opts Options) (*Set, error)

func (EKS) MarkAndSweep

func (e EKS) MarkAndSweep(opts Options, set *Set) error

type ElasticFileSystems

type ElasticFileSystems struct{}

func (ElasticFileSystems) ListAll

func (ElasticFileSystems) ListAll(opts Options) (*Set, error)

func (ElasticFileSystems) MarkAndSweep

func (ElasticFileSystems) MarkAndSweep(opts Options, set *Set) error

type IAMInstanceProfiles

type IAMInstanceProfiles struct{}

IAM Instance Profiles

func (IAMInstanceProfiles) ListAll

func (IAMInstanceProfiles) ListAll(opts Options) (*Set, error)

func (IAMInstanceProfiles) MarkAndSweep

func (IAMInstanceProfiles) MarkAndSweep(opts Options, set *Set) error

type IAMOIDCProviders

type IAMOIDCProviders struct{}

func (IAMOIDCProviders) ListAll

func (IAMOIDCProviders) ListAll(opts Options) (*Set, error)

func (IAMOIDCProviders) MarkAndSweep

func (IAMOIDCProviders) MarkAndSweep(opts Options, set *Set) error

type IAMRoles

type IAMRoles struct{}

func (IAMRoles) ListAll

func (IAMRoles) ListAll(opts Options) (*Set, error)

func (IAMRoles) MarkAndSweep

func (IAMRoles) MarkAndSweep(opts Options, set *Set) error

type Instances

type Instances struct{}

func (Instances) ListAll

func (Instances) ListAll(opts Options) (*Set, error)

func (Instances) MarkAndSweep

func (Instances) MarkAndSweep(opts Options, set *Set) error

type Interface

type Interface interface {
	// ARN returns the AWS ARN for the resource
	// (c.f. http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html). This
	// is only used for uniqueness in the Mark set, but ARNs are
	// intended to be globally unique across regions and accounts, so
	// that works.
	ARN() string

	// ResourceKey() returns a per-resource key, because ARNs might conflict if two objects
	// with the same name are created at different times (e.g. IAM roles)
	ResourceKey() string
}

type InternetGateways

type InternetGateways struct{}

func (InternetGateways) ListAll

func (InternetGateways) ListAll(opts Options) (*Set, error)

func (InternetGateways) MarkAndSweep

func (InternetGateways) MarkAndSweep(opts Options, set *Set) error

type KeyPairs

type KeyPairs struct{}

func (KeyPairs) ListAll

func (KeyPairs) ListAll(opts Options) (*Set, error)

func (KeyPairs) MarkAndSweep

func (KeyPairs) MarkAndSweep(opts Options, set *Set) error

MarkAndSweep looks at the provided set, and removes resources older than its TTL that have been previously tagged.

type LaunchConfigurations

type LaunchConfigurations struct{}

LaunchConfigurations: http://docs.aws.amazon.com/sdk-for-go/api/service/autoscaling/#AutoScaling.DescribeLaunchConfigurations

func (LaunchConfigurations) ListAll

func (LaunchConfigurations) ListAll(opts Options) (*Set, error)

func (LaunchConfigurations) MarkAndSweep

func (LaunchConfigurations) MarkAndSweep(opts Options, set *Set) error

type LaunchTemplates

type LaunchTemplates struct{}

LaunchTemplates https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#EC2.DescribeLaunchTemplates

func (LaunchTemplates) ListAll

func (LaunchTemplates) ListAll(opts Options) (*Set, error)

func (LaunchTemplates) MarkAndSweep

func (LaunchTemplates) MarkAndSweep(opts Options, set *Set) error

type LoadBalancers

type LoadBalancers struct{}

func (LoadBalancers) ListAll

func (LoadBalancers) ListAll(opts Options) (*Set, error)

func (LoadBalancers) MarkAndSweep

func (LoadBalancers) MarkAndSweep(opts Options, set *Set) error

type NATGateway

type NATGateway struct{}

NATGateway is a VPC component: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html

func (NATGateway) ListAll

func (NATGateway) ListAll(opts Options) (*Set, error)

ListAll populates a set will all available NATGateway resources.

func (NATGateway) MarkAndSweep

func (NATGateway) MarkAndSweep(opts Options, set *Set) error

MarkAndSweep looks at the provided set, and removes resources older than its TTL that have been previously tagged.

type NetworkInterfaces

type NetworkInterfaces struct{}

func (NetworkInterfaces) ListAll

func (NetworkInterfaces) ListAll(opts Options) (*Set, error)

func (NetworkInterfaces) MarkAndSweep

func (NetworkInterfaces) MarkAndSweep(opts Options, set *Set) error

type Options

type Options struct {
	Session *session.Session `json:"-"`
	Account string
	Region  string

	// Only resources which contain all IncludeTags will be considered for cleanup.
	IncludeTags TagMatcher
	// Any resources with at least one tag in ExcludeTags will be excluded from cleanup.
	// ExcludeTags takes precedence over IncludeTags - i.e. a resource that matches both
	// will be excluded.
	ExcludeTags TagMatcher

	// If set, any resources with a tag matching this key can override the global TTL (unless the global TTL is 0).
	// The value of the tag must be a valid Go time.Duration string.
	TTLTagKey string

	// Whether to actually delete resources, or just report what would be deleted.
	DryRun bool

	// If true, clean target groups.
	EnableTargetGroupClean bool

	// If true, clean key pairs.
	EnableKeyPairsClean bool

	// If true, clean VPC endpoints.
	EnableVPCEndpointsClean bool

	// If true, skip managed zone check and managed resource name check.
	SkipRoute53ManagementCheck bool

	// If true, clean DNS zones.
	EnableDNSZoneClean bool

	// If true, clean S3 Buckets.
	EnableS3BucketsClean bool

	// Resource record set types that shoud not be deleted.
	SkipResourceRecordSetTypes map[string]bool
}

Options holds parameters for resource functions.

func (Options) ManagedPerTags

func (opts Options) ManagedPerTags(tags Tags) bool

ManagedPerTags returns whether the given list of tags is matched by all IncludeTags and no ExcludeTags.

type Route53ResourceRecordSets

type Route53ResourceRecordSets struct{}

func (Route53ResourceRecordSets) ListAll

func (Route53ResourceRecordSets) ListAll(opts Options) (*Set, error)

func (Route53ResourceRecordSets) MarkAndSweep

func (rrs Route53ResourceRecordSets) MarkAndSweep(opts Options, set *Set) error

type RouteTables

type RouteTables struct{}

func (RouteTables) ListAll

func (RouteTables) ListAll(opts Options) (*Set, error)

func (RouteTables) MarkAndSweep

func (RouteTables) MarkAndSweep(opts Options, set *Set) error

type S3Bucket

type S3Bucket struct{}

func (S3Bucket) ListAll

func (S3Bucket) ListAll(opts Options) (*Set, error)

func (S3Bucket) MarkAndSweep

func (S3Bucket) MarkAndSweep(opts Options, set *Set) error

type SQSQueues

type SQSQueues struct{}

func (SQSQueues) ListAll

func (SQSQueues) ListAll(opts Options) (*Set, error)

func (SQSQueues) MarkAndSweep

func (SQSQueues) MarkAndSweep(opts Options, set *Set) error

type SecurityGroups

type SecurityGroups struct{}

SecurityGroups: https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#EC2.DescribeSecurityGroups

func (SecurityGroups) ListAll

func (SecurityGroups) ListAll(opts Options) (*Set, error)

func (SecurityGroups) MarkAndSweep

func (SecurityGroups) MarkAndSweep(opts Options, set *Set) error

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set keeps track of the first time we saw a particular ARN, and the global TTL. See Mark() for more details.

func LoadSet

func LoadSet(sess *session.Session, p *s3path.Path, ttl time.Duration) (*Set, error)

func NewSet

func NewSet(ttl time.Duration) *Set

func (*Set) GetARNs

func (s *Set) GetARNs() []string

func (*Set) Mark

func (s *Set) Mark(opts Options, r Interface, created *time.Time, tags Tags) bool

Mark marks a particular resource as currently present, records when it was created or first seen, and advises on whether it should be deleted.

When determining whether a resource should be deleted, first the options for IncludeTags and ExcludeTags are applied against the provided tags. If the resource should be managed per tags, then the TTL is evaluated. Note that if the TTLTagKey option is set, the resource has a tag matching this key, and the global TTL is not set to 0, then the TTL duration in this tag's value will be used for this resource.

If Mark(r) returns true, the resource is managed per tags, and the TTL has expired for r and it should be deleted. If the created time is not provided, the current time is used instead.

func (*Set) MarkComplete

func (s *Set) MarkComplete() int

MarkComplete figures out which ARNs were in previous passes but not this one, and eliminates them. It should only be run after all resources have been marked.

func (*Set) Save

func (s *Set) Save(sess *session.Session, p *s3path.Path) error

type Snapshots

type Snapshots struct{}

func (Snapshots) ListAll

func (Snapshots) ListAll(opts Options) (*Set, error)

func (Snapshots) MarkAndSweep

func (Snapshots) MarkAndSweep(opts Options, set *Set) error

type Subnets

type Subnets struct{}

Subnets: https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#EC2.DescribeSubnets

func (Subnets) ListAll

func (Subnets) ListAll(opts Options) (*Set, error)

func (Subnets) MarkAndSweep

func (Subnets) MarkAndSweep(opts Options, set *Set) error

type TagMatcher

type TagMatcher map[string]sets.String

TagMatcher maps keys to valid values. An empty set of values will result in matching tags with any value.

func TagMatcherForTags

func TagMatcherForTags(tags []string) (TagMatcher, error)

TagMatcherForTags creates a new TagMatcher for the given list of tags provided in key=value format. If "=value" is not provided, then the TagMatcher will match any value for that key. (If the value is empty, only an empty tag value matches.)

func (TagMatcher) Matches

func (tm TagMatcher) Matches(key, value string) bool

type Tags

type Tags map[string]string

func (Tags) Add

func (tags Tags) Add(key *string, value *string)

type TargetGroups

type TargetGroups struct{}

func (TargetGroups) ListAll

func (TargetGroups) ListAll(opts Options) (*Set, error)

func (TargetGroups) MarkAndSweep

func (TargetGroups) MarkAndSweep(opts Options, set *Set) error

type Type

type Type interface {
	// MarkAndSweep queries the resource in a specific region, using
	// the provided session (which has account-number acct), calling
	// res.Mark(<resource>) on each resource and deleting
	// appropriately.
	MarkAndSweep(opts Options, res *Set) error

	// ListAll queries all the resources this account has access to
	ListAll(opts Options) (*Set, error)
}

type VPCEndpoints

type VPCEndpoints struct{}

func (VPCEndpoints) ListAll

func (VPCEndpoints) ListAll(opts Options) (*Set, error)

func (VPCEndpoints) MarkAndSweep

func (VPCEndpoints) MarkAndSweep(opts Options, set *Set) error

type VPCs

type VPCs struct{}

func (VPCs) ListAll

func (VPCs) ListAll(opts Options) (*Set, error)

func (VPCs) MarkAndSweep

func (VPCs) MarkAndSweep(opts Options, set *Set) error

type Volumes

type Volumes struct{}

Volumes: https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#EC2.DescribeVolumes

func (Volumes) ListAll

func (Volumes) ListAll(opts Options) (*Set, error)

func (Volumes) MarkAndSweep

func (Volumes) MarkAndSweep(opts Options, set *Set) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL