Skip to content

feat(terraform): add BYOIP support for all devnet instances#734

Merged
ktechmidas merged 1 commit intov1.0-devfrom
infra/byoip
Mar 2, 2026
Merged

feat(terraform): add BYOIP support for all devnet instances#734
ktechmidas merged 1 commit intov1.0-devfrom
infra/byoip

Conversation

@ktechmidas
Copy link
Contributor

@ktechmidas ktechmidas commented Feb 28, 2026

Summary

  • Adds byoip_pool_id terraform variable — when set, all instance types get EIPs allocated from the specified IPAM pool
  • Creates EIP + association resources for masternodes (amd/arm), web, wallet, seed, and miner instances
  • Updates existing HP masternode and VPN EIPs to use the pool when configured
  • Updates inventory and services outputs to use EIP addresses when BYOIP is active

Usage

In a devnet tfvars file:

byoip_pool_id = "ipam-pool-0de83ed8bba5f9b48"

When not set (default ""), behavior is unchanged.

Test plan

  • Deploy a devnet with byoip_pool_id set and verify all instances get 68.67.122.x addresses
  • Deploy a devnet without byoip_pool_id and verify existing behavior is unchanged
  • Verify inventory output contains correct EIP addresses

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added Bring Your Own IP (BYOIP) support for all instance types. When configured with an IPAM pool ID, instances automatically use allocated addresses from your custom IP pool instead of default public addresses.

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

📝 Walkthrough

Walkthrough

This pull request introduces BYOIP (Bring Your Own IP) support to the Terraform AWS infrastructure. A new byoip_pool_id variable enables conditional allocation of Elastic IPs from BYOIP pools across multiple instance types. EIP creation logic is extended to masternode, web, wallet, seed, and miner instances, and output references are updated to select EIPs from BYOIP pools when available, falling back to instance public IPs otherwise.

Changes

Cohort / File(s) Summary
BYOIP Variable Definition
terraform/aws/variables.tf
Added byoip_pool_id variable with description and empty string default to control BYOIP pool allocation.
EIP Resource Expansion
terraform/aws/instances.tf
Extended existing HP masternode EIP resources to support BYOIP via updated count conditions. Introduced new EIP and EIP association resources for masternode amd/arm, web, wallet, seed, and miner instance types, each tied to byoip_pool_id non-empty condition with public_ipv4_pool attribute set accordingly.
DNS and VPN Configuration
terraform/aws/main.tf
Updated DNS IP selection logic in random_shuffle to use combined condition (create_eip OR byoip_pool_id) for determining EIP vs. instance public IP sources. Added public_ipv4_pool attribute to VPN EIP resource.
Inventory Output Configuration
terraform/aws/ansible_inventory_output.tf
Updated public IP selection across host groups (web, dashd_wallet, seed_node, miner, masternode, hp_masternode variants) to conditionally use BYOIP EIPs when available, otherwise fall back to instance public IPs.
Service Output Configuration
terraform/aws/services_output.tf
Extended conditional EIP-based IP selection to additional service blocks (masternode, hp_masternode, wallet, seed, miner, dashd_wallet) using combined BYOIP/EIP creation conditions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Through BYOIP pools, we hopped with glee,
Elastic IPs for all, from ARM to x86,
Each instance type now has a choice so neat,
Fall back gracefully when pools aren't complete! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the primary change: adding BYOIP support for all devnet instances in Terraform, which aligns with the comprehensive changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch infra/byoip

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

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

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
terraform/aws/services_output.tf (1)

248-252: ⚠️ Potential issue | 🟡 Minor

Copy-paste bug: ARM masternode incorrectly named "amd".

The hp_masternodes_arm block uses "hp-masternode-amd-${n + 1}" instead of "hp-masternode-arm-${n + 1}".

