diff --git a/locals.tf b/locals.tf index a261816..6099b7d 100644 --- a/locals.tf +++ b/locals.tf @@ -16,6 +16,7 @@ locals { restriction_type = "none" locations = [] }) + price_class = coalesce(try(var.cloudfront.price_class, null), "PriceClass_All") cors = merge({ allow_credentials = false, allow_headers = ["*"], diff --git a/main.tf b/main.tf index 8dc0651..1f44aa8 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,5 @@ terraform { - required_version = "~> 1.5" + required_version = ">= 1.5" required_providers { aws = { @@ -12,11 +12,16 @@ terraform { data "aws_caller_identity" "current" {} data "aws_region" "current" {} +locals { + aws_region = var.region != null ? var.region : data.aws_region.current.name +} + /** * Assets & Cache S3 Bucket **/ module "assets" { source = "./modules/opennext-assets" + region = local.aws_region default_tags = var.default_tags prefix = "${var.prefix}-assets" @@ -31,6 +36,7 @@ module "assets" { **/ module "server_function" { source = "./modules/opennext-lambda" + region = local.aws_region default_tags = var.default_tags prefix = "${var.prefix}-nextjs-server" @@ -67,6 +73,7 @@ module "server_function" { **/ module "image_optimization_function" { source = "./modules/opennext-lambda" + region = local.aws_region default_tags = var.default_tags prefix = "${var.prefix}-nextjs-image-optimization" @@ -101,6 +108,7 @@ module "image_optimization_function" { **/ module "revalidation_function" { source = "./modules/opennext-lambda" + region = local.aws_region default_tags = var.default_tags prefix = "${var.prefix}-nextjs-revalidation" @@ -136,6 +144,7 @@ module "revalidation_function" { module "revalidation_queue" { source = "./modules/opennext-revalidation-queue" prefix = "${var.prefix}-revalidation-queue" + region = local.aws_region default_tags = var.default_tags aws_account_id = data.aws_caller_identity.current.account_id @@ -148,6 +157,7 @@ module "revalidation_queue" { module "warmer_function" { source = "./modules/opennext-lambda" + region = local.aws_region default_tags = var.default_tags prefix = "${var.prefix}-nextjs-warmer" @@ -184,6 +194,7 @@ module "warmer_function" { **/ module "cloudfront_logs" { source = "./modules/cloudfront-logs" + region = local.aws_region default_tags = var.default_tags log_group_name = "${var.prefix}-cloudfront-logs" @@ -197,16 +208,19 @@ module "cloudfront_logs" { module "cloudfront" { source = "./modules/opennext-cloudfront" prefix = "${var.prefix}-cloudfront" + region = local.aws_region default_tags = var.default_tags + price_class = local.cloudfront.price_class + comment = local.cloudfront.comment logging_bucket_domain_name = module.cloudfront_logs.logs_s3_bucket.bucket_regional_domain_name assets_origin_access_identity = module.assets.cloudfront_origin_access_identity.cloudfront_access_identity_path origins = { assets_bucket = module.assets.assets_bucket.bucket_regional_domain_name - server_function = "${module.server_function.lambda_function_url.url_id}.lambda-url.${data.aws_region.current.name}.on.aws" - image_optimization_function = "${module.image_optimization_function.lambda_function_url.url_id}.lambda-url.${data.aws_region.current.name}.on.aws" + server_function = "${module.server_function.lambda_function_url.url_id}.lambda-url.${local.aws_region}.on.aws" + image_optimization_function = "${module.image_optimization_function.lambda_function_url.url_id}.lambda-url.${local.aws_region}.on.aws" } aliases = local.cloudfront.aliases diff --git a/modules/cloudfront-logs/main.tf b/modules/cloudfront-logs/main.tf index a63a64f..4c9296b 100644 --- a/modules/cloudfront-logs/main.tf +++ b/modules/cloudfront-logs/main.tf @@ -1,5 +1,5 @@ terraform { - required_version = "~> 1.5" + required_version = ">= 1.5" required_providers { aws = { @@ -15,6 +15,7 @@ terraform { } provider "aws" { + region = var.region default_tags { tags = var.default_tags } diff --git a/modules/cloudfront-logs/variables.tf b/modules/cloudfront-logs/variables.tf index c95a0e9..0ac05ab 100644 --- a/modules/cloudfront-logs/variables.tf +++ b/modules/cloudfront-logs/variables.tf @@ -4,6 +4,11 @@ variable "default_tags" { default = {} } +variable "region" { + type = string + description = "The deployment region to be used by the AWS provider." +} + variable "log_group_name" { type = string diff --git a/modules/opennext-assets/main.tf b/modules/opennext-assets/main.tf index 2e5485c..9b66b22 100644 --- a/modules/opennext-assets/main.tf +++ b/modules/opennext-assets/main.tf @@ -1,5 +1,5 @@ terraform { - required_version = "~> 1.5" + required_version = ">= 1.5" required_providers { aws = { @@ -10,6 +10,7 @@ terraform { } provider "aws" { + region = var.region default_tags { tags = var.default_tags } diff --git a/modules/opennext-assets/variables.tf b/modules/opennext-assets/variables.tf index 4049bd5..ff701de 100644 --- a/modules/opennext-assets/variables.tf +++ b/modules/opennext-assets/variables.tf @@ -9,7 +9,10 @@ variable "default_tags" { default = {} } - +variable "region" { + type = string + description = "The deployment region to be used by the AWS provider." +} variable "assets_path" { type = string diff --git a/modules/opennext-cloudfront/main.tf b/modules/opennext-cloudfront/main.tf index 04b13ab..ca45e91 100644 --- a/modules/opennext-cloudfront/main.tf +++ b/modules/opennext-cloudfront/main.tf @@ -1,5 +1,5 @@ terraform { - required_version = "~> 1.5" + required_version = ">= 1.5" required_providers { aws = { @@ -10,6 +10,7 @@ terraform { } provider "aws" { + region = var.region default_tags { tags = var.default_tags } diff --git a/modules/opennext-cloudfront/variables.tf b/modules/opennext-cloudfront/variables.tf index 1ab6fe3..ac899b2 100644 --- a/modules/opennext-cloudfront/variables.tf +++ b/modules/opennext-cloudfront/variables.tf @@ -9,6 +9,11 @@ variable "default_tags" { default = {} } +variable "region" { + type = string + description = "The deployment region to be used by the AWS provider." +} + variable "comment" { type = string description = "Comment to add to the CloudFront distribution" @@ -18,6 +23,16 @@ variable "acm_certificate_arn" { type = string } +variable "price_class" { + type = string + description = "The price class to use for the distribution" + validation { + condition = contains(["PriceClass_200", "PriceClass_100", "PriceClass_All"], var.price_class) + error_message = "Valid values for price_class are: `PriceClass_200`, `PriceClass_100` and `PriceClass_All`." + } + default = "PriceClass_All" +} + variable "origins" { type = object({ assets_bucket = string diff --git a/modules/opennext-lambda/main.tf b/modules/opennext-lambda/main.tf index a7b2f7e..2e2768d 100644 --- a/modules/opennext-lambda/main.tf +++ b/modules/opennext-lambda/main.tf @@ -1,5 +1,5 @@ terraform { - required_version = "~> 1.5" + required_version = ">= 1.5" required_providers { aws = { @@ -14,6 +14,7 @@ terraform { } provider "aws" { + region = var.region default_tags { tags = var.default_tags } diff --git a/modules/opennext-lambda/variables.tf b/modules/opennext-lambda/variables.tf index 40c3422..5afac3e 100644 --- a/modules/opennext-lambda/variables.tf +++ b/modules/opennext-lambda/variables.tf @@ -12,7 +12,10 @@ variable "default_tags" { default = {} } - +variable "region" { + type = string + description = "The deployment region to be used by the AWS provider." +} /** * Create Toggles diff --git a/modules/opennext-revalidation-queue/main.tf b/modules/opennext-revalidation-queue/main.tf index 2e5485c..c44a71b 100644 --- a/modules/opennext-revalidation-queue/main.tf +++ b/modules/opennext-revalidation-queue/main.tf @@ -10,6 +10,7 @@ terraform { } provider "aws" { + region = var.region default_tags { tags = var.default_tags } diff --git a/modules/opennext-revalidation-queue/variables.tf b/modules/opennext-revalidation-queue/variables.tf index 3ace808..7e5b736 100644 --- a/modules/opennext-revalidation-queue/variables.tf +++ b/modules/opennext-revalidation-queue/variables.tf @@ -3,6 +3,11 @@ variable "prefix" { description = "Prefix for created resource IDs" } +variable "region" { + type = string + description = "The deployment region to be used by the AWS provider." +} + variable "default_tags" { type = map(string) description = "Default tags to apply to all created resources" diff --git a/variables.tf b/variables.tf index c11dbac..1b73f07 100644 --- a/variables.tf +++ b/variables.tf @@ -14,6 +14,16 @@ variable "default_tags" { default = {} } +/** + * AWS Provider Variables + **/ +variable "region" { + type = string + description = "The deployment region to be used by the AWS provider." + default = null +} + + /** * Route53 (DNS) Variables **/ @@ -317,6 +327,7 @@ variable "cloudfront" { override = bool value = string }))) + price_class = optional(string) geo_restriction = optional(object({ restriction_type = string locations = list(string)