From 4eb40f7d82e086a56264e4f8511d7207e3570331 Mon Sep 17 00:00:00 2001 From: aatish sharma Date: Wed, 10 Apr 2024 14:48:30 +0530 Subject: [PATCH] feat: enable of logging_config --- examples/bucket-secure/example.tf | 2 ++ examples/domain-cdn/example.tf | 12 ++++++++++++ main.tf | 13 +++++++++++++ variables.tf | 18 ++++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/examples/bucket-secure/example.tf b/examples/bucket-secure/example.tf index b2136df..1b0584a 100644 --- a/examples/bucket-secure/example.tf +++ b/examples/bucket-secure/example.tf @@ -45,6 +45,8 @@ module "cdn" { trusted_signers = ["self"] public_key_enable = true public_key = "./cdn.pem" + access_log_bucket = module.s3_bucket.id + } diff --git a/examples/domain-cdn/example.tf b/examples/domain-cdn/example.tf index daa521f..9e24b82 100644 --- a/examples/domain-cdn/example.tf +++ b/examples/domain-cdn/example.tf @@ -8,6 +8,17 @@ locals { environment = "test" } +module "s3_bucket" { + source = "clouddrove/s3/aws" + version = "2.0.0" + + name = "${local.name}-secure-bucket-cdn" + environment = local.environment + versioning = true + acl = "private" +} + + module "acm" { source = "clouddrove/acm/aws" version = "1.4.1" @@ -33,6 +44,7 @@ module "cdn" { viewer_protocol_policy = "redirect-to-https" allowed_methods = ["GET", "HEAD"] acm_certificate_arn = module.acm.arn + access_log_bucket = module.s3_bucket.id } diff --git a/main.tf b/main.tf index 6e094b0..71206c1 100644 --- a/main.tf +++ b/main.tf @@ -81,6 +81,12 @@ resource "aws_cloudfront_distribution" "bucket" { max_ttl = var.max_ttl } + logging_config { + include_cookies = var.include_cookies + bucket = var.access_log_bucket + prefix = var.prefix + } + restrictions { geo_restriction { restriction_type = var.geo_restriction_type @@ -127,6 +133,13 @@ resource "aws_cloudfront_distribution" "domain" { } } + logging_config { + include_cookies = var.include_cookies + bucket = var.access_log_bucket + prefix = var.prefix + } + + viewer_certificate { cloudfront_default_certificate = var.acm_certificate_arn == "" ? true : false acm_certificate_arn = var.acm_certificate_arn diff --git a/variables.tf b/variables.tf index 5023184..e214599 100644 --- a/variables.tf +++ b/variables.tf @@ -304,4 +304,22 @@ variable "error_caching_min_ttl" { type = string default = "10" description = "the value of errro caching min ttl" +} + +variable "include_cookies" { + type = bool + default = null + description = "Whether to include cookies in access logs (default: false)." +} + +variable "prefix" { + type = string + default = "" + description = "Prefix to the access log filenames for this distribution, for example, myprefix/" +} + +variable "access_log_bucket" { + type = string + default = "" + description = "Amazon S3 bucket to store the access logs in, for example, myawslogbucket.s3.amazonaws.com." } \ No newline at end of file