🐛 Proposed fix
 hp_masternodes_arm = [
   for n in range(length(aws_instance.hp_masternode_arm)) : templatefile(
     "${path.module}/templates/services/node.tpl",
     {
-      name = "hp-masternode-amd-${n + 1}"
+      name = "hp-masternode-arm-${n + 1}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@terraform/aws/services_output.tf` around lines 248 - 252, The
hp_masternodes_arm list comprehension incorrectly sets the generated name string
to "hp-masternode-amd-${n + 1}"; update the templatefile argument in the
hp_masternodes_arm block so the name value reads "hp-masternode-arm-${n + 1}"
(i.e., replace "amd" with "arm") to match the block identifier
hp_masternodes_arm and ensure correct naming for ARM masternodes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ansible/deploy.yml`:
- Line 338: Change the HP masternode play's top-level setting from gather_facts:
true back to gather_facts: false (restore fast-deploy behavior), and if specific
facts are needed move those collects into pre_tasks; also ensure the play
includes the dashmate_deploy tag and sets strategy: free to allow parallel fast
deployments (look for the play block labeled for the HP masternode or the
gather_facts entry in ansible/deploy.yml to update these keys).

---

Outside diff comments:
In `@terraform/aws/services_output.tf`:
- Around line 248-252: The hp_masternodes_arm list comprehension incorrectly
sets the generated name string to "hp-masternode-amd-${n + 1}"; update the
templatefile argument in the hp_masternodes_arm block so the name value reads
"hp-masternode-arm-${n + 1}" (i.e., replace "amd" with "arm") to match the block
identifier hp_masternodes_arm and ensure correct naming for ARM masternodes.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3cf17de and 0c219e7.

📒 Files selected for processing (7)
  • INFRA.MD
  • ansible/deploy.yml
  • terraform/aws/ansible_inventory_output.tf
  • terraform/aws/instances.tf
  • terraform/aws/main.tf
  • terraform/aws/services_output.tf
  • terraform/aws/variables.tf

hosts: hp_masternodes
become: true
gather_facts: false
gather_facts: true
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Revert HP masternode play to gather_facts: false

Line 338 currently enables full fact gathering, which breaks the fast-deploy contract for ansible/deploy.yml. Keep gather_facts: false and gather only minimal required facts in pre_tasks if needed.

Suggested patch
-  gather_facts: true
+  gather_facts: false
@@
   pre_tasks:
+    - name: Gather minimal OS facts needed by roles
+      ansible.builtin.setup:
+        gather_subset:
+          - min
+        filter:
+          - ansible_os_family
     - name: Check inventory for HP masternodes
       ansible.builtin.set_fact:
         node: "{{ hp_masternodes[inventory_hostname] }}"

As per coding guidelines, "ansible/deploy.yml: Add dashmate_deploy tag, set gather_facts: false, and use strategy: free in ansible/deploy.yml to enable fast, parallel deployments".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ansible/deploy.yml` at line 338, Change the HP masternode play's top-level
setting from gather_facts: true back to gather_facts: false (restore fast-deploy
behavior), and if specific facts are needed move those collects into pre_tasks;
also ensure the play includes the dashmate_deploy tag and sets strategy: free to
allow parallel fast deployments (look for the play block labeled for the HP
masternode or the gather_facts entry in ansible/deploy.yml to update these
keys).

When byoip_pool_id is set, all instances (masternodes, HP masternodes,
web, wallet, seed, miner, VPN) get EIPs allocated from the specified
IPAM pool instead of auto-assigned AWS public IPs. This gives devnets
stable, predictable IPs from our own address space.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
terraform/aws/services_output.tf (1)

248-252: ⚠️ Potential issue | 🟡 Minor

Bug: Incorrect name for ARM HP masternode in services output.

Line 252 names ARM HP masternodes as "hp-masternode-amd-${n + 1}" instead of "hp-masternode-arm-${n + 1}". This appears to be a pre-existing bug, but worth fixing while touching this file.

Proposed fix
 hp_masternodes_arm = [
  for n in range(length(aws_instance.hp_masternode_arm)) : templatefile(
    "${path.module}/templates/services/node.tpl",
    {
-      name = "hp-masternode-amd-${n + 1}"
+      name = "hp-masternode-arm-${n + 1}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@terraform/aws/services_output.tf` around lines 248 - 252, In
hp_masternodes_arm output generation change the mistaken instance name string:
update the name passed into templatefile for the hp_masternodes_arm list
(currently "hp-masternode-amd-${n + 1}") to the correct "hp-masternode-arm-${n +
1}" so ARM nodes are labeled correctly; modify the name literal in the
hp_masternodes_arm for-expression that calls templatefile.
🧹 Nitpick comments (1)
terraform/aws/main.tf (1)

358-374: Consider extracting the repeated concat expression into a local.

The same concat expression appears three times. Extracting it to a local variable would improve readability and maintainability.

Suggested refactor
+locals {
+  hpmn_ips = concat(
+    (var.create_eip || var.byoip_pool_id != "") ? aws_eip.hpmn_arm_eip.*.public_ip : aws_instance.hp_masternode_arm.*.public_ip,
+    (var.create_eip || var.byoip_pool_id != "") ? aws_eip.hpmn_amd_eip.*.public_ip : aws_instance.hp_masternode_amd.*.public_ip
+  )
+}
+
 resource "random_shuffle" "dns_ips" {
-  input = concat(
-    (var.create_eip || var.byoip_pool_id != "") ? aws_eip.hpmn_arm_eip.*.public_ip : aws_instance.hp_masternode_arm.*.public_ip,
-    (var.create_eip || var.byoip_pool_id != "") ? aws_eip.hpmn_amd_eip.*.public_ip : aws_instance.hp_masternode_amd.*.public_ip
-  )
-  result_count = length(
-    concat(
-      (var.create_eip || var.byoip_pool_id != "") ? aws_eip.hpmn_arm_eip.*.public_ip : aws_instance.hp_masternode_arm.*.public_ip,
-      (var.create_eip || var.byoip_pool_id != "") ? aws_eip.hpmn_amd_eip.*.public_ip : aws_instance.hp_masternode_amd.*.public_ip
-    )
-  ) > local.dns_record_length ? local.dns_record_length : length(
-    concat(
-      (var.create_eip || var.byoip_pool_id != "") ? aws_eip.hpmn_arm_eip.*.public_ip : aws_instance.hp_masternode_arm.*.public_ip,
-      (var.create_eip || var.byoip_pool_id != "") ? aws_eip.hpmn_amd_eip.*.public_ip : aws_instance.hp_masternode_amd.*.public_ip
-    )
-  )
+  input        = local.hpmn_ips
+  result_count = min(length(local.hpmn_ips), local.dns_record_length)
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@terraform/aws/main.tf` around lines 358 - 374, The repeated concat(...)
expression used inside resource random_shuffle.dns_ips should be extracted into
a local variable (e.g., local.dns_inputs) to avoid duplication; update the
resource to reference that local for input and for computing result_count
(replace the three concat(...) uses with local.dns_inputs and use
length(local.dns_inputs) where needed), and ensure the ternary conditions remain
identical to preserve behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@terraform/aws/services_output.tf`:
- Around line 248-252: In hp_masternodes_arm output generation change the
mistaken instance name string: update the name passed into templatefile for the
hp_masternodes_arm list (currently "hp-masternode-amd-${n + 1}") to the correct
"hp-masternode-arm-${n + 1}" so ARM nodes are labeled correctly; modify the name
literal in the hp_masternodes_arm for-expression that calls templatefile.

---

Nitpick comments:
In `@terraform/aws/main.tf`:
- Around line 358-374: The repeated concat(...) expression used inside resource
random_shuffle.dns_ips should be extracted into a local variable (e.g.,
local.dns_inputs) to avoid duplication; update the resource to reference that
local for input and for computing result_count (replace the three concat(...)
uses with local.dns_inputs and use length(local.dns_inputs) where needed), and
ensure the ternary conditions remain identical to preserve behavior.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c219e7 and c1a0c58.

📒 Files selected for processing (5)
  • terraform/aws/ansible_inventory_output.tf
  • terraform/aws/instances.tf
  • terraform/aws/main.tf
  • terraform/aws/services_output.tf
  • terraform/aws/variables.tf
🚧 Files skipped from review as they are similar to previous changes (2)
  • terraform/aws/ansible_inventory_output.tf
  • terraform/aws/variables.tf

Copy link
Collaborator

@vivekgsharma vivekgsharma left a comment

Choose a reason for hiding this comment

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

LGTM

@ktechmidas ktechmidas merged commit 5d5f249 into v1.0-dev Mar 2, 2026
2 checks passed
@ktechmidas ktechmidas deleted the infra/byoip branch March 2, 2026 16:14
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