Compare commits
10 Commits
fix/destin
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75506536fa | ||
|
|
a65f546776 | ||
|
|
a9d8e8005e | ||
|
|
32510c0a75 | ||
|
|
d9f0c626d5 | ||
|
|
fb2d9762d8 | ||
|
|
ff67359ba4 | ||
|
|
a56df16830 | ||
|
|
13da1c0347 | ||
|
|
4de7c8c5ec |
27
.github/workflows/acctest.yml
vendored
27
.github/workflows/acctest.yml
vendored
@@ -1,32 +1,5 @@
|
||||
name: Acceptance Tests
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "*"
|
||||
# paths:
|
||||
# - "internal/**"
|
||||
# - "scripts/**"
|
||||
# - "tools/**"
|
||||
# - "main.go"
|
||||
# - "docker-compose.yaml"
|
||||
# - ".github/workflows/acctest.yml"
|
||||
# - "Makefile"
|
||||
# - "go.mod"
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
tags:
|
||||
- "v*"
|
||||
paths:
|
||||
- "internal/**"
|
||||
- "scripts/**"
|
||||
- "tools/**"
|
||||
- "main.go"
|
||||
- "docker-compose.yaml"
|
||||
- ".github/workflows/acctest.yml"
|
||||
- "Makefile"
|
||||
schedule:
|
||||
- cron: "0 13 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
|
||||
|
||||
81
.github/workflows/ci.yaml
vendored
81
.github/workflows/ci.yaml
vendored
@@ -1,34 +1,79 @@
|
||||
---
|
||||
name: ci
|
||||
|
||||
on:
|
||||
pull_request: {}
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
tags:
|
||||
- "v*"
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: "ubuntu-latest"
|
||||
# Runs on PRs: fast validation checks
|
||||
validate:
|
||||
if: github.event_name == 'pull_request'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
- name: Checkout provider
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
go-version-file: "go.mod"
|
||||
path: terraform-provider-unifi
|
||||
|
||||
- name: Checkout go-unifi dependency
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: shadyeip/go-unifi
|
||||
path: go-unifi
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: terraform-provider-unifi/go.mod
|
||||
cache: true
|
||||
check-latest: true
|
||||
|
||||
- run: "go build ./..."
|
||||
- name: Check formatting
|
||||
working-directory: terraform-provider-unifi
|
||||
run: |
|
||||
unformatted=$(gofmt -l .)
|
||||
if [ -n "$unformatted" ]; then
|
||||
echo "::error::Files not formatted with gofmt:"
|
||||
echo "$unformatted"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
lint:
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
- name: Vet
|
||||
working-directory: terraform-provider-unifi
|
||||
run: go vet ./...
|
||||
|
||||
- name: Lint
|
||||
uses: golangci/golangci-lint-action@v6.5.2
|
||||
with:
|
||||
go-version-file: "go.mod"
|
||||
working-directory: terraform-provider-unifi
|
||||
skip-pkg-cache: true
|
||||
|
||||
# Runs on merge to main: full build
|
||||
build:
|
||||
if: github.event_name == 'push'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout provider
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: terraform-provider-unifi
|
||||
|
||||
- name: Checkout go-unifi dependency
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: shadyeip/go-unifi
|
||||
path: go-unifi
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: terraform-provider-unifi/go.mod
|
||||
cache: true
|
||||
check-latest: true
|
||||
|
||||
- uses: "golangci/golangci-lint-action@v6.5.2"
|
||||
with:
|
||||
skip-pkg-cache: true
|
||||
- name: Build
|
||||
working-directory: terraform-provider-unifi
|
||||
run: go build ./...
|
||||
|
||||
62
.github/workflows/release.yml
vendored
62
.github/workflows/release.yml
vendored
@@ -1,35 +1,87 @@
|
||||
name: goreleaser
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- "v*"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: "Version tag to release (e.g. v2026.02.09)"
|
||||
required: false
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
concurrency: release
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
- name: Checkout provider
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
path: terraform-provider-unifi
|
||||
|
||||
- name: Checkout go-unifi dependency
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: shadyeip/go-unifi
|
||||
path: go-unifi
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: "go.mod"
|
||||
go-version-file: "terraform-provider-unifi/go.mod"
|
||||
check-latest: false
|
||||
|
||||
- name: Determine version
|
||||
id: version
|
||||
working-directory: terraform-provider-unifi
|
||||
run: |
|
||||
if [ -n "${{ inputs.tag }}" ]; then
|
||||
TAG="${{ inputs.tag }}"
|
||||
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
|
||||
TAG="${GITHUB_REF#refs/tags/}"
|
||||
else
|
||||
# Date-based version: v2026.02.09, v2026.02.09.1, v2026.02.09.2, ...
|
||||
DATE_TAG="v$(date -u +'%Y.%m.%d')"
|
||||
SUFFIX=0
|
||||
TAG="$DATE_TAG"
|
||||
while git rev-parse "$TAG" >/dev/null 2>&1; do
|
||||
SUFFIX=$((SUFFIX + 1))
|
||||
TAG="${DATE_TAG}.${SUFFIX}"
|
||||
done
|
||||
fi
|
||||
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Create and push tag
|
||||
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
||||
working-directory: terraform-provider-unifi
|
||||
run: |
|
||||
git tag "${{ steps.version.outputs.tag }}"
|
||||
git push origin "${{ steps.version.outputs.tag }}"
|
||||
|
||||
- name: Import GPG key
|
||||
if: env.GPG_PRIVATE_KEY != ''
|
||||
id: import_gpg
|
||||
uses: crazy-max/ghaction-import-gpg@v6
|
||||
with:
|
||||
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
env:
|
||||
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v6
|
||||
with:
|
||||
version: latest
|
||||
args: release --parallelism 2 --clean
|
||||
args: >-
|
||||
release --parallelism 2 --clean
|
||||
${{ steps.import_gpg.outputs.fingerprint == '' && '--skip=sign' || '' }}
|
||||
workdir: terraform-provider-unifi
|
||||
env:
|
||||
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
47
Makefile
47
Makefile
@@ -3,14 +3,59 @@ TESTARGS ?=
|
||||
TEST_COUNT ?= 1
|
||||
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
|
||||
default: build
|
||||
|
||||
# Build for the local platform
|
||||
.PHONY: 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
|
||||
testacc:
|
||||
go build ./...
|
||||
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
|
||||
|
||||
66
README.md
66
README.md
@@ -26,14 +26,76 @@ Use a hard-wired connection to your controller to use this provider.
|
||||
|
||||
## Installation
|
||||
|
||||
The provider is available in the [Terraform Registry](https://registry.terraform.io/providers/filipowm/unifi/latest). To use it in your Terraform configuration:
|
||||
### Building from Source
|
||||
|
||||
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)
|
||||
|
||||
```bash
|
||||
make install
|
||||
```
|
||||
|
||||
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
|
||||
make build-linux-arm64
|
||||
```
|
||||
|
||||
Then deploy to the remote host:
|
||||
|
||||
```bash
|
||||
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:
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
unifi = {
|
||||
source = "filipowm/unifi"
|
||||
version = "~> 1.0.0" # Use the latest version
|
||||
version = "= 99.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
After building/deploying, initialize Terraform:
|
||||
|
||||
```bash
|
||||
rm -f .terraform.lock.hcl
|
||||
terraform init
|
||||
```
|
||||
|
||||
### From Terraform Registry
|
||||
|
||||
The upstream provider is available in the [Terraform Registry](https://registry.terraform.io/providers/filipowm/unifi/latest):
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
unifi = {
|
||||
source = "filipowm/unifi"
|
||||
version = "~> 1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user