Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add region explicitly in aws provider to avoid regressions #15

Merged
merged 6 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["*"],
Expand Down
20 changes: 17 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = "~> 1.5"
required_version = ">= 1.5"

required_providers {
aws = {
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/cloudfront-logs/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = "~> 1.5"
required_version = ">= 1.5"

required_providers {
aws = {
Expand All @@ -15,6 +15,7 @@ terraform {
}

provider "aws" {
region = var.region
default_tags {
tags = var.default_tags
}
Expand Down
5 changes: 5 additions & 0 deletions modules/cloudfront-logs/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/opennext-assets/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = "~> 1.5"
required_version = ">= 1.5"

required_providers {
aws = {
Expand All @@ -10,6 +10,7 @@ terraform {
}

provider "aws" {
region = var.region
default_tags {
tags = var.default_tags
}
Expand Down
5 changes: 4 additions & 1 deletion modules/opennext-assets/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/opennext-cloudfront/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = "~> 1.5"
required_version = ">= 1.5"

required_providers {
aws = {
Expand All @@ -10,6 +10,7 @@ terraform {
}

provider "aws" {
region = var.region
default_tags {
tags = var.default_tags
}
Expand Down
15 changes: 15 additions & 0 deletions modules/opennext-cloudfront/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/opennext-lambda/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = "~> 1.5"
required_version = ">= 1.5"

required_providers {
aws = {
Expand All @@ -14,6 +14,7 @@ terraform {
}

provider "aws" {
region = var.region
default_tags {
tags = var.default_tags
}
Expand Down
5 changes: 4 additions & 1 deletion modules/opennext-lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/opennext-revalidation-queue/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ terraform {
}

provider "aws" {
region = var.region
default_tags {
tags = var.default_tags
}
Expand Down
5 changes: 5 additions & 0 deletions modules/opennext-revalidation-queue/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
**/
Expand Down Expand Up @@ -317,6 +327,7 @@ variable "cloudfront" {
override = bool
value = string
})))
price_class = optional(string)
geo_restriction = optional(object({
restriction_type = string
locations = list(string)
Expand Down
Loading