Skip to content

Conversation

@devksingh4
Copy link
Member

@devksingh4 devksingh4 commented Oct 28, 2025

Allows for easily switching the region currently serving traffic

Summary by CodeRabbit

  • New Features

    • Multi-region support: frontend now routes to region-specific endpoints and honors a selectable active region at runtime.
    • Secondary-region compute and queue components added to enable regional failover and lower latency; CDN origins and routing are region-aware.
  • Chores

    • Deployment tooling updated to accept and validate a configured active region in prod and QA plans; build scripts now propagate the active-region setting.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 2025

💰 Infracost report

Monthly estimate increased by $6 📈

Changed project Baseline cost Usage cost* Total change New monthly cost
acm-uiuc/core/terraform/envs/prod +$0 +$6 +$6 (+7%) $83

*Usage costs were estimated using infracost-usage.yml, see docs for other options.

Estimate details
Key: * usage cost, ~ changed, + added, - removed

──────────────────────────────────
Project: envs-prod
Module path: envs/prod

+ module.lambdas_usw2.aws_lambda_function.api_lambda
  +$1

    + Requests
      +$0.05, +0.25 1M requests*

    + Duration (first 7.5B)
      +$1, +100,000 GB-seconds*

+ module.lambdas_usw2.aws_lambda_function.slow_lambda
  +$1

    + Requests
      +$0.05, +0.25 1M requests*

    + Duration (first 7.5B)
      +$1, +100,000 GB-seconds*

+ module.lambdas_usw2.aws_lambda_function.sqs_lambda
  +$1

    + Requests
      +$0.05, +0.25 1M requests*

    + Duration (first 7.5B)
      +$1, +100,000 GB-seconds*

+ module.lambdas_usw2.aws_cloudwatch_log_group.api_logs
  +$0.32

    + Data ingested
      +$0.25, +0.5 GB*

    + Archival Storage
      +$0.06, +2 GB*

    + Insights queries data scanned
      +$0.01, +1 GB*

+ module.lambdas_usw2.module.lambda_warmer_main.aws_cloudwatch_log_group.warmer_logs
  +$0.32

    + Data ingested
      +$0.25, +0.5 GB*

    + Archival Storage
      +$0.06, +2 GB*

    + Insights queries data scanned
      +$0.01, +1 GB*

+ module.lambdas_usw2.module.lambda_warmer_slow.aws_cloudwatch_log_group.warmer_logs
  +$0.32

    + Data ingested
      +$0.25, +0.5 GB*

    + Archival Storage
      +$0.06, +2 GB*

    + Insights queries data scanned
      +$0.01, +1 GB*

+ module.lambdas_usw2.module.lambda_warmer_main.aws_lambda_function.warmer_function
  +$0.22

    + Requests
      +$0.05, +0.25 1M requests*

    + Duration (first 7.5B)
      +$0.17, +12,500 GB-seconds*

+ module.lambdas_usw2.module.lambda_warmer_slow.aws_lambda_function.warmer_function
  +$0.22

    + Requests
      +$0.05, +0.25 1M requests*

    + Duration (first 7.5B)
      +$0.17, +12,500 GB-seconds*

+ module.sqs_queues_usw2.aws_sqs_queue.app_dlq
  +$0.02

    + Requests
      +$0.02, +0.05 1M requests*

+ module.sqs_queues_usw2.aws_sqs_queue.app_queue
  +$0.02

    + Requests
      +$0.02, +0.05 1M requests*

+ module.sqs_queues_usw2.aws_sqs_queue.sales_email_queue
  +$0.02

    + Requests
      +$0.02, +0.05 1M requests*

Monthly cost change for acm-uiuc/core/terraform/envs/prod (Module path: envs/prod)
Amount:  +$6 ($77 → $83)
Percent: +7%

──────────────────────────────────
Key: * usage cost, ~ changed, + added, - removed
1 project has no cost estimate change.
Run the following command to see its breakdown: infracost breakdown --path=/path/to/code

──────────────────────────────────
*Usage costs were estimated using infracost-usage.yml, see docs for other options.

312 cloud resources were detected:
∙ 130 were estimated
∙ 182 were free

