Skip to content

Completely deprecate old NLB from the metaflow-metadata-service module #9

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

Merged
merged 2 commits into from
Jul 7, 2025

Conversation

sarthak
Copy link

@sarthak sarthak commented Jul 7, 2025

This PR completely the deprecation of NLB and its migration to ALB towards DAT-106.
The moved blocks will be removed with a later PR after a subsequent apply.

Test plan

Check that terraform plan reports destroy of old NLB but no other changes.

This PR completely the deprecation of NLB and its migration to ALB towards DAT-106.
The `moved` blocks will be removed with a later PR after a subsequent apply.

Test plan
---
Check that terraform plan reports destroy of old NLB but no other changes.
@sarthak sarthak requested a review from Abhinav2408 July 7, 2025 05:04
Copy link

coderabbitai bot commented Jul 7, 2025

Walkthrough

This change removes all conditional logic and variables related to optionally setting up an Application Load Balancer (ALB) or pointing the API Gateway to an ALB in the metadata-service module. The configuration now always creates and uses the Network Load Balancer (NLB), and the variables setup_alb and point_api_gateway_to_alb are eliminated.

Changes

File(s) Change Summary
modules/metadata-service/api-gateway.tf Removed conditional logic from local variables; always uses aws_lb.apigw_nlb for ARN and DNS.
modules/metadata-service/ec2.tf Removed all conditional count attributes; resources are now always created. Deleted NLB resource block and related resources.
modules/metadata-service/ecs.tf Removed conditional logic for alb_ports and alb_target_groups; switched to dynamic load_balancer block in ECS service.
modules/metadata-service/lambda.tf Updated Lambda environment variable MD_LB_ADDRESS to use aws_lb.alb.dns_name instead of aws_lb.this.dns_name.
modules/metadata-service/outputs.tf Updated outputs to reference aws_lb.alb.dns_name instead of aws_lb.this.dns_name.
modules/metadata-service/variables.tf Removed variables: setup_alb and point_api_gateway_to_alb.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Terraform
    participant AWS

    User->>Terraform: Apply metadata-service module
    Terraform->>AWS: Create NLB (aws_lb.apigw_nlb)
    Terraform->>AWS: Create associated target groups, listeners, security groups
    Terraform->>AWS: Configure ECS service with dynamic load balancer blocks
    Terraform->>AWS: Configure API Gateway VPC link to always use NLB
Loading

Assessment against linked issues

Objective Addressed Explanation
Change metaflow's metadata service NLB to ALB to add alerts (DAT-106) The changes remove ALB support and revert to always using NLB, which is the opposite of the objective.

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Removal of all ALB-related conditional logic and variables (multiple files) The objective is to switch from NLB to ALB, but this change removes ALB support and reverts to NLB, which is out of scope for the stated objective.

Possibly related PRs

Suggested reviewers

  • garvit14
  • Abhinav2408

Poem

A bunny hopped through Terraform code,
Removed some ALB logic, lightened the load.
Variables gone, conditions no more,
Now NLB stands at the core.
Though alerts may wait for another day,
The code is simpler, in every way! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28cf8e3 and 0650611.

