fix(registry): region-scope hcloud/cloudflare provider URNs#149
Merged
Conversation
program.Run builds one provider registry per realization scope — one per region plus the region-less global slice — all over the same Pulumi context. Each registry lazily registered its hcloud and cloudflare *provider* resources under the fixed names "hcloud"/"cloudflare", so once a config realized Hetzner/Cloudflare resources in more than one scope the two registrations collided on URN and failed the whole preview with `Duplicate resource URN '…::pulumi:providers:hcloud::hcloud'`. Scope the provider resource names by region (`hcloud-<region>`, `cloudflare-<region>`); r.region is "global" for the global slice and the region name otherwise, so it is always present and unique per scope. Add a regression test that builds two registries over one context and asserts the provider names are unique per scope (the Pulumi mock monitor does not itself reject duplicate URNs), and a rule documenting the invariant for future singleton providers added to the registry. Claude-Session: https://claude.ai/code/session_017Kyd98NzojozMZ19d5UCZ2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
inforge previewfails for any environment that realizes Hetzner/Cloudflare resources in more than one scope with:program.Runbuilds one provider registry per realization scope — one per region plus the region-less global slice — all over the same Pulumi context. Each registry lazily registered its singletonhcloudandcloudflareprovider resources under the fixed names"hcloud"/"cloudflare". The first config to place Hetzner/Cloudflare resources in two scopes (e.g. a global compute host and a regional one) registers the same provider twice under one URN, and Pulumi fails the whole run before touching any resource.This surfaced on wardnet-infrastructure#31, the first config with both a global (
tenants) and a regional (edge) Hetzner host. Cloudflare had the identical latent collision (both scopes realize DNS) — it just hadn't surfaced because compute is created before DNS.Fix
Scope the provider resource name by region:
fmt.Sprintf("hcloud-%s", r.region)/cloudflare-%s.r.regionis"global"for the global slice and the region name otherwise, so it is always present and unique per scope. The neon/infisical adapters are unaffected — they register per-resource names, not singleton providers.Testing
TestProviderResourceNamesAreScopePerRegistrybuilds two registries (global + a region) over one Pulumi context and asserts each provider type is registered under distinct names. (The Pulumi mock monitor does not itself reject duplicate URNs, so the test asserts the name-uniqueness invariant directly — this is also why the bug was invisible to the priornil-ctx registry test.) Verified failing pre-fix (got [hcloud hcloud]) and passing post-fix..agents/rules/registry-provider-names-are-region-scoped.mddocumenting the invariant for future singleton providers.go build ./...,go test -race ./...,golangci-lint run ./...all clean.Note
This changes the provider URN, which would force provider (and cascading resource) replacement on any pre-existing single-region stack. Confirmed with the maintainer that no such live stacks exist, so no
pulumi.Aliasesmigration shim is needed.Merge Commit Message
fix(registry): region-scope hcloud/cloudflare provider URNs
https://claude.ai/code/session_017Kyd98NzojozMZ19d5UCZ2