Migrate terrifi_firewall_group off go-unifi SDK (#157) - #158
Draft
alexklibisz wants to merge 1 commit into
Draft
Conversation
First step toward replacing the go-unifi SDK with local API contracts (see issue #157). The growing list of SDK workarounds tagged TODO(go-unifi) has been the source of several recent bugs (#147, #151, #154), and roughly half the resources already bypass the SDK for one endpoint or another. firewall_group is the simplest resource still fully using the SDK and a good starting point. Adds a new internal/unifi package that will be the home for locally defined API contracts. For now it holds NotFoundError (replacing unifi.NotFoundError from the SDK) and the FirewallGroup struct. Adds internal/provider/firewall_group_api.go with Create/Get/Update/ Delete/List methods on *Client that hit /api/s/{site}/rest/firewallgroup directly via the existing doV2Request HTTP helper. These shadow the promoted SDK methods on *Client.ApiClient. The resource, its tests, and the generate package all switch from the SDK's unifi.FirewallGroup to the local type. The struct shapes match field-for-field so no model conversion code needed to change. Other resources continue to use the SDK and will be migrated one at a time. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
fdcastel
added a commit
to fdcastel/terraform-provider-terrifi
that referenced
this pull request
May 29, 2026
Adds local internal/unifi.DNSRecord plus internal/provider/dns_record_api.go implementing Create/Get/Update/Delete/List on *Client via the existing doV2Request HTTP layer. Resource, test, and generate files swap from the SDK type to the local one. Continues alexklibisz#158's pattern. A local types.Number-equivalent (unifi.Number) is added because the v2 static-dns endpoint emits port/priority/ttl/weight as either JSON numbers or quoted strings depending on controller version; DNSRecord.UnmarshalJSON coerces both shapes.
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.
Summary
First step toward #157 — drop the go-unifi SDK in favor of locally-defined API contracts and HTTP calls.
internal/unifipackage will be the home for local API types. Currently holdsNotFoundErrorandFirewallGroup.internal/provider/firewall_group_api.goimplementsCreate/Get/Update/Delete/Liston*Clientusing the existingdoV2RequestHTTP layer. These shadow the promoted SDK methods on*Client.ApiClient.firewall_group_resource.go, its tests, andinternal/generate/firewall_group.goswap from the SDK type to the local one (struct shapes match field-for-field, no conversion code changed).firewall_groupwas chosen as the starting point because it's the simplest resource still fully on the SDK (5 schema attrs, 9 SDK fields, no quirky unmarshaling).Test plan
go build ./...cleango test ./...unit tests passTERRIFI_ACC_TARGET=docker task test:acc -- -run TestAccFirewallGroupterrifi generate-importsstill emitsterrifi_firewall_groupblocks against a real controllerNotes
FirewallGroup.GroupMembersis serialized withoutomitempty; the API helper normalizes a nil slice to[]string{}so the controller receives an authoritative empty array when all members are removed.{meta, data}reused via the existingcheckV1Metahelper.*Clientembeds the SDK's*ApiClient; local methods with the same name win at type resolution, confirmed by clean compile across the rest of the codebase.🤖 Generated with Claude Code