fix: use local go-unifi with omitempty fix for zone policy bug

Switch go-unifi dependency from remote fork to local module which includes
the fix for empty string fields (firewall_zone_id, etc.) being sent in
network API requests, causing all zone policies to disappear from the UI.

Also updates Makefile with cross-compile and deploy targets, and README
with self-contained build/install instructions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Adam Nadrowski
2026-02-06 23:00:11 -05:00
parent 13da1c0347
commit a56df16830
4 changed files with 103 additions and 40 deletions

View File

@@ -3,14 +3,59 @@ TESTARGS ?=
TEST_COUNT ?= 1 TEST_COUNT ?= 1
TEST_TIMEOUT ?= 20m TEST_TIMEOUT ?= 20m
BINARY = terraform-provider-unifi
VERSION = 99.0.0
PLUGIN_DIR = registry.terraform.io/filipowm/unifi/$(VERSION)
LOCAL_OS = $(shell go env GOOS)
LOCAL_ARCH = $(shell go env GOARCH)
LOCAL_PLATFORM = $(LOCAL_OS)_$(LOCAL_ARCH)
DEPLOY_HOST ?=
TF_DIR ?=
.PHONY: default .PHONY: default
default: build default: build
# Build for the local platform
.PHONY: build .PHONY: build
build: build:
go install go build -o $(BINARY) .
# Build and install into local Terraform plugin directory
.PHONY: install
install: build
mkdir -p ~/.terraform.d/plugins/$(PLUGIN_DIR)/$(LOCAL_PLATFORM)
cp $(BINARY) ~/.terraform.d/plugins/$(PLUGIN_DIR)/$(LOCAL_PLATFORM)/$(BINARY)
# Cross-compile for Linux ARM64 (UDM-SE, docker-host, etc.)
.PHONY: build-linux-arm64
build-linux-arm64:
GOOS=linux GOARCH=arm64 go build -o $(BINARY)_linux_arm64 .
# Cross-compile for Linux AMD64
.PHONY: build-linux-amd64
build-linux-amd64:
GOOS=linux GOARCH=amd64 go build -o $(BINARY)_linux_amd64 .
# Deploy to a remote host via scp
# Usage: make deploy DEPLOY_HOST=root@192.168.1.1
# make deploy DEPLOY_HOST=root@192.168.1.1 TF_DIR=/root/terraform
.PHONY: deploy
deploy: build-linux-arm64
@if [ -z "$(DEPLOY_HOST)" ]; then echo "Error: set DEPLOY_HOST (e.g. make deploy DEPLOY_HOST=root@192.168.1.1)"; exit 1; fi
ssh $(DEPLOY_HOST) 'mkdir -p ~/.terraform.d/plugins/$(PLUGIN_DIR)/linux_arm64'
scp $(BINARY)_linux_arm64 $(DEPLOY_HOST):~/.terraform.d/plugins/$(PLUGIN_DIR)/linux_arm64/$(BINARY)
@if [ -n "$(TF_DIR)" ]; then \
echo "Reinitializing Terraform on $(DEPLOY_HOST)..."; \
ssh $(DEPLOY_HOST) 'cd $(TF_DIR) && rm -f .terraform.lock.hcl && terraform init'; \
fi
.PHONY: testacc .PHONY: testacc
testacc: testacc:
go build ./... go build ./...
TF_ACC=1 go test $(TEST) -v -count $(TEST_COUNT) -timeout $(TEST_TIMEOUT) $(TESTARGS) TF_ACC=1 go test $(TEST) -v -count $(TEST_COUNT) -timeout $(TEST_TIMEOUT) $(TESTARGS)
.PHONY: clean
clean:
rm -f $(BINARY) $(BINARY)_linux_arm64 $(BINARY)_linux_amd64

View File

