8000 Added cloudfront request policy for caching by bbrauneck · Pull Request #8 · xoap-io/terraform-aws-web-cloudfront · GitHub
[go: up one dir, main page]

Skip to content

Added cloudfront request policy for caching #8

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

Merged
merged 6 commits into from
Jun 23, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/commit-message-validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v4
- uses: wagoid/commitlint-github-action@v5
2 changes: 1 addition & 1 deletion .github/workflows/megalinter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
DISABLE_LINTERS: TERRAFORM_TERRASCAN
- name: Archive production artifacts
if: ${{ success() }} || ${{ failure() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: MegaLinter reports
path: |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Please be aware that this is mainly a copy operation which means all your curren
|------|------|
| [aws_cloudfront_cache_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_cache_policy) | resource |
| [aws_cloudfront_distribution.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution) | resource |
| [aws_cloudfront_origin_request_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_origin_request_policy) | resource |

## Inputs

Expand Down
31 changes: 23 additions & 8 deletions main.tf
962B
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ resource "aws_cloudfront_cache_policy" "this" {
enable_accept_encoding_gzip = true
enable_accept_encoding_brotli = true
cookies_config {
cookie_behavior = "none"
cookie_behavior = "all"
}
headers_config {
header_behavior = "none"
Expand All @@ -39,6 +39,18 @@ resource "aws_cloudfront_cache_policy" "this" {

}
}
resource "aws_cloudfront_origin_request_policy" "this" {
name = module.this_label.id
cookies_config {
cookie_behavior = "all"
}
headers_config {
header_behavior = "none"
}
query_strings_config {
query_string_behavior = "all"
}
}
#tfsec:ignore:AWS045
resource "aws_cloudfront_distribution" "this" {
origin {
Expand All @@ -65,13 +77,16 @@ resource "aws_cloudfront_distribution" "this" {
default_root_object = var.default_root_object
aliases = var.cloudfront_aliases
default_cache_behavior {
allowed_methods = var.allowed_methods
cached_methods = var.cached_methods
target_origin_id = var.s3_origin_id
compress = true
cache_policy_id = aws_cloudfront_cache_policy.this.id
viewer_protocol_policy = var.viewer_protocol_policy
min_ttl = var.cf_min_ttl
allowed_methods = var.allowed_methods
cached_methods = var.cached_methods
target_origin_id = var.s3_origin_id
compress = true
cache_policy_id = aws_cloudfront_cache_policy.this.id
origin_request_policy_id = aws_cloudfront_origin_request_policy.this.id
viewer_protocol_policy = var.viewer_protocol_policy
min_ttl = var.cf_min_ttl
max_ttl = var.cf_max_ttl
default_ttl = var.cf_default_ttl
}
price_class = var.cf_price_class
viewer_certificate {
Expand Down
0