Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
94 changes: 94 additions & 0 deletions .github/workflows/infracost.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Generate Infra cost report
on:
pull_request:
types: [opened, synchronize, closed]
push:
branches:
- main

env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
jobs:
infracost-pull-request-checks:
name: Infracost Pull Request Checks
if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize')
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write # Required to post comments
steps:
- name: Setup Infracost
uses: infracost/actions/setup@v3
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}

- name: Checkout base branch
uses: actions/checkout@v4
with:
ref: '${{ github.event.pull_request.base.ref }}'

- name: Generate Infracost cost estimate baseline
run: |
infracost breakdown --path=terraform/ \
--format=json \
--out-file=/tmp/infracost-base.json

- name: Checkout PR branch
uses: actions/checkout@v4

- name: Generate Infracost diff
run: |
infracost diff --path=terraform/ \
--format=json \
--compare-to=/tmp/infracost-base.json \
--out-file=/tmp/infracost.json

- name: Post Infracost comment
run: |
infracost comment github --path=/tmp/infracost.json \
--repo=$GITHUB_REPOSITORY \
--github-token=${{ github.token }} \
--pull-request=${{ github.event.pull_request.number }} \
--behavior=update

infracost-default-branch-update:
name: Infracost Default Branch Update
if: github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master')
runs-on: ubuntu-latest
steps:
- name: Setup Infracost
uses: infracost/actions/setup@v3
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}

- name: Checkout main/master branch
uses: actions/checkout@v4

- name: Run Infracost on default branch and update Infracost Cloud
run: |
infracost breakdown --path=terraform/ \
--format=json \
--out-file=infracost.json

infracost upload --path=infracost.json || echo "Always pass main branch runs even if there are policy failures"

# Update PR status in Infracost Cloud
infracost-pull-request-status-update:
name: Infracost PR Status Update
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Infracost PR Status Update
run: |
PR_STATUS="MERGED"
if [[ ${{ github.event.pull_request.merged }} = false ]]; then PR_STATUS="CLOSED"; fi

echo "Updating status of ${{ github.event.pull_request.html_url }} to $PR_STATUS"
curl -i \
--request POST \
--header "Content-Type: application/json" \
--header "X-API-Key: $INFRACOST_API_KEY" \
--data "{ \"query\": \"mutation {updatePullRequestStatus( url: \\\"${{ github.event.pull_request.html_url }}\\\", status: $PR_STATUS )}\" }" \
"https://dashboard.api.infracost.io/graphql";
env:
INFRACOST_API_KEY: ${{ secrets.INFRACOST_API_KEY }}
34 changes: 34 additions & 0 deletions terraform/modules/frontend/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@ resource "aws_s3_bucket" "frontend" {
bucket = "${var.BucketPrefix}-${var.ProjectId}"
}

resource "aws_s3_bucket_lifecycle_configuration" "frontend" {
bucket = aws_s3_bucket.frontend.id

rule {
id = "AbortIncompleteMultipartUploads"
status = "Enabled"

abort_incomplete_multipart_upload {
days_after_initiation = 1
}
}

rule {
id = "ObjectLifecycle"
status = "Enabled"

filter {}

transition {
days = 30
storage_class = "INTELLIGENT_TIERING"
}

noncurrent_version_transition {
noncurrent_days = 30
storage_class = "STANDARD_IA"
}

noncurrent_version_expiration {
noncurrent_days = 30
}
}
}

data "archive_file" "ui" {
type = "zip"
source_dir = "${path.module}/../../../dist_ui/"
Expand Down
4 changes: 2 additions & 2 deletions terraform/modules/lambdas/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,13 @@ resource "aws_lambda_function_url" "slow_api_lambda_function_url" {
}

module "lambda_warmer_main" {
source = "github.com/acm-uiuc/terraform-modules/lambda-warmer?ref=b52f22e32c6c07af9b1b4750a226882aaccc769d"
source = "git::https://github.com/acm-uiuc/terraform-modules.git//lambda-warmer?ref=b52f22e32c6c07af9b1b4750a226882aaccc769d"
function_to_warm = local.core_api_lambda_name
is_streaming_lambda = true
}

module "lambda_warmer_slow" {
source = "github.com/acm-uiuc/terraform-modules/lambda-warmer?ref=b52f22e32c6c07af9b1b4750a226882aaccc769d"
source = "git::https://github.com/acm-uiuc/terraform-modules.git//lambda-warmer?ref=b52f22e32c6c07af9b1b4750a226882aaccc769d"
function_to_warm = local.core_api_slow_lambda_name
is_streaming_lambda = true
}
Expand Down
Loading