Skip to content

Migrate terrifi_firewall_group off go-unifi SDK (#157) - #158

Draft
alexklibisz wants to merge 1 commit into
mainfrom
issue-157-firewall-group
Draft

Migrate terrifi_firewall_group off go-unifi SDK (#157)#158
alexklibisz wants to merge 1 commit into
mainfrom
issue-157-firewall-group

Conversation

@alexklibisz

Copy link
Copy Markdown
Owner

Summary

First step toward #157 — drop the go-unifi SDK in favor of locally-defined API contracts and HTTP calls.

  • New internal/unifi package will be the home for local API types. Currently holds NotFoundError and FirewallGroup.
  • New internal/provider/firewall_group_api.go implements Create/Get/Update/Delete/List on *Client using the existing doV2Request HTTP layer. These shadow the promoted SDK methods on *Client.ApiClient.
  • firewall_group_resource.go, its tests, and internal/generate/firewall_group.go swap from the SDK type to the local one (struct shapes match field-for-field, no conversion code changed).
  • Other resources are untouched and still use the SDK; they will be migrated one at a time.

firewall_group was 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 ./... clean
  • go test ./... unit tests pass
  • Acceptance tests against docker controller: TERRIFI_ACC_TARGET=docker task test:acc -- -run TestAccFirewallGroup
  • Verify terrifi generate-imports still emits terrifi_firewall_group blocks against a real controller

Notes

  • Local FirewallGroup.GroupMembers is serialized without omitempty; the API helper normalizes a nil slice to []string{} so the controller receives an authoritative empty array when all members are removed.
  • v1 REST envelope {meta, data} reused via the existing checkV1Meta helper.
  • Method shadowing: *Client embeds 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

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.
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.

1 participant