Infracost estimate: Monthly estimate increased by $6 ↑
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Changed project                                    ┃ Baseline cost ┃ Usage cost* ┃ Total change ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━┫
┃ acm-uiuc/core/terraform/envs/prod                  ┃           +$0 ┃         +$6 ┃    +$6 (+7%) ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
This comment will be updated when code changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 28, 2025

Walkthrough

Adds a new Makefile variable current_active_region and threads it into Terraform plans; introduces a new us-west-2 lambdas/sqs deployment in prod; converts frontend inputs to per-region maps and updates the frontend module to create dynamic, region-aware CloudFront origins controlled by CurrentActiveRegion.

Changes

Cohort / File(s) Summary
Makefile region plumbing
Makefile
Added current_active_region = "us-east-2" and passed it into Terraform plan commands for prod and qa via -var="current_active_region=$(current_active_region)".
Env-level Terraform variables
terraform/envs/prod/variables.tf, terraform/envs/qa/variables.tf
Added variable "current_active_region" (type = string) with validation restricting values to ["us-east-2","us-west-2"] and an error_message for invalid inputs.
Prod environment modules
terraform/envs/prod/main.tf
Added module "lambdas_usw2" (region = "us-west-2"), module "sqs_queues_usw2", region-specific locals (e.g., queue_arns_usw2), an event source mapping for us-west-2, and updated the frontend module inputs to accept per-region maps and CurrentActiveRegion.
QA environment frontend wiring
terraform/envs/qa/main.tf
Moved deployment_env into locals, made RunEnvironment use local.deployment_env, and updated module "frontend" to accept CoreLambdaHost and CoreSlowLambdaHost as region maps and added CurrentActiveRegion wired from var.current_active_region.
Frontend module - runtime behavior
terraform/modules/frontend/main.tf
Replaced static Lambda origins with dynamic for_each origins over CoreLambdaHost/CoreSlowLambdaHost; made CloudFront target_origin_id and ordered_cache_behavior entries region-aware using var.CurrentActiveRegion (applies to main and ical distributions).
Frontend module - variable signatures
terraform/modules/frontend/variables.tf
Changed CoreLambdaHost from string to map(string); added CoreSlowLambdaHost as map(string); added CurrentActiveRegion as string.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CF as CloudFront
  participant FrontendTF as Frontend (Terraform config)
  participant Lambda_E as Lambda us-east-2
  participant Lambda_W as Lambda us-west-2

  Note over FrontendTF,CF: Provision time — dynamic origins created per-region
  FrontendTF->>CF: register origins for "us-east-2" and "us-west-2" (origin IDs include region)
  CF-->>FrontendTF: origins created

  Note over User,CF: Runtime request routing
  User->>CF: HTTP request
  alt CurrentActiveRegion = "us-east-2"
    CF->>Lambda_E: route to origin "LambdaFunction-us-east-2"
  else CurrentActiveRegion = "us-west-2"
    CF->>Lambda_W: route to origin "LambdaFunction-us-west-2"
  end
  Lambda_E-->>CF: response
  Lambda_W-->>CF: response
  CF-->>User: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Focus areas:
    • terraform/modules/frontend/main.tf — dynamic origins, ordered_cache_behavior target_origin_id replacements, ical distribution changes.
    • terraform/envs/prod/main.tf — new lambdas_usw2 and sqs_queues_usw2 modules, locals and event source mappings.
    • Interface changes in terraform/modules/frontend/variables.tf and env-level variable additions that affect module inputs.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Make currently active region a terraform parameter" directly and accurately reflects the primary objective of the changeset. The PR introduces current_active_region as a configurable Terraform parameter across the Makefile, prod/qa variables files, and main configuration files, enabling dynamic region selection rather than hardcoded values. The title is concise, specific, and clearly conveys the main change without vague language or noise. While the PR also includes multi-region infrastructure updates (such as us-west-2 support and region-aware routing), these are supportive changes that enable the core objective of making the active region configurable.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dsingh14/multiregion-integration

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 6329407 and 4e6b73a.

📒 Files selected for processing (2)
  • terraform/envs/prod/main.tf (4 hunks)
  • terraform/envs/qa/main.tf (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • terraform/envs/qa/main.tf
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Run Unit Tests
  • GitHub Check: Build Application
🔇 Additional comments (6)
terraform/envs/prod/main.tf (6)

40-43: Queue ARN structure is consistent and well-organized.

The new queue_arns_usw2 local follows the same pattern as the primary region queues, enabling straightforward multi-region event source mapping.


45-45: Centralizing environment configuration improves maintainability.

Extracting the environment name to a local variable makes the configuration more maintainable and ensures consistency across module instantiations.


101-101: RunEnvironment refactored to use centralized local variable.

This change aligns with the introduction of local.deployment_env, reducing duplication and improving maintainability.


110-120: Verify frontend module is compatible with per-region maps and CurrentActiveRegion.

Lines 112–119 change CoreLambdaHost and CoreSlowLambdaHost from scalar values to region maps, which is a breaking change. Ensure the frontend module:

  1. Accepts these inputs as map(string) types
  2. Includes the CurrentActiveRegion input variable
  3. Uses CurrentActiveRegion to select the active endpoint from the maps
  4. Properly handles terraform state migration for existing deployments

150-178: Multi-region modules and resources are well-structured and properly configured.

The new lambdas_usw2, sqs_queues_usw2, and queue_consumer_usw2 resources:

  • Follow consistent patterns with their primary-region counterparts
  • Include explicit depends_on blocks for proper sequencing
  • Use region-specific module outputs correctly (e.g., module.lambdas_usw2.core_sqs_consumer_lambda_arn)
  • Share origin verification keys across regions (appropriate for multi-region failover)

120-120: Variable properly defined with validation.

The current_active_region variable in terraform/envs/prod/variables.tf is correctly defined with type string and includes validation that restricts values to ["us-east-2", "us-west-2"] as required.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
terraform/envs/qa/variables.tf (1)

53-61: Provide more descriptive validation error message and verify default value intent.

The validation error message is generic and doesn't inform users which regions are allowed. Additionally, this variable lacks a default value, which means deployments will fail if not explicitly provided via CLI or a .tfvars file. Verify if this is intentional for safety or an oversight.

For better UX, include the allowed regions in the error message:

-  validation {
-    condition     = contains(["us-east-2", "us-west-2"], var.current_active_region)
-    error_message = "Invalid value for current_active_region"
-  }
+  validation {
+    condition     = contains(["us-east-2", "us-west-2"], var.current_active_region)
+    error_message = "current_active_region must be either 'us-east-2' or 'us-west-2'"
+  }

If a default value is appropriate for this environment, add: default = "us-east-2".

terraform/envs/prod/variables.tf (1)

52-60: Improve validation error message and clarify default value strategy.

Same issue as the QA environment: the error message is not user-friendly. Update to include the allowed regions:

-  validation {
-    condition     = contains(["us-east-2", "us-west-2"], var.current_active_region)
-    error_message = "Invalid value for current_active_region"
-  }
+  validation {
+    condition     = contains(["us-east-2", "us-west-2"], var.current_active_region)
+    error_message = "current_active_region must be either 'us-east-2' or 'us-west-2'"
+  }

Consider adding a default value if appropriate for this environment.

Makefile (1)

4-4: Consider whether hardcoded region aligns with PR objective of "easily switching" regions.

The PR description states the goal is to "allow for easily switching the region currently serving traffic." However, the current_active_region is hardcoded to "us-east-2" in the Makefile (line 4). To enable true runtime flexibility, consider allowing the region to be overridden at invocation time:

-current_active_region = "us-east-2"
+current_active_region ?= "us-east-2"

This allows operators to switch regions via: make deploy_prod current_active_region=us-west-2

Alternatively, if hardcoding is intentional to prevent accidental region switches, document this decision and clarify the intended workflow for changing regions (e.g., via code review and merge).

Also applies to: 52-52, 59-59

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 3fb0821 and 11fcc0b.

📒 Files selected for processing (3)
  • Makefile (2 hunks)
  • terraform/envs/prod/variables.tf (1 hunks)
  • terraform/envs/qa/variables.tf (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build Application
  • GitHub Check: Run Unit Tests

@devksingh4 devksingh4 merged commit 28f5550 into main Oct 29, 2025
10 of 11 checks passed
@devksingh4 devksingh4 deleted the dsingh14/multiregion-integration branch October 29, 2025 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants