From 60355d438dfc8250ee0286ce2f7cbdcedb240949 Mon Sep 17 00:00:00 2001 From: Jakub Jindra Date: Wed, 17 Jan 2024 09:04:10 +0100 Subject: [PATCH] feat(cloudfront-logging): enable cloudfront_distribution logging to s3 --- README.md | 1 + main.tf | 10 ++++++++++ variables.tf | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 7c8a91e..8c288cb 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ module "static-site" { | [gitlab\_environment](#input\_gitlab\_environment) | n/a | `string` | `"*"` | no | | [gitlab\_project\_id](#input\_gitlab\_project\_id) | n/a | `string` | `null` | no | | [logs\_bucket](#input\_logs\_bucket) | n/a | `string` | `null` | no | +| [logs\_bucket\_domain\_name](#input\_logs\_bucket\_domain\_name) | n/a | `string` | `null` | no | | [override\_status\_code\_403](#input\_override\_status\_code\_403) | n/a | `number` | `403` | no | | [override\_status\_code\_404](#input\_override\_status\_code\_404) | n/a | `number` | `200` | no | | [proxy\_paths](#input\_proxy\_paths) | n/a |
list(object({
origin_domain = string
path_prefix = string
}))
| `[]` | no | diff --git a/main.tf b/main.tf index c908966..033ed3b 100644 --- a/main.tf +++ b/main.tf @@ -186,6 +186,16 @@ resource "aws_cloudfront_distribution" "this" { minimum_protocol_version = "TLSv1.2_2018" } + dynamic "logging_config" { + for_each = var.logs_bucket_domain_name == null ? [] : [1] + + content { + bucket = var.logs_bucket_domain_name + prefix = "cloudfront/access_logs/${local.main_domain_sanitized}/" + include_cookies = false + } + } + tags = local.tags } diff --git a/variables.tf b/variables.tf index 664eb4e..5d90758 100644 --- a/variables.tf +++ b/variables.tf @@ -31,6 +31,11 @@ variable "logs_bucket" { default = null } +variable "logs_bucket_domain_name" { + type = string + default = null +} + variable "cloudfront_price_class" { type = string default = "PriceClass_100"