feat(config): add firewall-group cross-resource references#15
feat(config): add firewall-group cross-resource references#15devantler wants to merge 3 commits into
Conversation
Add Crossplane cross-resource references for unifi_firewall_rule and unifi_firewall_policy so a rule/policy can point at a FirewallGroup, Network, or FirewallZone by name via the generated *Ref/*Selector companions instead of a hard-coded post-reconcile UniFi id. The raw id fields stay settable, so the change is purely additive. - firewall_rule: src/dst_firewall_group_ids (list) -> Group, src/dst_network_id -> Network - firewall_policy: source/destination.network_ids (list) -> Network, source/destination.zone_id -> FirewallZone (nested under the single-nested source/destination blocks, not top-level as the issue table assumed) Generated on Linux (upjet make generate); deltas are firewall-scoped only. Adds an example wiring a Rule to a Group and Network by *Ref. Part of #10 Fixes #11
📝 WalkthroughWalkthroughThis PR adds Crossplane reference and selector support for firewall Policy and Rule resources in both cluster-scoped and namespaced APIs. Generated types gain new Related issues: Suggested labels: generated, api-change, firewall Suggested reviewers: devantler 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
✅
|
goconst flags unifi_network (now 5 occurrences across shortGroups keys and the new firewall references). Pull the referenced Terraform resource names out as constants so each literal appears once. Reference values are unchanged, so the generated output is identical (no regeneration).
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@config/unifi/config.go`:
- Around line 74-83: The new resource-name constants are only used in the
cross-resource references, while shortGroups in config/unifi/config.go still
repeats the same string literals. Update the shortGroups map entries to use
resFirewallGroup, resFirewallZone, resNetwork, and resVPNClient so all
references to these resource names share the same constants and the duplicate
literals are removed consistently.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 45e26328-14d8-45ec-aa56-4113869dd701
📒 Files selected for processing (1)
config/unifi/config.go
📜 Review details
⏰ Context from checks skipped due to timeout. (14)
- GitHub Check: 🧪 Test
- GitHub Check: 🔍 Dead Code Analysis
- GitHub Check: 📊 Code Coverage
- GitHub Check: 🏗️ Build
- GitHub Check: 🧹 Lint - mega-linter
- GitHub Check: 📦 Tidy
- GitHub Check: 🧹 Lint - golangci-lint
- GitHub Check: 🛡️ Vulnerability Scan
- GitHub Check: check-diff
- GitHub Check: unit-tests
- GitHub Check: lint
- GitHub Check: local-deploy
- GitHub Check: Analyze (go)
- GitHub Check: Analyze (python)
🧰 Additional context used
📓 Path-based instructions (1)
config/unifi/config.go
📄 CodeRabbit inference engine (AGENTS.md)
Use
config/unifi/config.goto define resource grouping (ShortGroups) and Kind disambiguation.
Files:
config/unifi/config.go
🔇 Additional comments (4)
config/unifi/config.go (4)
74-83: LGTM on the constant extraction.Clean deduplication of repeated Terraform resource-name literals for goconst compliance.
97-102: LGTM!
104-122: Reference wiring forunifi_firewall_rulematches the issue requirements.
src_firewall_group_ids/dst_firewall_group_ids→unifi_firewall_group, andsrc_network_id/dst_network_id→unifi_network, aligning with issue#11's spec.
124-142: Nested reference paths forunifi_firewall_policylook correct.Keying by
source.network_ids/source.zone_idanddestination.network_ids/destination.zone_idmatches the documented upjet pattern for referencing fields nested in single-nested blocks (e.g., thezone_mappings.vswitch_idexample used elsewhere in the upjet ecosystem), and correctly targetsunifi_network/unifi_firewall_zone.
Switch the shortGroups map keys for firewall_group, firewall_zone, network, and vpn_client to the resFirewallGroup/resFirewallZone/ resNetwork/resVPNClient constants so each resource name has a single source of truth instead of a repeated string literal. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Good catch — applied in |

Why
Firewall resources reference other UniFi objects (groups, networks, zones) by raw ID strings a user
can only know after those objects reconcile — the same wiring pain that cross-resource references
already solved for traffic routes. The firewall group is the densest cluster of these references and
the natural next place to remove that friction.
What
Adds Crossplane cross-resource references to
firewall_ruleandfirewall_policyso a rule/policycan point at a FirewallGroup, Network, or FirewallZone by name (via the generated
*Ref/*Selectorcompanions) instead of a hard-coded post-create id. The raw id fields stay settable directly, so this
is purely additive — no behaviour change for existing manifests.
First reviewable increment of the cross-resource-references theme; sibling resources follow as
separate children.
Part of #10
Fixes #11