Skip to content
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

feat: Automatically invalidate CDN cache after deployment #40

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions .github/workflows/terraform-apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ on:
description: Name of the concurrency group (avoids simultaneous Terraform execution against the same environment)
type: string
default: run_terraform
clear-web-cache:
description: Whether to invalidate the CloudFront distribution cache as a post-deployment step.
type: boolean
default: true
secrets:
aws-access-key-id:
required: true
Expand Down Expand Up @@ -149,3 +153,12 @@ jobs:
AWS_ACCESS_KEY_ID: "${{ steps.decrypt-aws-access-key-id.outputs.out }}"
AWS_SECRET_ACCESS_KEY: "${{ steps.decrypt-aws-secret-access-key.outputs.out }}"
AWS_SESSION_TOKEN: "${{ steps.decrypt-aws-session-token.outputs.out }}"
- name: Invalidate CloudFront distribution cache
if: success() && inputs.clear-web-cache
run:
DISTRIBUTION_ID=$(terraform output -json | jq .web_cloudfront_distribution_id.value)
aws cloudfront create-invalidation --paths '/*' --distribution-id $DISTRIBUTION_ID
env:
AWS_ACCESS_KEY_ID: "${{ steps.decrypt-aws-access-key-id.outputs.out }}"
AWS_SECRET_ACCESS_KEY: "${{ steps.decrypt-aws-secret-access-key.outputs.out }}"
AWS_SESSION_TOKEN: "${{ steps.decrypt-aws-session-token.outputs.out }}"
4 changes: 4 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "web_cloudfront_distribution_id" {
description = "The ID of the CloudFront distribution serving the web app."
value = module.cdn.cloudfront_distribution_id
}
Loading