From 4914cbee4592a7dce463e606b6d9afe451137c07 Mon Sep 17 00:00:00 2001 From: Julieta Aghamyan Date: Tue, 8 Oct 2024 16:34:26 +0400 Subject: [PATCH] fix(DMVP-5400): Cloudfront custom error response --- modules/cloudfront/distribution.tf | 10 ++++++++++ modules/cloudfront/variables.tf | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/modules/cloudfront/distribution.tf b/modules/cloudfront/distribution.tf index ccb97045..0cf91140 100644 --- a/modules/cloudfront/distribution.tf +++ b/modules/cloudfront/distribution.tf @@ -23,6 +23,16 @@ resource "aws_cloudfront_distribution" "main" { retain_on_delete = var.retain_on_delete default_root_object = var.default_root_object + dynamic "custom_error_response" { + for_each = var.custom_error_response.enabled ? [1] : [] + content { + error_caching_min_ttl = var.custom_error_response.error_caching_min_ttl + error_code = var.custom_error_response.error_code + response_code = var.custom_error_response.response_code + response_page_path = var.custom_error_response.response_page_path + } + } + tags = { Name = var.tags_name } diff --git a/modules/cloudfront/variables.tf b/modules/cloudfront/variables.tf index b70d4c47..bd3c2fba 100644 --- a/modules/cloudfront/variables.tf +++ b/modules/cloudfront/variables.tf @@ -312,3 +312,21 @@ variable "create_response_headers_policy" { } description = "Create cloudfront custom header policy" } + +variable "custom_error_response" { + type = object({ + enabled = optional(bool, false) + error_caching_min_ttl = optional(number, 10) + error_code = optional(number, 404) + response_code = optional(number, 200) + response_page_path = optional(string, "/index.html") + }) + default = { + enabled = false + error_caching_min_ttl = 10 + error_code = 404 + response_code = 200 + response_page_path = "/index.html" + } + description = "Cloudfront custom error response" +}