@@ -26,41 +26,61 @@ Use a hard-wired connection to your controller to use this provider.
## Installation ## Installation
### From This Fork (Recommended) ### Building from Source
This fork includes bug fixes not yet in the upstream provider. To install: This repo includes the `go-unifi` SDK as a local module (in `../go-unifi`). Both are built together — no external repo references needed.
**Prerequisites:** Go 1.23+, Terraform 1.0+
#### Build and install locally (macOS)
1. Build the provider:
```bash ```bash
git clone https://github.com/shadyeip/terraform-provider-unifi.git make install
cd terraform-provider-unifi
go build -o terraform-provider-unifi
``` ```
2. Create the plugin directory and copy the binary: This builds the provider and installs it to `~/.terraform.d/plugins/` for local use.
#### Cross-compile for a remote host (e.g. UDM-SE, Linux ARM64 docker-host)
```bash ```bash
mkdir -p ~/.terraform.d/plugins/registry.terraform.io/filipowm/unifi/99.0.0/darwin_arm64 make build-linux-arm64
cp terraform-provider-unifi ~/.terraform.d/plugins/registry.terraform.io/filipowm/unifi/99.0.0/darwin_arm64/
``` ```
Replace `darwin_arm64` with your platform: Then deploy to the remote host:
- `darwin_amd64` - macOS Intel
- `linux_amd64` - Linux x86_64 ```bash
- `linux_arm64` - Linux ARM64 make deploy DEPLOY_HOST=root@<your-udm-ip>
```
Or manually:
```bash
scp terraform-provider-unifi_linux_arm64 root@<host>:~/.terraform.d/plugins/registry.terraform.io/filipowm/unifi/99.0.0/linux_arm64/terraform-provider-unifi
```
#### All-in-one: build, deploy, and init on remote host
```bash
make deploy DEPLOY_HOST=root@<your-udm-ip> TF_DIR=/path/to/terraform/configs
```
### Terraform Configuration
Configure your `versions.tf` to use the local provider:
3. Configure Terraform to use the local provider:
```hcl ```hcl
terraform { terraform {
required_providers { required_providers {
unifi = { unifi = {
source = "filipowm/unifi" source = "filipowm/unifi"
version = "99.0.0" version = "= 99.0.0"
} }
} }
} }
``` ```
4. Initialize Terraform: After building/deploying, initialize Terraform:
```bash ```bash
rm -f .terraform.lock.hcl rm -f .terraform.lock.hcl
terraform init terraform init
@@ -68,14 +88,14 @@ This fork includes bug fixes not yet in the upstream provider. To install:
### From Terraform Registry ### From Terraform Registry
The provider is available in the [Terraform Registry](https://registry.terraform.io/providers/filipowm/unifi/latest). To use it in your Terraform configuration: The upstream provider is available in the [Terraform Registry](https://registry.terraform.io/providers/filipowm/unifi/latest):
```hcl ```hcl
terraform { terraform {
required_providers { required_providers {
unifi = { unifi = {
source = "filipowm/unifi" source = "filipowm/unifi"
version = "~> 1.0.0" # Use the latest version version = "~> 1.0.0"
} }
} }
} }

2
go.mod
View File

@@ -427,4 +427,4 @@ require (
tags.cncf.io/container-device-interface v0.8.1 // indirect tags.cncf.io/container-device-interface v0.8.1 // indirect
) )
replace github.com/filipowm/go-unifi => github.com/shadyeip/go-unifi v1.8.1 replace github.com/filipowm/go-unifi => ../go-unifi

2
go.sum
View File

@@ -830,8 +830,6 @@ github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b h1:h+3JX2VoWTFuyQEo87pStk/a99dzIO1mM9KxIyLPGTU= github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b h1:h+3JX2VoWTFuyQEo87pStk/a99dzIO1mM9KxIyLPGTU=
github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b/go.mod h1:/yeG0My1xr/u+HZrFQ1tOQQQQrOawfyMUH13ai5brBc= github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b/go.mod h1:/yeG0My1xr/u+HZrFQ1tOQQQQrOawfyMUH13ai5brBc=
github.com/shadyeip/go-unifi v1.8.1 h1:sjigrGs7985w9IjbRoNGnRBeon1CsRfSN367fxaIaCM=
github.com/shadyeip/go-unifi v1.8.1/go.mod h1:hf0HZI8SX/h6vEa0BQzxY8Bpm4enbRmrPJ1DFFt6/4A=
github.com/shibumi/go-pathspec v1.3.0 h1:QUyMZhFo0Md5B8zV8x2tesohbb5kfbpTi9rBnKh5dkI= github.com/shibumi/go-pathspec v1.3.0 h1:QUyMZhFo0Md5B8zV8x2tesohbb5kfbpTi9rBnKh5dkI=
github.com/shibumi/go-pathspec v1.3.0/go.mod h1:Xutfslp817l2I1cZvgcfeMQJG5QnU2lh5tVaaMCl3jE= github.com/shibumi/go-pathspec v1.3.0/go.mod h1:Xutfslp817l2I1cZvgcfeMQJG5QnU2lh5tVaaMCl3jE=
github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI= github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI=