-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* budget lib * remove my email * added clarification * small fixes * add dummy sim * fix * change the order * create the lib with the script * add peerDependencies * change the name of the class to Alert * update todo --------- Co-authored-by: Elad Ben-Israel <eladb@monada.co>
- Loading branch information
Showing
14 changed files
with
10,341 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: budget-pull | ||
on: | ||
pull_request: | ||
paths: | ||
- budget/** | ||
jobs: | ||
build-budget: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
sparse-checkout: budget | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20.x | ||
registry-url: https://registry.npmjs.org | ||
- name: Install winglang | ||
run: npm i -g winglang | ||
- name: Install dependencies | ||
run: npm install --include=dev | ||
working-directory: budget | ||
- name: Test | ||
run: wing test | ||
working-directory: budget | ||
- name: Pack | ||
run: wing pack | ||
working-directory: budget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: budget-release | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- budget/** | ||
- "!budget/package-lock.json" | ||
jobs: | ||
build-budget: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
sparse-checkout: budget | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20.x | ||
registry-url: https://registry.npmjs.org | ||
- name: Install winglang | ||
run: npm i -g winglang | ||
- name: Install dependencies | ||
run: npm install --include=dev | ||
working-directory: budget | ||
- name: Test | ||
run: wing test | ||
working-directory: budget | ||
- name: Pack | ||
run: wing pack | ||
working-directory: budget | ||
- name: Get package version | ||
run: echo WINGLIB_VERSION=$(node -p "require('./package.json').version") >> | ||
"$GITHUB_ENV" | ||
working-directory: budget | ||
- name: Publish | ||
run: npm publish --access=public --registry https://registry.npmjs.org --tag | ||
latest *.tgz | ||
working-directory: budget | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
- name: Tag commit | ||
uses: tvdias/github-tagger@v0.0.1 | ||
with: | ||
repo-token: ${{ secrets.PROJEN_GITHUB_TOKEN }} | ||
tag: budget-v${{ env.WINGLIB_VERSION }} | ||
- name: GitHub release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
name: budget v${{ env.WINGLIB_VERSION }} | ||
tag_name: budget-v${{ env.WINGLIB_VERSION }} | ||
files: "*.tgz" | ||
token: ${{ secrets.PROJEN_GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Wing | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# budget | ||
|
||
A Wing library for working with [AWS Budgets](https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-managing-costs.html) | ||
|
||
## Prerequisites | ||
|
||
* [winglang](https://winglang.io). | ||
|
||
## Installation | ||
|
||
```sh | ||
npm i @winglibs/budget | ||
``` | ||
|
||
## Usage | ||
|
||
**⚠️ The budget refers to the entire account and not just for the current project!** | ||
|
||
Add your budget alert to the code: | ||
|
||
```wing | ||
bring budget; | ||
new budget.Alert( | ||
name: "Test", | ||
amount: 10, | ||
emailAddresses: ["your@email.com"], | ||
); | ||
``` | ||
|
||
*Note: The budget amount is in USD.* | ||
|
||
You get an alert when your monthly payment goes over your budget. | ||
|
||
## TODO | ||
|
||
- [ ] Set a budget alert only for resources with certain tags. | ||
- [ ] Allow to perform automatic actions when the budget runs out. | ||
|
||
## License | ||
|
||
This library is licensed under the [MIT License](./LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
pub enum TimeUnit { | ||
DAILY, | ||
MONTHLY, | ||
ANNUALLY, | ||
} | ||
|
||
pub struct AlertProps { | ||
name: str; | ||
amount: num; // USD | ||
emailAddresses: Array<str>; | ||
timeUnit: TimeUnit?; // default: MONTHLY | ||
} | ||
|
||
pub interface IAlert { | ||
} | ||
|
||
pub class Util { | ||
pub static timeUnitToStr(timeUnit: TimeUnit): str { | ||
if timeUnit == TimeUnit.DAILY { | ||
return "DAILY"; | ||
} elif timeUnit == TimeUnit.MONTHLY { | ||
return "MONTHLY"; | ||
} elif timeUnit == TimeUnit.ANNUALLY { | ||
return "ANNUALLY"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
bring "./budget-shared.w" as shared; | ||
|
||
pub class AlertSim impl shared.IAlert { | ||
new(props: shared.AlertProps) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
bring "cdktf" as cdktf; | ||
bring "@cdktf/provider-aws" as tfaws; | ||
|
||
bring "./budget-shared.w" as shared; | ||
|
||
pub class AlertTfAws impl shared.IAlert { | ||
budget: tfaws.budgetsBudget.BudgetsBudget; | ||
|
||
new(props: shared.AlertProps) { | ||
this.budget = new tfaws.budgetsBudget.BudgetsBudget( | ||
name: props.name, | ||
budgetType: "COST", | ||
limitUnit: "USD", | ||
limitAmount: "{props.amount}", | ||
timeUnit: shared.Util.timeUnitToStr(props.timeUnit ?? shared.TimeUnit.MONTHLY), | ||
notification: { | ||
comparison_operator: "GREATER_THAN", | ||
threshold: 100, | ||
threshold_type: "PERCENTAGE", | ||
notification_type: "ACTUAL", | ||
subscriber_email_addresses: props.emailAddresses, | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
bring "./budget.w" as budget; | ||
|
||
// use budget of 10 USD | ||
|
||
new budget.Alert( | ||
name: "test", | ||
amount: 10, | ||
emailAddresses: ["your@email.com"], | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
bring util; | ||
|
||
bring "./budget-sim.w" as sim; | ||
bring "./budget-tfaws.w" as tfaws; | ||
bring "./budget-shared.w" as shared; | ||
|
||
pub class Alert { | ||
platform: shared.IAlert; | ||
|
||
new(props: shared.AlertProps) { | ||
if util.env("WING_TARGET") == "tf-aws" { | ||
this.platform = new tfaws.AlertTfAws(props); | ||
} elif util.env("WING_TARGET") == "sim" { | ||
this.platform = new sim.AlertSim(props); | ||
} else { | ||
throw "unknown platform"; | ||
} | ||
} | ||
} |
Oops, something went wrong.