https://github.com/shiftcode/delete-cfn-stacks-action
github workflow action to delete aws cloudformation stacks
https://github.com/shiftcode/delete-cfn-stacks-action
Last synced: 7 months ago
JSON representation
github workflow action to delete aws cloudformation stacks
- Host: GitHub
- URL: https://github.com/shiftcode/delete-cfn-stacks-action
- Owner: shiftcode
- Created: 2021-03-31T12:03:33.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-26T12:36:59.000Z (about 2 years ago)
- Last Synced: 2025-03-29T01:19:18.421Z (11 months ago)
- Language: TypeScript
- Size: 1.58 MB
- Stars: 1
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Delete CloudFormation stacks action


This action deletes all cloudformation xx/pr stacks in the provided region with the given name prefix + the stage suffix.
The stage is transformed from the branch name (eg. `#85-my-feature` > `xx85` / `pr85`). Production branch (`master` | `main`) branch
is always ignored.
Make sure your CloudFormation Stacks are fully deletable (if autoDeleteBuckets=true also autoDeleteItems, etc.)
## Usage
### Inputs
#### `stackNamePrefix`
**Required** `string` The prefix of the stack names to delete.
#### `waitForDeleteComplete`
**Optional** `boolean` Whether the action should wait until the stack is completely deleted (status=`DELETE_COMPLETE`).
#### `ignoreBranches`
**Optional** `JSON String Array` branches to ignore (early exit, necessary since on-delete workflows do not support branch restrictions).
Production branches (`master` | `main`) branch is always ignored.
### Example workflow step config
```
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: 'arn:aws:iam::{ACCOUNT_ID}:role/{ROLE_NAME}'
aws-region: eu-central-1
- name: Delete Stacks
uses: shiftcode/delete-cfn-stacks-action@v0.0.X
with:
stackNamePrefix: 'ch-website'
waitForDeleteComplete: true
# master & main are ignored by default
ignoreBranches: '["#1-dev"]'
```
### Hints
- If there are stacks in multiple regions: use both actions two times with their corresponding region.
- If working with `assumedRoles` and [`aws-actions/configure-aws-credentials@v1`](https://github.com/aws-actions/configure-aws-credentials) the policy statement for the static iam user needs to have the actions `"sts:AssumeRole` AND `sts:TagSession` allowed on the role to assume.
The Trust relationship of the assumed role needs to allow those actions for the assuming user.
## Development
### testing
To test the action locally: call `index.js` with env var `INPUT_STACKNAMEPREFIX`
--> `INPUT_STACKNAMEPREFIX="bag-covid19" node ./dist/index.js`
### new version
1) implement your changes
2) commit with `npx commit`
3) set tag `git tag -a -m "my fancy release" v0.0.X`
4) push with tags `git push --follow-tags`