Skip to content

fix(terraform/cloudflare/k8s): import existing tunnel route via data source (BOXP-135) - #11700

Merged
boxp merged 1 commit into
mainfrom
codex-task-board/BOXP-135-20260728T071919Z-6d118ceb-3ff4-491b-8484-404da83e2d8a
Jul 28, 2026
Merged

fix(terraform/cloudflare/k8s): import existing tunnel route via data source (BOXP-135)#11700
boxp merged 1 commit into
mainfrom
codex-task-board/BOXP-135-20260728T071919Z-6d118ceb-3ff4-491b-8484-404da83e2d8a

Conversation

@boxp

@boxp boxp commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

Changes

  • terraform/cloudflare/b0xp.io/k8s/tunnel.tf: data source + import ブロック追加
  • docs/project_docs/BOXP-135/plan.md: 調査・修正計画ドキュメント

How It Works

  1. data "cloudflare_zero_trust_tunnel_cloudflared_route" "codex_workspace"network_subset = network_superset = "192.168.10.98/32" でフィルタリングし、Cloudflare API から既存 route の UUID を取得
  2. import ブロックが {account_id}/{route_uuid} 形式で route を Terraform state に取り込む
  3. 初回 apply 成功後、import ブロックは idempotent (no-op)
  4. データソースと import ブロックは後続の PR で削除可能

Test Plan

References

🤖 Generated with Claude Code

…source (BOXP-135)

The v4→v5 provider migration (PR #11342) removed
cloudflare_zero_trust_tunnel_route.codex_workspace from state via
tfmigrate but never imported the v5 equivalent, causing every apply to
attempt creating the 192.168.10.98/32 route and receive a 409 Conflict
from Cloudflare (error 1014: route already exists).

Fix: add a cloudflare_zero_trust_tunnel_cloudflared_route data source
filtered by network_subset/superset to look up the existing route UUID,
then use an import block to bring it into state under the v5 resource
name. The data source exists in provider v5.22.0 (confirmed via
provider.go registration).

After a successful apply the import block becomes a no-op; a follow-up
PR can remove the data source and import block.

Closes follow-up PRs: #11621, #11675

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@boxp
boxp force-pushed the codex-task-board/BOXP-135-20260728T071919Z-6d118ceb-3ff4-491b-8484-404da83e2d8a branch from 766f812 to fd9154e Compare July 28, 2026 07:38
@boxp-tfaction

boxp-tfaction Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Plan Result (terraform/cloudflare/b0xp.io/k8s)

CI link

Plan: 1 to import, 0 to add, 1 to change, 0 to destroy.
  • Update
    • cloudflare_zero_trust_device_default_profile.warp_include
  • Import
    • cloudflare_zero_trust_tunnel_cloudflared_route.codex_workspace
Change Result (Click me)
  # cloudflare_zero_trust_device_default_profile.warp_include will be updated in-place
  ~ resource "cloudflare_zero_trust_device_default_profile" "warp_include" {
        id                             = "1984a4314b3e75f3bedce97c7a8e0c81"
      ~ policy_id                      = "0197d1b3-fe50-7488-8b3d-55f27f26ea8b" -> (known after apply)
        # (20 unchanged attributes hidden)
    }

  # cloudflare_zero_trust_tunnel_cloudflared_route.codex_workspace will be imported
    resource "cloudflare_zero_trust_tunnel_cloudflared_route" "codex_workspace" {
        account_id         = "1984a4314b3e75f3bedce97c7a8e0c81"
        comment            = "lolice codex-workspace LoadBalancer for WARP access"
        created_at         = "2026-05-29T12:29:24Z"
        id                 = "6b22520e-ad37-4864-8e43-842ff88fa48a"
        network            = "192.168.10.98/32"
        tunnel_id          = "0eb241e1-1295-4672-8285-f18241a38210"
        virtual_network_id = "9bcd88ee-63e3-476b-bf2a-0f685c18cdd6"
    }

Plan: 1 to import, 0 to add, 1 to change, 0 to destroy.

Warning: Redundant ignore_changes element

  on tunnel.tf line 12, in resource "cloudflare_zero_trust_tunnel_cloudflared_config" "k8s_tunnel":
  12: resource "cloudflare_zero_trust_tunnel_cloudflared_config" "k8s_tunnel" {

Adding an attribute name to ignore_changes tells Terraform to ignore future
changes to the argument in configuration after the object has been created,
retaining the value originally configured.

The attribute created_at is decided by the provider alone and therefore there
can be no configured value to compare with. Including this attribute in
ignore_changes has no effect. Remove the attribute from ignore_changes to
quiet this warning.

(and one more similar warning elsewhere)

⚠️ Warnings

Warning: Redundant ignore_changes element

  on tunnel.tf line 12, in resource "cloudflare_zero_trust_tunnel_cloudflared_config" "k8s_tunnel":
  12: resource "cloudflare_zero_trust_tunnel_cloudflared_config" "k8s_tunnel" {

Adding an attribute name to ignore_changes tells Terraform to ignore future
changes to the argument in configuration after the object has been created,
retaining the value originally configured.

The attribute created_at is decided by the provider alone and therefore there
can be no configured value to compare with. Including this attribute in
ignore_changes has no effect. Remove the attribute from ignore_changes to
quiet this warning.

(and one more similar warning elsewhere)

@boxp
boxp merged commit c2547c1 into main Jul 28, 2026
13 checks passed
@boxp
boxp deleted the codex-task-board/BOXP-135-20260728T071919Z-6d118ceb-3ff4-491b-8484-404da83e2d8a branch July 28, 2026 08:19
@boxp-tfaction

boxp-tfaction Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

✅ Apply Succeeded (terraform/cloudflare/b0xp.io/k8s)

CI link

Apply complete! Resources: 1 imported, 0 added, 1 changed, 0 destroyed.
Details (Click me)
Jul 28 08:20:54.016 WRN The policy file is ignored unless it is allowed by "aqua policy allow" command.

$ aqua policy allow "/home/runner/work/arch/arch/aqua/aqua-policy.yaml"

If you want to keep ignoring the policy file without the warning, please run "aqua policy deny" command.

$ aqua policy deny "/home/runner/work/arch/arch/aqua/aqua-policy.yaml"

  program=aqua version=2.62.1 env=linux/amd64 exe_name=terraform package_name=hashicorp/terraform package_version=v1.15.8 registry=standard policy_file=/home/runner/work/arch/arch/aqua/aqua-policy.yaml doc=https://aquaproj.github.io/docs/reference/codes/003
cloudflare_zero_trust_tunnel_cloudflared_route.codex_workspace: Importing... [id=1984a4314b3e75f3bedce97c7a8e0c81/6b22520e-ad37-4864-8e43-842ff88fa48a]
cloudflare_zero_trust_tunnel_cloudflared_route.codex_workspace: Import complete [id=1984a4314b3e75f3bedce97c7a8e0c81/6b22520e-ad37-4864-8e43-842ff88fa48a]
cloudflare_zero_trust_device_default_profile.warp_include: Modifying... [id=1984a4314b3e75f3bedce97c7a8e0c81]
cloudflare_zero_trust_device_default_profile.warp_include: Modifications complete after 0s [id=1984a4314b3e75f3bedce97c7a8e0c81]

Apply complete! Resources: 1 imported, 0 added, 1 changed, 0 destroyed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant