Skip to content

Commit

Permalink
Self documenting makefile.
Browse files Browse the repository at this point in the history
Updated readme.
  • Loading branch information
nirdosh17 committed Aug 17, 2021
1 parent 4c74442 commit fccd167
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
build:
.DEFAULT_GOAL=help

build: ## Download packages and build binary
go mod download && \
go build -o cfn-teardown .

run: build
run: build ## Build and run binary
./cfn-teardown

# http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
33 changes: 14 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ CFN Teardown is a tool to delete CloudFormation stacks respecting stack dependen

If you deploy all of you intrastructure using CloudFormation with a `consistent naming convention` for stacks, then you can use this tool to tear down the environment.

Teardown of huge number of stacks using this tool is considerably faster that applying brute force.

**Example of consistent stack naming:**

- qa-bucket-users
Expand All @@ -23,12 +21,13 @@ You can supply stack pattern as `qa-` in this tool to delete these stacks.

- Multiple safety checks to prevent accidental deletion.

- Generates a file `stack_teardown_details` listing stack dependencies which can be watched live to get an idea of how the script is working. It contains useful details like time taken to delete each stacks, delete attempts, failure reason and many more.
- Generates `stack_teardown_details.json` listing stack dependencies which can be watched live to get an idea of how the script is working. It contains useful details like time taken to delete each stacks, delete attempts, failure reason and many more.

- Supports slack notification via webhook.
- Supports slack notification for deletion status updates via webhook.

---

## Install
### Install

```bash

Expand All @@ -40,7 +39,7 @@ go get github.com/nirdosh17/cfn-teardown



## Using CFN Teardown
### Using CFN Teardown

Required global flags for all commands: `STACK_PATTERN`, `AWS_REGION`, `AWS_PROFILE`

Expand All @@ -56,7 +55,7 @@ Required global flags for all commands: `STACK_PATTERN`, `AWS_REGION`, `AWS_PROF



## Configuration
### Configuration

Configuration for this command can be set in three different ways in the precedence order defined below:
1. Environment variables(same as flag name)
Expand Down Expand Up @@ -96,7 +95,7 @@ cfn-teardown listDependencies --help
cfn-teardown deleteStacks --help
```

## How it works?
### How it works?

1. Scans all stacks in your account.

Expand Down Expand Up @@ -152,13 +151,12 @@ cfn-teardown deleteStacks --help



## Assume Role

By default it tries to use the IAM role of environment it is being run. e.g. Codebuild, EC2 instance. We can also supply role arn if we want the script to assume a different role.
### Assume Role

By default it tries to use the IAM role of environment it is currently running in. But we can also supply role arn if we want the script to assume a different role.


## Safety Checks for Accidental Deletion
### Safety Checks for Accidental Deletion

- `DRY_RUN` flag must be explicitely set to `false` to activate delete functionality

Expand All @@ -167,14 +165,11 @@ By default it tries to use the IAM role of environment it is being run. e.g. Cod
- `TARGET_ACCOUNT_ID` flag will check the supplied account id with aws session account id during runtime to confirm that we are deleting stacks in the desired aws account


## Edge Case
- If a stack can't be deleted from the AWS Console itself due to some dependencies or error, then it won't be deleted by this tool as well. In such case, manual intervention is required.
- To delete a stack with S3 bucket, this script empties the bucket first and then deletes the stack since CFN does not allow to delete stack with non-empty bucket.
### Limitation
If a stack can't be deleted from the AWS Console itself due to some dependencies or error, then it won't be deleted by this tool as well. In such case, manual intervention is required.


## Caution :warning:
---
### Caution :warning:
_With great power, comes great responsibility_

- Use this tool with great caution. **Don't ever** run this in production environment with the intention of deleting a subset of stacks.
- First try within small number of test stacks in dry run mode.
- Use redundant safety flags `DRY_RUN`, `TARGET_ACCOUNT_ID` and `ABORT_WAIT_TIME_MINUTES`.

0 comments on commit fccd167

Please sign in to comment.