Skip to content

fix: stop calling the ssh tunnel when removing ssh_tunnel - #796

Merged
fernando-toledo merged 3 commits into
mainfrom
ftoledo/ssh-tunnel-delete-404
Nov 9, 2026
Merged

fernando-toledo merged 3 commits into
mainfrom
ftoledo/ssh-tunnel-delete-404

Conversation

@fernando-toledo

@fernando-toledo fernando-toledo commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

TL/DR

Removing the ssh_tunnel block of a Postgres or Redshift dbtcloud_global_connection no longer calls the tunnel, because the connection update that comes first already removes it.

Why

Since https://github.com/dbt-labs/dbt-cloud/pull/19697 (hard delete of EncryptionInfo), the server deletes a connection's SSH tunnel as part of the connection update that leaves the tunnel disabled. The provider then called the tunnel to delete it and got 404 resource-not-found, so the apply failed with Error with the SSH Tunnel. This is why TestAccDbtCloudGlobalConnectionPostgresResource and TestAccDbtCloudGlobalConnectionRedshiftResource fail in CI on main and on other PRs.

The call was redundant before that change too: the update already disabled the tunnel, and Read only shows a tunnel while is_ssh_tunnel_enabled is true.

Before

  • Removing ssh_tunnel fails with Error with the SSH Tunnel (404 on POST /v2/accounts/<id>/encryptions/<id>/).

After

  • Removing ssh_tunnel makes one request, the connection update, and the apply succeeds.
  • Adding a tunnel and changing its hostname or port are unchanged, and an error on a tunnel change still fails the apply.

Notes

  • Destroying a connection that still has a tunnel is not covered here: that path deletes the connection and then calls the tunnel, and it also answers 404 on the current server. It needs its own change.
  • Related server change: https://github.com/dbt-labs/dbt-cloud/pull/20030 makes an update with state=2 hard-delete the tunnel, which keeps older provider versions working.

fernando toledo added 2 commits November 6, 2026 11:35
A connection update that leaves the tunnel disabled makes the server
delete the tunnel, so the follow-up call to the tunnel answers 404.
Treat that answer as the tunnel being already gone.
Only an already removed tunnel is accepted when removing ssh_tunnel; a
403 on removal and a 404 on a hostname change still fail the apply.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change that tolerates already-deleted SSH tunnels during removal.

No open issues 🎉

What changed in this PR

This PR makes SSH tunnel removal resilient when dbt Cloud has already deleted the tunnel during a Postgres or Redshift global connection update.

Changes:

  • Accepts resource-not-found errors when deleting a tunnel, without changing create or update error handling.
  • Adds mocked regression tests for successful removal and continued failure on other removal or hostname-change errors.
  • Adds an unreleased changelog entry.
File Description
pkg/​framework/​objects/​global_connection/​resource.go Allows deletion to succeed when the tunnel is already gone.
pkg/​framework/​objects/​global_connection/​resource_ssh_tunnel_unit_test.go Tests removal for both adapters and preserves error-handling coverage.
.changes/​unreleased/​Fixes-20261106-150000.yaml Documents the SSH tunnel removal fix.

Review effort: Balanced

@fernando-toledo
fernando-toledo marked this pull request as ready for review November 6, 2026 16:35
@fernando-toledo
fernando-toledo requested review from a team, tudor-scurtu and victorasu November 6, 2026 17:22

@skapfer skapfer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wondering whether we should just not update the tunnel config at all in the delete path. The connection update already does the job, and the extra encryption_info update seems redundant in every case?

Conceptually, encryption info should be in connection config, not its own resource at the API level. So I think it's OK to omit state updates that serve no purpose.

@@ -1773,7 +1773,8 @@ func (r *globalConnectionResource) handleSSHTunnelUpdates(
State: dbt_cloud.STATE_DELETED,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we still need to POST to the encryptions endpoint? It looks like the connection update precedes the encryption write, so when the SSH tunnel goes away in a TF apply, this will always return 404.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call, I think it makes to avoid the extra call. thanks!

@skapfer

skapfer commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

The connection update that comes first already removes the tunnel, so
the follow-up call to the tunnel is redundant and answers 404 once the
server hard-deletes it. Drop the call and keep the guard on tunnel
changes.
@fernando-toledo fernando-toledo changed the title fix: accept an already removed ssh tunnel when removing ssh_tunnel fix: stop calling the ssh tunnel when removing ssh_tunnel Nov 9, 2026
@fernando-toledo
fernando-toledo merged commit bc66c72 into main Nov 9, 2026
3 of 4 checks passed
@fernando-toledo
fernando-toledo deleted the ftoledo/ssh-tunnel-delete-404 branch November 9, 2026 13:41
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.

4 participants