Skip to content

Commit 2a71063

Browse files
authored
Merge pull request #8 from xoap-io/dev
Added cloudfront request policy for caching
2 parents 0cefb82 + 6bf2098 commit 2a71063

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

.github/workflows/commit-message-validator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ jobs:
99
- uses: actions/checkout@v3
1010
with:
1111
fetch-depth: 0
12-
- uses: wagoid/commitlint-github-action@v4
12+
- uses: wagoid/commitlint-github-action@v5

.github/workflows/megalinter.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
DISABLE_LINTERS: TERRAFORM_TERRASCAN
2727
- name: Archive production artifacts
2828
if: ${{ success() }} || ${{ failure() }}
29-
uses: actions/upload-artifact@v2
29+
uses: actions/upload-artifact@v3
3030
with:
3131
name: MegaLinter reports
3232
path: |

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Please be aware that this is mainly a copy operation which means all your curren
126126
|------|------|
127127
| [aws_cloudfront_cache_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_cache_policy) | resource |
128128
| [aws_cloudfront_distribution.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution) | resource |
129+
| [aws_cloudfront_origin_request_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_origin_request_policy) | resource |
129130

130131
## Inputs
131132

main.tf

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ resource "aws_cloudfront_cache_policy" "this" {
2828
enable_accept_encoding_gzip = true
2929
enable_accept_encoding_brotli = true
3030
cookies_config {
31-
cookie_behavior = "none"
31+
cookie_behavior = "all"
3232
}
3333
headers_config {
3434
header_behavior = "none"
@@ -39,6 +39,18 @@ resource "aws_cloudfront_cache_policy" "this" {
3939

4040
}
4141
}
42+
resource "aws_cloudfront_origin_request_policy" "this" {
43+
name = module.this_label.id
44+
cookies_config {
45+
cookie_behavior = "all"
46+
}
47+
headers_config {
48+
header_behavior = "none"
49+
}
50+
query_strings_config {
51+
query_string_behavior = "all"
52+
}
53+
}
4254
#tfsec:ignore:AWS045
4355
resource "aws_cloudfront_distribution" "this" {
4456
origin {
@@ -65,13 +77,16 @@ resource "aws_cloudfront_distribution" "this" {
6577
default_root_object = var.default_root_object
6678
aliases = var.cloudfront_aliases
6779
default_cache_behavior {
68-
allowed_methods = var.allowed_methods
69-
cached_methods = var.cached_methods
70-
target_origin_id = var.s3_origin_id
71-
compress = true
72-
cache_policy_id = aws_cloudfront_cache_policy.this.id
73-
viewer_protocol_policy = var.viewer_protocol_policy
74-
min_ttl = var.cf_min_ttl
80+
allowed_methods = var.allowed_methods
81+
cached_methods = var.cached_methods
82+
target_origin_id = var.s3_origin_id
83+
compress = true
84+
cache_policy_id = aws_cloudfront_cache_policy.this.id
85+
origin_request_policy_id = aws_cloudfront_origin_request_policy.this.id
86+
viewer_protocol_policy = var.viewer_protocol_policy
87+
min_ttl = var.cf_min_ttl
88+
max_ttl = var.cf_max_ttl
89+
default_ttl = var.cf_default_ttl
7590
}
7691
price_class = var.cf_price_class
7792
viewer_certificate {

0 commit comments

Comments
 (0)