Skip to content

fix: prevent port 8000 wipe by avoiding ForceNew on InstancePublicPorts#42

Merged
aliasunder merged 2 commits into
mainfrom
fix/lightsail-ports-forcenew
May 18, 2026
Merged

fix: prevent port 8000 wipe by avoiding ForceNew on InstancePublicPorts#42
aliasunder merged 2 commits into
mainfrom
fix/lightsail-ports-forcenew

Conversation

@aliasunder
Copy link
Copy Markdown
Owner

@aliasunder aliasunder commented May 18, 2026

Summary

  • port_info is ForceNew in the Pulumi/Terraform AWS provider — adding or removing entries triggers a resource replacement (delete → create). The default create-before-delete order causes the delete step to wipe the newly created ports because PutInstancePublicPorts is a replace-all API. This is a known Pulumi bug
  • PR feat: restrict SSH to Tailscale with configurable firewall CIDRs #40's approach removed the port 22 entry when SSH_CIDRS=none, triggering replacement and leaving port 8000 closed (503 on healthcheck)

Fix (two layers)

  1. Always keep both port entries — map SSH_CIDRS=none to a non-routable CIDR (192.0.2.1/32, RFC 5737 TEST-NET) instead of removing the entry. Since cidrs is NOT ForceNew, this is an in-place update — no replacement ever triggered
  2. Add deleteBeforeReplace: true — safety net for any future replacement trigger. Reverses the order to delete-old → create-new so the create happens last and sticks

Test plan

  • npm run build + npm run lint + npm test pass
  • Deploy with SSH_CIDRS unset → both ports open at 0.0.0.0/0
  • Deploy with SSH_CIDRS=none → port 22 CIDRs set to 192.0.2.1/32, port 8000 unchanged at 0.0.0.0/0
  • Healthcheck passes after both deploys
  • Verify via aws lightsail get-instance-port-states that both ports are always present

🤖 Generated with Claude Code

port_info is ForceNew in the Pulumi/Terraform AWS provider — adding or
removing entries triggers a resource replacement. The default
create-before-delete order causes the delete step to wipe ports set by
the create (PutInstancePublicPorts is a replace-all API). This is a
known issue (pulumi/pulumi-aws#1511).

Two-layer fix:
1. Always keep both port entries — map SSH_CIDRS=none to a non-routable
   CIDR (192.0.2.1/32, RFC 5737 TEST-NET) instead of removing the
   entry. Only cidrs changes, which is NOT ForceNew.
2. Add deleteBeforeReplace as a safety net — if a replacement is ever
   triggered by other changes, delete-old runs first so create-new
   sets the final state correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aliasunder aliasunder force-pushed the fix/lightsail-ports-forcenew branch from b57d08e to 0c200ce Compare May 18, 2026 18:01
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aliasunder aliasunder force-pushed the fix/lightsail-ports-forcenew branch from 0c200ce to 099e28b Compare May 18, 2026 18:03
@aliasunder aliasunder merged commit 6ea57b2 into main May 18, 2026
2 checks passed
@aliasunder aliasunder deleted the fix/lightsail-ports-forcenew branch May 18, 2026 18:03
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