-
Notifications
You must be signed in to change notification settings - Fork 0
[PLT-1227] Cost Anomaly alert to slack #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
juliareynolds-nava
wants to merge
51
commits into
main
Choose a base branch
from
plt_1227_cost_anomaly
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
aa10a8a
initial checkin
juliareynolds-nava 1480012
add workflow check
juliareynolds-nava 348f933
fmt
juliareynolds-nava be551af
cost monitor and sns configuration
juliareynolds-nava 12e67cb
formatting
juliareynolds-nava 08a73fe
formatting
juliareynolds-nava 0ef1ac3
implementing alarm-to-slack
juliareynolds-nava 945a6bd
formatting
juliareynolds-nava e44bc9d
added cdap to function apps
juliareynolds-nava a4e330c
Changed threshold settings per DF
juliareynolds-nava e269c58
Update terraform/services/cost-anomaly/main.tf
juliareynolds-nava 5a76f50
adding cdap repo
juliareynolds-nava 4dd8ca2
implementing the topic module in cost anomaly alert
juliareynolds-nava a1907bd
Added lambda code
juliareynolds-nava 4be6eaa
Added lambda code
juliareynolds-nava 6002b24
testing feedback
juliareynolds-nava 3951b1c
correct indent
juliareynolds-nava 8682d57
test
juliareynolds-nava 66f5156
test
juliareynolds-nava 74616f9
parameterized webhook
juliareynolds-nava 711e343
inject param name as env variable to lambda
juliareynolds-nava 4bb9dab
correct workflow for tofu
juliareynolds-nava 402fc1a
remove lambda > work will be in plt-1361
juliareynolds-nava 57c2e14
remove lambda > work will be in plt-1361
juliareynolds-nava a19ffce
revert topic module changes
juliareynolds-nava 2e16165
revert function module changes
juliareynolds-nava 4bb6797
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava 2233697
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava dda9eeb
set working directory at top of workflow
juliareynolds-nava a5c570b
set working directory at top of workflow
juliareynolds-nava 81e5026
set working directory at top of workflow
juliareynolds-nava d305754
set working directory at top of workflow
juliareynolds-nava 5960f0d
run tofu apply with exclusions first
juliareynolds-nava 7e38dfd
run tofu apply with exclusions first
juliareynolds-nava 6af0408
run tofu apply with exclusions first
juliareynolds-nava 28d47f6
pr feedback
juliareynolds-nava a8efedc
pr feedback
juliareynolds-nava a230bf7
pr feedback
juliareynolds-nava a7c4c76
Add standards module.
juliareynolds-nava b3efdbc
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava f34d264
Add standards module.
juliareynolds-nava f72b677
tofu fmt
juliareynolds-nava c7cacd8
tofu fmt
juliareynolds-nava efa17ae
tofu fmt
juliareynolds-nava 36b5d50
Update .github/workflows/tf-cost-anomaly.yml
juliareynolds-nava 531e15d
Update terraform/services/cost-anomaly/main.tf
juliareynolds-nava 5907d1b
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava a61fa99
fix env description.
juliareynolds-nava 70c3ec5
added cron schedule to workflow
juliareynolds-nava b485d31
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava d8cd832
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,61 @@ | ||
name: tf-cost-anomaly | ||
run-name: tf-cost-anomaly ${{ (inputs.apply || (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'schedule') && 'apply' || 'plan' }} | ||
|
||
on: | ||
push: | ||
paths: | ||
- .github/workflows/tf-cost-anomaly.yml | ||
- terraform/services/cost-anomaly/** | ||
schedule: | ||
- cron: "12 14 * * 1-5" | ||
workflow_dispatch: | ||
inputs: | ||
apply: | ||
required: false | ||
type: boolean | ||
description: "Apply the terraform?" | ||
|
||
env: | ||
TENV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
defaults: | ||
run: | ||
working-directory: ./terraform/services/cost-anomaly | ||
|
||
jobs: | ||
check-fmt: | ||
runs-on: codebuild-cdap-${{github.run_id}}-${{github.run_attempt}} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: sigstore/cosign-installer@d58896d6a1865668819e1d91763c7751a165e159 # v3.9.2 | ||
- uses: cmsgov/cdap/actions/setup-tenv@8343fb96563ce4b74c4dececee9b268f42bd4a40 | ||
- run: tofu fmt -check -diff -recursive . | ||
|
||
plan-apply: | ||
needs: check-fmt | ||
permissions: | ||
contents: read | ||
id-token: write | ||
runs-on: codebuild-cdap-${{github.run_id}}-${{github.run_attempt}} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
app: [bcda] | ||
env: [test, prod] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: sigstore/cosign-installer@d58896d6a1865668819e1d91763c7751a165e159 # v3.9.2 | ||
- uses: cmsgov/cdap/actions/setup-tenv@8343fb96563ce4b74c4dececee9b268f42bd4a40 | ||
- uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 # v5.0.0 | ||
with: | ||
role-to-assume: arn:aws:iam::${{ contains(fromJSON('["dev", "test"]'), matrix.env) && secrets.NON_PROD_ACCOUNT || secrets.PROD_ACCOUNT }}:role/delegatedadmin/developer/${{ matrix.app }}-${{ matrix.env }}-github-actions | ||
aws-region: ${{ vars.AWS_REGION }} | ||
- run: tofu init -backend-config=../../backends/${{ matrix.app }}-${{ matrix.env }}.s3.tfbackend | ||
- run: tofu plan -exclude=module.sns_to_slack_queue.data.aws_iam_policy_document.sns_send_message -exclude=module.sns_to_slack_queue.aws_sns_topic_subscription.this -out=tf.plan | ||
env: | ||
TF_VAR_app: ${{ matrix.app }} | ||
TF_VAR_env: ${{ matrix.env }} | ||
- if: inputs.apply || (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'schedule' | ||
run: tofu apply -auto-approve tf.plan | ||
- if: inputs.apply || (github.event_name == 'push' && github.ref == 'refs/heads/main') | ||
run: tofu apply -auto-approve tf.plan | ||
Comment on lines
+60
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop this duplicate apply step |
This file contains hidden or 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,67 @@ | ||
data "aws_caller_identity" "current" {} | ||
|
||
locals { | ||
function_name = "cost-anomaly-alert" | ||
} | ||
|
||
module "standards" { | ||
source = "github.com/CMSgov/cdap//terraform/modules/standards" | ||
app = "cdap" | ||
env = var.env | ||
providers = { aws = aws, aws.secondary = aws.secondary } | ||
root_module = "https://github.com/CMSgov/cdap/tree/main/terraform/services/cost-anomaly" | ||
service = "cost-anomaly" | ||
} | ||
|
||
resource "aws_ce_anomaly_monitor" "account_alerts" { | ||
name = "AccountAlerts" | ||
monitor_type = "DIMENSIONAL" | ||
monitor_dimension = "SERVICE" | ||
} | ||
|
||
resource "aws_sns_topic" "cost_anomaly_sns" { | ||
name = "cost-anomaly-topic" | ||
kms_master_key_id = "alias/bcda-${var.env}" | ||
} | ||
|
||
resource "aws_ce_anomaly_subscription" "realtime_subscription" { | ||
name = "cost_anomaly_subscription" | ||
frequency = "IMMEDIATE" | ||
|
||
monitor_arn_list = [ | ||
aws_ce_anomaly_monitor.account_alerts.arn | ||
] | ||
|
||
subscriber { | ||
type = "SNS" | ||
address = aws_sns_topic.cost_anomaly_sns.arn | ||
} | ||
|
||
threshold_expression { | ||
or { | ||
dimension { | ||
key = "ANOMALY_TOTAL_IMPACT_ABSOLUTE" | ||
match_options = ["GREATER_THAN_OR_EQUAL"] | ||
values = ["20"] | ||
} | ||
} | ||
or { | ||
dimension { | ||
key = "ANOMALY_TOTAL_IMPACT_PERCENTAGE" | ||
match_options = ["GREATER_THAN_OR_EQUAL"] | ||
values = ["5"] | ||
} | ||
} | ||
} | ||
} | ||
|
||
module "sns_to_slack_queue" { | ||
source = "../../modules/queue" | ||
|
||
name = "cost-anomaly-alert-queue" | ||
sns_topic_arn = aws_sns_topic.cost_anomaly_sns.arn | ||
|
||
app = "bcda" | ||
env = var.env | ||
function_name = local.function_name | ||
} |
This file contains hidden or 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,28 @@ | ||
terraform { | ||
backend "s3" { | ||
key = "cost-anomaly/terraform.tfstate" | ||
} | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~>5" | ||
} | ||
} | ||
required_version = "1.10.5" | ||
} | ||
|
||
provider "aws" { | ||
alias = "primary" | ||
region = "us-east-1" | ||
default_tags { | ||
tags = module.standards.default_tags | ||
} | ||
} | ||
|
||
provider "aws" { | ||
alias = "secondary" | ||
region = "us-west-2" | ||
default_tags { | ||
tags = module.standards.default_tags | ||
} | ||
} |
This file contains hidden or 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,8 @@ | ||
variable "env" { | ||
description = "The application environment (test, prod)" | ||
type = string | ||
validation { | ||
condition = contains(["test", "prod"], var.env) | ||
error_message = "Valid value for env is test or prod." | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these excludes in the plan?