Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
aa10a8a
initial checkin
juliareynolds-nava Aug 21, 2025
1480012
add workflow check
juliareynolds-nava Aug 21, 2025
348f933
fmt
juliareynolds-nava Aug 22, 2025
be551af
cost monitor and sns configuration
juliareynolds-nava Aug 25, 2025
12e67cb
formatting
juliareynolds-nava Aug 25, 2025
08a73fe
formatting
juliareynolds-nava Aug 25, 2025
0ef1ac3
implementing alarm-to-slack
juliareynolds-nava Aug 25, 2025
945a6bd
formatting
juliareynolds-nava Aug 25, 2025
e44bc9d
added cdap to function apps
juliareynolds-nava Aug 25, 2025
a4e330c
Changed threshold settings per DF
juliareynolds-nava Aug 26, 2025
e269c58
Update terraform/services/cost-anomaly/main.tf
juliareynolds-nava Sep 2, 2025
5a76f50
adding cdap repo
juliareynolds-nava Sep 3, 2025
4dd8ca2
implementing the topic module in cost anomaly alert
juliareynolds-nava Sep 3, 2025
a1907bd
Added lambda code
juliareynolds-nava Sep 19, 2025
4be6eaa
Added lambda code
juliareynolds-nava Sep 19, 2025
6002b24
testing feedback
juliareynolds-nava Sep 22, 2025
3951b1c
correct indent
juliareynolds-nava Sep 22, 2025
8682d57
test
juliareynolds-nava Sep 22, 2025
66f5156
test
juliareynolds-nava Sep 22, 2025
74616f9
parameterized webhook
juliareynolds-nava Sep 23, 2025
711e343
inject param name as env variable to lambda
juliareynolds-nava Sep 23, 2025
4bb9dab
correct workflow for tofu
juliareynolds-nava Sep 23, 2025
402fc1a
remove lambda > work will be in plt-1361
juliareynolds-nava Sep 24, 2025
57c2e14
remove lambda > work will be in plt-1361
juliareynolds-nava Sep 24, 2025
a19ffce
revert topic module changes
juliareynolds-nava Sep 24, 2025
2e16165
revert function module changes
juliareynolds-nava Sep 24, 2025
4bb6797
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava Sep 24, 2025
2233697
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava Sep 26, 2025
dda9eeb
set working directory at top of workflow
juliareynolds-nava Sep 26, 2025
a5c570b
set working directory at top of workflow
juliareynolds-nava Sep 26, 2025
81e5026
set working directory at top of workflow
juliareynolds-nava Sep 26, 2025
d305754
set working directory at top of workflow
juliareynolds-nava Sep 26, 2025
5960f0d
run tofu apply with exclusions first
juliareynolds-nava Sep 26, 2025
7e38dfd
run tofu apply with exclusions first
juliareynolds-nava Sep 26, 2025
6af0408
run tofu apply with exclusions first
juliareynolds-nava Sep 26, 2025
28d47f6
pr feedback
juliareynolds-nava Sep 29, 2025
a8efedc
pr feedback
juliareynolds-nava Sep 29, 2025
a230bf7
pr feedback
juliareynolds-nava Sep 30, 2025
a7c4c76
Add standards module.
juliareynolds-nava Sep 30, 2025
b3efdbc
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava Sep 30, 2025
f34d264
Add standards module.
juliareynolds-nava Sep 30, 2025
f72b677
tofu fmt
juliareynolds-nava Sep 30, 2025
c7cacd8
tofu fmt
juliareynolds-nava Sep 30, 2025
efa17ae
tofu fmt
juliareynolds-nava Sep 30, 2025
36b5d50
Update .github/workflows/tf-cost-anomaly.yml
juliareynolds-nava Oct 3, 2025
531e15d
Update terraform/services/cost-anomaly/main.tf
juliareynolds-nava Oct 3, 2025
5907d1b
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava Oct 3, 2025
a61fa99
fix env description.
juliareynolds-nava Oct 3, 2025
70c3ec5
added cron schedule to workflow
juliareynolds-nava Oct 6, 2025
b485d31
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava Oct 7, 2025
d8cd832
Merge branch 'main' into plt_1227_cost_anomaly
juliareynolds-nava Oct 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/tf-cost-anomaly.yml
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
Copy link
Member

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?

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this duplicate apply step

67 changes: 67 additions & 0 deletions terraform/services/cost-anomaly/main.tf
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
}
28 changes: 28 additions & 0 deletions terraform/services/cost-anomaly/terraform.tf
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
}
}
8 changes: 8 additions & 0 deletions terraform/services/cost-anomaly/variables.tf
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."
}
}