Format source code
mastergo fmt.go fmtrepository·master·Indexed 25 days ago
https://github.com/gruntwork-io/cloud-nukeA CLI tool designed to delete all resources in a cloud account, primarily used for cleaning up test accounts and removing unnecessary defaults. It supports destructive operations and non-destructive inspections for AWS and GCP, with granular filtering by region, resource type, tags, and age.
go fmt.go fmtFor several AWS resource types, cloud-nuke can perform a permission check before attempting deletion to ensure you have sufficient rights. This check utilizes the AWS DryRun feature where available.
If the check fails, cloud-nuke will raise error: INSUFFICIENT_PERMISSION.
Supported resources for this check:
You can use a YAML configuration file to perform granular resource filtering during a cloud-nuke run. Use the --config flag to specify the path to your YAML file.
Top-level keys in the YAML file must correspond to the resource type's config key found in the cloud-nuke config support matrix.
cloud-nuke aws --config path/to/file.yamlUse these commands to manage and clean up AWS resources.
WARNING: Running cloud-nuke aws is HIGHLY DESTRUCTIVE and deletes all resources in your account. Never use this in a production environment.
cloud-nuke awscloud-nuke inspect-awscloud-nuke aws --dry-run--region flags.--resource-type flags.--config flag for granular filtering.# Delete all resources (with confirmation prompt)
cloud-nuke aws
# Inspect resources without deleting
cloud-nuke inspect-aws
# Delete resources in specific regions only
cloud-nuke aws --region us-east-1 --region us-west-2
# Delete only specific resource types
cloud-nuke aws --resource-type ec2 --resource-type s3
# Preview what would be deleted
cloud-nuke aws --dry-run
# Use a config file for granular filtering
cloud-nuke aws --config path/to/config.yamlTo run the cloud-nuke application from the source code, use the go run command from the root of the repository.
go run main.goTo ensure code quality and prevent nil pointer dereferences during local development, it is recommended to use pre-commit hooks. This will automatically run linters before you commit code.
pre-commit using pip.pip install pre-commit
pre-commit install
pre-commit run --all-filesWhen working with the AWS SDK, always check that both the output and the specific fields within the output are not nil before accessing them. This prevents nil pointer dereference panics if an error is not returned but the response object is incomplete.
// ✅ Good
output, err := client.DescribeResourcePolicy(ctx, input)
if err != nil {
return err
}
if output != nil && output.Policy != nil {
policy := output.Policy
}You can install cloud-nuke by downloading the binary directly or using a package manager.
PATH (e.g., /usr/local/bin/cloud-nuke).chmod u+x /usr/local/bin/cloud-nuke.cloud-nuke --help.brew install cloud-nukebrew install cloud-nuke (via Homebrew on Linux)winget install cloud-nukebrew install cloud-nukeCloud-nuke features global time-based protection via the cloud-nuke-after tag. Any resource with this tag and a future RFC 3339 timestamp is automatically excluded from deletion until that time passes.
Requirement: The resource must support tag-based filtering.
cloud-nuke-after = 2026-06-01T00:00:00ZWhen releasing new versions, follow these versioning rules:
X in v0.X.Y) if the release includes new resource types.v0.2.0, cloud-nuke uses an opt-out model for new resources, meaning new resource types are inherently backward-incompatible for users with CI pipelines relying on cloud-nuke.cloud-nuke-after followed by an ISO 8601 date (e.g., 2024-07-09T00:00:00Z). Cloud-nuke will skip these resources until that date has passed.