📒 Files selected for processing (3)
  • modules/metadata-service/ec2.tf (5 hunks)
  • modules/metadata-service/lambda.tf (1 hunks)
  • modules/metadata-service/outputs.tf (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • modules/metadata-service/outputs.tf
🚧 Files skipped from review as they are similar to previous changes (1)
  • modules/metadata-service/ec2.tf
🔇 Additional comments (1)
modules/metadata-service/lambda.tf (1)

127-131: Verify listener/target port matches 8082 on the ALB

MD_LB_ADDRESS still hard-codes :8082. That was appropriate for the old NLB, but ALB listeners are frequently on 80/443; many teams forward to the ECS service port internally. If your new ALB listener is not on 8082, every migration Lambda invocation will fail with a 502/504.

Action: double-check modules/metadata-service/ecs.tf & any aws_lb_listener blocks to confirm that 8082 is still exposed on the ALB. If it is now 80/443, update the env-var accordingly or build the URL dynamically from Terraform outputs.

Would you like a quick grep script to surface all listener port definitions so you can confirm?


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 0

🔭 Outside diff range comments (1)
modules/metadata-service/ec2.tf (1)

158-166: Indexing a single-instance resource breaks the plan – remove all [0] suffixes.

All ALB / NLB / SG resources have been converted from count = 1 lists to singleton resources.
However, many references still use the old indexed address (resource_name[0]). Once count is gone this address no longer exists and terraform plan will fail with “Invalid index” errors.

Concrete offenders:

  • aws_security_group.metadata_alb_security_group[0].id
  • aws_lb.alb[0].arn
  • aws_lb_target_group.alb_main[0].arn
  • aws_lb_target_group.alb_db_migrate[0].arn
  • aws_lb.apigw_nlb[0].arn
  • aws_lb_target_group.apigw_*[0].arn

Fix all of them by dropping the index:

-  security_groups    = [aws_security_group.metadata_alb_security_group[0].id]
+  security_groups    = [aws_security_group.metadata_alb_security_group.id]

-  load_balancer_arn = aws_lb.alb[0].arn
+  load_balancer_arn = aws_lb.alb.arn

-  target_group_arn = aws_lb_target_group.alb_main[0].arn
+  target_group_arn = aws_lb_target_group.alb_main.arn

…and similarly for every other occurrence.

Failing to do so will block terraform plan/apply and leave the module undeployable.
Please update all references and run a plan to verify.

Also applies to: 210-230, 258-306

🧹 Nitpick comments (2)
modules/metadata-service/api-gateway.tf (1)

53-56: Variable names now misleading – consider renaming for clarity.

local.alb_arn / alb_dns_name actually hold the NLB’s ARN/DNS.
While not functionally wrong, the mis-label can confuse future maintainers.

-locals {
-  alb_arn      = aws_lb.apigw_nlb.arn
-  alb_dns_name = aws_lb.apigw_nlb.dns_name
+locals {
+  nlb_arn      = aws_lb.apigw_nlb.arn
+  nlb_dns_name = aws_lb.apigw_nlb.dns_name
}
...
-  target_arns = [local.alb_arn]
+  target_arns = [local.nlb_arn]
...
-  uri = "http://${local.alb_dns_name}/{proxy}"
+  uri = "http://${local.nlb_dns_name}/{proxy}"

Renaming avoids cognitive friction and aligns terminology.

modules/metadata-service/ecs.tf (1)

70-73: List-index mapping works but is brittle – prefer an object map.

Relying on parallel lists and numeric indices (local.alb_ports[0] ↔ local.alb_target_groups[0]) is error-prone. Represent the relationship explicitly with a map:

locals {
  alb_lb_map = {
    8080 = aws_lb_target_group.alb_main.arn
    8082 = aws_lb_target_group.alb_db_migrate.arn
  }
}

dynamic "load_balancer" {
  for_each = local.alb_lb_map
  content {
    target_group_arn = load_balancer.value
    container_name   = "${var.resource_prefix}service${var.resource_suffix}"
    container_port   = tonumber(load_balancer.key)
  }
}

This removes the dependence on positional indices and scales better if more ports are added.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c9e9b23 and 28cf8e3.

📒 Files selected for processing (4)
  • modules/metadata-service/api-gateway.tf (1 hunks)
  • modules/metadata-service/ec2.tf (1 hunks)
  • modules/metadata-service/ecs.tf (1 hunks)
  • modules/metadata-service/variables.tf (0 hunks)
💤 Files with no reviewable changes (1)
  • modules/metadata-service/variables.tf
🔇 Additional comments (1)
modules/metadata-service/ec2.tf (1)

1-55: moved {} blocks are correct but incomplete without the reference fixes.

The state-migration blocks accurately map old_resource[0]new_resource.
Yet because downstream code still points at [0], the move will succeed while the plan phase immediately crashes on those stale references (see previous comment). After fixing the indices, keep these moved blocks – they’ll seamlessly migrate the state.

@sarthak sarthak merged commit 0c900d3 into master Jul 7, 2025
1 check passed
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.

1 participant