### Install UniFi OS Server Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/hardware-testing/unifi-os-server/README.md SSH into the server and run the install script. You can specify a version or install the default. ```sh ssh terrifi-unifi-os-server sudo ./install.sh # installs default version (5.0.6) sudo ./install.sh 4.3.6 # or specify a version ``` -------------------------------- ### Install Latest or Specific Pre-Release Version Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/examples/using-pre-release/README.md Use the install script to download and place the provider binary. Specify a version tag for a particular pre-release. ```shell ./install.sh ``` ```shell ./install.sh v0.1.0-RC1 ``` -------------------------------- ### Check GOBIN and PATH Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Troubleshoots CLI installation issues by verifying the GOBIN directory and ensuring it is included in the system's PATH. ```sh $ echo $GOBIN /Users/alex/.asdf/installs/golang/1.26.1/bin $ which terrifi /Users/alex/.asdf/installs/golang/1.26.1/bin/terrifi ``` -------------------------------- ### Install Latest Released CLI Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Installs the latest released version of the terrifi CLI using go install. This is used to switch back from a pre-release or local build. ```sh go install github.com/alexklibisz/terrifi/cmd/terrifi@latest ``` -------------------------------- ### Using with device data source Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md This example shows how to use the `terrifi_device` data source to retrieve device information and then use that information to configure another `terrifi_device` resource. ```APIDOC ## terrifi_device ### Description Manages settings on an adopted UniFi network device (access point, switch, or gateway). ### Parameters #### Required - `mac` (String) - The MAC address of the device (e.g. `aa:bb:cc:dd:ee:ff`). The device must already be adopted by the controller. Changing this forces a new resource. #### Optional - `name` (String) - The display name for the device. - `led_enabled` (Boolean) - Whether LEDs are enabled. `true` forces on, `false` forces off. Omit to follow site default. - `locked` (Boolean) - Whether the device is locked to prevent accidental removal. ### Request Example ```terraform data "terrifi_device" "ap" { name = "Living Room AP" } resource "terrifi_device" "ap" { mac = data.terrifi_device.ap.mac name = "Living Room AP" led_enabled = false locked = true } ``` ``` -------------------------------- ### Multiple settings Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md This example applies multiple configuration settings to a UniFi device, including name, LED status, lock status, and SNMP details. ```APIDOC ## terrifi_device ### Description Manages settings on an adopted UniFi network device (access point, switch, or gateway). ### Parameters #### Required - `mac` (String) - The MAC address of the device (e.g. `aa:bb:cc:dd:ee:ff`). The device must already be adopted by the controller. Changing this forces a new resource. #### Optional - `name` (String) - The display name for the device. - `led_enabled` (String) - Whether LEDs are enabled. `true` forces on, `false` forces off. Omit to follow site default. - `locked` (Boolean) - Whether the device is locked to prevent accidental removal. - `snmp_contact` (String) - [SNMP](https://en.wikipedia.org/wiki/Simple_Network_Management_Protocol) contact string (max 255 characters). Identifies who is responsible for the device; read by network monitoring tools like Nagios, PRTG, or LibreNMS. - `snmp_location` (String) - [SNMP](https://en.wikipedia.org/wiki/Simple_Network_Management_Protocol) location string (max 255 characters). Describes where the device is physically located; read by network monitoring tools. ### Request Example ```terraform resource "terrifi_device" "gateway" { mac = "aa:bb:cc:11:22:33" name = "Main Gateway" led_enabled = "on" locked = true snmp_contact = "noc@example.com" snmp_location = "DC1" } ``` ``` -------------------------------- ### LED override Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md This example shows how to disable the LED on a UniFi device. ```APIDOC ## terrifi_device ### Description Manages settings on an adopted UniFi network device (access point, switch, or gateway). ### Parameters #### Required - `mac` (String) - The MAC address of the device (e.g. `aa:bb:cc:dd:ee:ff`). The device must already be adopted by the controller. Changing this forces a new resource. #### Optional - `name` (String) - The display name for the device. - `led_enabled` (Boolean) - Whether LEDs are enabled. `true` forces on, `false` forces off. Omit to follow site default. ### Request Example ```terraform resource "terrifi_device" "office_ap" { mac = "aa:bb:cc:dd:ee:ff" name = "Office AP" led_enabled = false } ``` ``` -------------------------------- ### Static management IP Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md This example configures a static IP address for a UniFi device's management network. ```APIDOC ## terrifi_device ### Description Manages settings on an adopted UniFi network device (access point, switch, or gateway). ### Parameters #### Required - `mac` (String) - The MAC address of the device (e.g. `aa:bb:cc:dd:ee:ff`). The device must already be adopted by the controller. Changing this forces a new resource. #### Optional - `name` (String) - The display name for the device. - `config_network` (Block) - Management network configuration. Omit to leave the device's current configuration untouched. See [below](#config_network). ### Request Example ```terraform resource "terrifi_device" "core_switch" { mac = "11:22:33:44:55:66" name = "Core Switch" config_network = { type = "static" ip = "192.168.1.5" netmask = "255.255.255.0" gateway = "192.168.1.1" dns1 = "1.1.1.1" dns2 = "8.8.8.8" } } ``` To revert to DHCP, change `type` to `"dhcp"` and remove the addressing fields: ```terraform resource "terrifi_device" "core_switch" { mac = "11:22:33:44:55:66" name = "Core Switch" config_network = { type = "dhcp" } } ``` ``` -------------------------------- ### Verify CLI Installation Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Checks the installed terrifi CLI version. The version should typically end with a Git hash for local builds. ```sh $ terrifi --version ``` -------------------------------- ### Pin a client to an access point Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/data-sources/device.md This example shows how to look up an access point by name and then use its MAC address to pin a client device to it. ```terraform data "terrifi_device" "office_ap" { name = "Office AP" } resource "terrifi_client_device" "laptop" { mac = "11:22:33:44:55:66" name = "Work Laptop" fixed_ap_mac = data.terrifi_device.office_ap.mac } ``` -------------------------------- ### SNMP settings Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md This example configures SNMP settings for a UniFi device, including contact and location. ```APIDOC ## terrifi_device ### Description Manages settings on an adopted UniFi network device (access point, switch, or gateway). ### Parameters #### Required - `mac` (String) - The MAC address of the device (e.g. `aa:bb:cc:dd:ee:ff`). The device must already be adopted by the controller. Changing this forces a new resource. #### Optional - `name` (String) - The display name for the device. - `snmp_contact` (String) - [SNMP](https://en.wikipedia.org/wiki/Simple_Network_Management_Protocol) contact string (max 255 characters). Identifies who is responsible for the device; read by network monitoring tools like Nagios, PRTG, or LibreNMS. - `snmp_location` (String) - [SNMP](https://en.wikipedia.org/wiki/Simple_Network_Management_Protocol) location string (max 255 characters). Describes where the device is physically located; read by network monitoring tools. ### Request Example ```terraform resource "terrifi_device" "core_switch" { mac = "11:22:33:44:55:66" name = "Core Switch" snmp_contact = "admin@example.com" snmp_location = "Server Room A, Rack 1" } ``` ``` -------------------------------- ### Radio settings (access points) Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md This example configures radio settings for both 2.4 GHz and 5 GHz bands on an access point. ```APIDOC ## terrifi_device ### Description Manages settings on an adopted UniFi network device (access point, switch, or gateway). ### Parameters #### Required - `mac` (String) - The MAC address of the device (e.g. `aa:bb:cc:dd:ee:ff`). The device must already be adopted by the controller. Changing this forces a new resource. #### Optional - `name` (String) - The display name for the device. - `radio_24` (Attributes) - Settings for the 2.4 GHz radio (UniFi `ng` radio) on an access point. See [nested schema for radio blocks](#nested-schema-for-radio-blocks). - `radio_5` (Attributes) - Settings for the 5 GHz radio (UniFi `na` radio) on an access point. See [nested schema for radio blocks](#nested-schema-for-radio-blocks). ### Request Example ```terraform resource "terrifi_device" "office_ap" { mac = "aa:bb:cc:dd:ee:ff" name = "Office AP" radio_24 = { channel = "auto" channel_width = 40 transmit_power_mode = "auto" } radio_5 = { channel = "auto" channel_width = 80 transmit_power_mode = "auto" } } ``` ``` -------------------------------- ### A record Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/dns_record.md Example of creating an 'A' record for a web server. Specifies the hostname, IP address, record type, and TTL. ```terraform resource "terrifi_dns_record" "web" { name = "web.example.com" value = "192.168.1.100" record_type = "A" ttl = 300 } ``` -------------------------------- ### Basic — set device name Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md This example demonstrates how to set the display name for a UniFi device using its MAC address. ```APIDOC ## terrifi_device ### Description Manages settings on an adopted UniFi network device (access point, switch, or gateway). ### Parameters #### Required - `mac` (String) - The MAC address of the device (e.g. `aa:bb:cc:dd:ee:ff`). The device must already be adopted by the controller. Changing this forces a new resource. #### Optional - `name` (String) - The display name for the device. ### Request Example ```terraform resource "terrifi_device" "living_room_ap" { mac = "aa:bb:cc:dd:ee:ff" name = "Living Room AP" } ``` ``` -------------------------------- ### Order firewall policies between two zones Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_policy_order.md This example demonstrates how to order firewall policies between two zones using the `terrifi_firewall_policy_order` resource. The policies themselves must be created separately. ```terraform resource "terrifi_firewall_zone" "iot" { name = "IoT" } resource "terrifi_firewall_zone" "trusted" { name = "Trusted" } resource "terrifi_firewall_policy" "allow_dns" { name = "Allow DNS" action = "ALLOW" source { zone_id = terrifi_firewall_zone.iot.id } destination { zone_id = terrifi_firewall_zone.trusted.id port_matching_type = "SPECIFIC" port = 53 } } resource "terrifi_firewall_policy" "block_all" { name = "Block All" action = "BLOCK" source { zone_id = terrifi_firewall_zone.iot.id } destination { zone_id = terrifi_firewall_zone.trusted.id } } resource "terrifi_firewall_policy_order" "iot_to_trusted" { source_zone_id = terrifi_firewall_zone.iot.id destination_zone_id = terrifi_firewall_zone.trusted.id policy_ids = [ terrifi_firewall_policy.allow_dns.id, # evaluated first terrifi_firewall_policy.block_all.id, # evaluated second ] } ``` -------------------------------- ### Allow specific IPs and port Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_policy.md This example demonstrates how to create a firewall policy that allows specific traffic based on source IP addresses and destination port. It requires defining source and destination zones, and specifies the protocol and port for the rule. ```terraform resource "terrifi_firewall_policy" "allow_https" { name = "Allow HTTPS from management" action = "ALLOW" protocol = "tcp" source { zone_id = terrifi_firewall_zone.management.id ips = ["10.0.0.0/24"] } destination { zone_id = terrifi_firewall_zone.servers.id port_matching_type = "SPECIFIC" port = 443 } } ``` -------------------------------- ### Configure Local Provider Installation Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Configures OpenTofu/Terraform to use a locally built provider by adding an entry to the provider_installation block in ~/.tofurc or ~/.terraformrc. This bypasses the need for 'tofu init'. ```hcl provider_installation { dev_overrides { "alexklibisz/terrifi" = "/home//terraform-provider-terrifi-0.4.0-RC2" } direct {} } ``` -------------------------------- ### Block by MAC address Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_policy.md This example shows how to block traffic from a specific device by its MAC address. It requires defining the source zone and the MAC address of the device to be blocked. ```terraform resource "terrifi_firewall_policy" "block_mac" { name = "Block specific device" action = "BLOCK" source { zone_id = terrifi_firewall_zone.iot.id mac_addresses = ["aa:bb:cc:dd:ee:ff"] } destination { zone_id = terrifi_firewall_zone.trusted.id } } ``` -------------------------------- ### Import firewall policy ordering Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_policy_order.md These examples show how to import existing firewall policy ordering configurations into Terraform state. You can import using the zone pair or include the site name for non-default sites. ```shell terraform import terrifi_firewall_policy_order.example : ``` ```shell terraform import terrifi_firewall_policy_order.example :: ``` -------------------------------- ### Manage UniFi OS Server Service Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/hardware-testing/unifi-os-server/README.md Common management commands for the uosserver service, including checking status, starting, stopping, and viewing the version. ```sh uosserver status # check if running uosserver start # start the service uosserver stop # stop the service uosserver version # show installed version uosserver shell # open a shell inside the container ``` -------------------------------- ### Uninstall UniFi OS Server Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/hardware-testing/unifi-os-server/README.md Completely remove UniFi OS Server, its data, and binaries using the uninstall script. This prepares the system for a fresh installation. ```sh sudo ./uninstall.sh ``` -------------------------------- ### terrifi_device Data Source Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/data-sources/device.md Looks up a UniFi network device (access point, switch, or gateway) by name or MAC address. Use this data source to reference device attributes in other resources — for example, to pin a client device to a specific access point. ```APIDOC ## terrifi_device (Data Source) Looks up a UniFi network device (access point, switch, or gateway) by name or MAC address. Use this data source to reference device attributes in other resources — for example, to pin a client device to a specific access point. ### Example Usage #### Look up by name ```terraform data "terrifi_device" "living_room_ap" { name = "Living Room AP" } ``` #### Look up by MAC ```terraform data "terrifi_device" "office_ap" { mac = "aa:bb:cc:dd:ee:ff" } ``` ### Schema #### Required (one of) Exactly one of `name` or `mac` must be specified. - `name` (String) — The name of the device to look up. - `mac` (String) — The MAC address of the device to look up (e.g. `aa:bb:cc:dd:ee:ff`). #### Optional - `site` (String) — The site to look up the device in. Defaults to the provider site. ### Read-Only - `id` (String) — The ID of the device. - `model` (String) — The hardware model of the device (e.g. `U6-LR`, `US-16-XG`). - `type` (String) — The device type (e.g. `uap` for access point, `usw` for switch, `ugw` for gateway). - `ip` (String) — The current IP address of the device. - `disabled` (Boolean) — Whether the device is administratively disabled. - `adopted` (Boolean) — Whether the device has been adopted by the controller. - `state` (Number) — The device state. 0 = unknown, 1 = connected, 2 = pending, 4 = upgrading, 5 = provisioning, 6 = heartbeat missed. ``` -------------------------------- ### SRV record with optional fields Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/dns_record.md Example of creating an 'SRV' record for a Minecraft server. Includes optional fields like port, priority, and weight, along with hostname, value, record type, and TTL. ```terraform resource "terrifi_dns_record" "minecraft" { name = "_minecraft._tcp.example.com" value = "mc.example.com" record_type = "SRV" port = 25565 priority = 10 weight = 100 ttl = 3600 } ``` -------------------------------- ### Weekly schedule Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_policy.md Create a firewall policy that is active only during specific days and times each week. This is useful for implementing business hour restrictions. The `schedule` block defines the mode, start and end times, and the days of the week for the policy. ```terraform resource "terrifi_firewall_policy" "weekday_block" { name = "Block during work hours" action = "BLOCK" source { zone_id = terrifi_firewall_zone.guest.id } destination { zone_id = terrifi_firewall_zone.internal.id } schedule { mode = "EVERY_WEEK" time_range_start = "08:00" time_range_end = "17:00" repeat_on_days = ["mon", "tue", "wed", "thu", "fri"] } } ``` -------------------------------- ### Run Terraform/OpenTofu Apply Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Applies Terraform/OpenTofu configurations using the locally built provider. No 'terraform init' or 'tofu init' is required when TF_CLI_CONFIG_FILE is set. ```sh cd /path/to/your/terraform/project tofu apply ``` -------------------------------- ### Initialize, Plan, and Apply Terraform Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/examples/using-pre-release/README.md Standard Terraform commands to initialize the workspace, preview changes, and apply them. ```shell terraform init terraform plan terraform apply ``` -------------------------------- ### Generate import blocks using Terrifi CLI Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/dns_record.md Shows how to use the Terrifi CLI to automatically generate import blocks for all DNS records. ```shell terrifi generate-imports terrifi_dns_record ``` -------------------------------- ### Generate Import Blocks for All Client Devices Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_device.md Leverage the Terrifi CLI to automatically generate import blocks for all client devices, simplifying bulk imports. ```shell terrifi generate-imports terrifi_client_device ``` -------------------------------- ### Build CLI Binary Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Builds the terrifi CLI binary. This command should be run from the terrifi project directory. ```sh $ cd /path/to/terrifi $ task build:cli ``` -------------------------------- ### Run Acceptance Tests (Hardware) Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Runs acceptance tests against real UniFi hardware. This requires setting environment variables such as UNIFI_*. ```sh task test:acc:hardware ``` -------------------------------- ### Check Terrifi Connection Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/index.md Verify that your environment variables are configured correctly for Terrifi. ```bash terrifi check-connection ``` -------------------------------- ### Import a firewall zone from a non-default site Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_zone.md Use this command to import a firewall zone from a non-default site. Use the format :. ```shell terraform import terrifi_firewall_zone.iot : ``` -------------------------------- ### Generate import blocks with Terrifi CLI Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/network.md Automate the generation of import blocks for all networks using the Terrifi CLI command `generate-imports`. This is a convenient way to manage existing networks. ```shell terrifi generate-imports terrifi_network ``` -------------------------------- ### Run Acceptance Tests (Docker) Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Executes acceptance tests against a Docker-based UniFi controller. Ensure Docker is running and accessible. ```sh task test:acc ``` -------------------------------- ### Generate import blocks for all firewall zones using Terrifi CLI Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_zone.md Use the Terrifi CLI to automatically generate import blocks for all firewall zones. This is a convenient way to manage multiple zones. ```shell terrafi generate-imports terrifi_firewall_zone ``` -------------------------------- ### Import a firewall group from a non-default site Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_group.md Illustrates importing a firewall group from a specific site using the 'site:id' format. ```shell terraform import terrifi_firewall_group.web_ports : ``` -------------------------------- ### Assign Client Devices to a Group Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_group.md Demonstrates how to create client devices and assign them to a previously defined client group using their IDs. Ensure the client group is created before assigning devices. ```terraform resource "terrifi_client_group" "smart_plugs" { name = "WiFi Smart Plugs" } resource "terrifi_client_device" "plug_living_room" { mac = "aa:bb:cc:dd:ee:01" name = "Living Room Plug" client_group_ids = [terrifi_client_group.smart_plugs.id] } resource "terrifi_client_device" "plug_bedroom" { mac = "aa:bb:cc:dd:ee:02" name = "Bedroom Plug" client_group_ids = [terrifi_client_group.smart_plugs.id] } ``` -------------------------------- ### Import Client Device by ID Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_device.md Use this command to import a single client device using its unique device ID. ```shell terraform import terrifi_client_device.printer ``` -------------------------------- ### Import DNS record Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/dns_record.md Demonstrates how to import an existing DNS record using its ID. For records on non-default sites, use the 'site:id' format. ```shell terraform import terrifi_dns_record.web ``` ```shell terraform import terrifi_dns_record.web : ``` -------------------------------- ### Use Device Data Source with Resource Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md Dynamically set device properties by first retrieving device information using the `terrifi_device` data source, then applying configuration changes. ```terraform data "terrifi_device" "ap" { name = "Living Room AP" } resource "terrifi_device" "ap" { mac = data.terrifi_device.ap.mac name = "Living Room AP" led_enabled = false locked = true } ``` -------------------------------- ### Import a network Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/network.md Use the `terraform import` command to import an existing network into your Terraform state. Provide the network ID for the default site or `site:id` for a non-default site. ```shell terraform import terrifi_network.iot ``` ```shell terraform import terrifi_network.iot : ``` -------------------------------- ### Run Specific Unit Test Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/CLAUDE.md Execute a single unit test by providing a pattern to the 'go test' command. ```sh task test:unit -- -run TestDNSRecordModelToAPI ``` -------------------------------- ### Import Client Device from Non-Default Site Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_device.md To import a client device located in a site other than the default, specify the site ID along with the device ID in the 'site:id' format. ```shell terraform import terrifi_client_device.printer : ``` -------------------------------- ### Generate Import Blocks with Terrifi CLI Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/wlan.md Use the Terrifi CLI to automatically generate import blocks for all WLAN resources. This simplifies the process of bringing existing WLANs under Terraform management. ```shell terrifi generate-imports terrifi_wlan ``` -------------------------------- ### Copy Scripts to Server Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/hardware-testing/unifi-os-server/README.md Use rsync to copy the necessary scripts to the UniFi OS Server. Ensure SSH access is configured. ```sh ./rsync.sh ``` -------------------------------- ### Build Provider Locally Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Builds the Terraform provider binary locally. Ensure you are in the terrifi project directory before running this command. ```sh cd /path/to/terrifi task build ``` -------------------------------- ### Import Device from Non-Default Site Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md To import a device associated with a specific site other than the default, prefix the MAC address with the site name and a colon. ```shell terraform import terrifi_device.ap mysite:aa:bb:cc:dd:ee:ff ``` -------------------------------- ### Configure Terrifi Provider with Environment Variables Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/index.md Configure the Terrifi provider using environment variables for authentication and controller connection. Ensure UNIFI_API, and either UNIFI_API_KEY or UNIFI_USERNAME/UNIFI_PASSWORD are set. ```terraform provider "terrifi" {} ``` -------------------------------- ### Generate Import Blocks with Terrifi CLI Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_group.md Utilizes the Terrifi CLI to automatically generate import blocks for all client groups, simplifying the import process. ```shell terrifi generate-imports terrifi_client_group ``` -------------------------------- ### Generate Import Blocks for All Devices Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md Utilize the Terrifi CLI to automatically generate Terraform import blocks for all managed devices. This is useful for bulk importing. ```shell terrifi generate-imports terrifi_device ``` -------------------------------- ### Run Specific Acceptance Test Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/CLAUDE.md Execute a single acceptance test by providing a pattern to the 'go test' command. ```sh task test:acc -- -run TestAccDNSRecord_basic ``` -------------------------------- ### Set Unifi Controller Credentials Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/examples/using-pre-release/README.md Export environment variables for Unifi API endpoint, API key, and insecure connection setting. ```shell export UNIFI_API="https://192.168.1.12:8443" export UNIFI_API_KEY="your-api-key" export UNIFI_INSECURE=true ``` -------------------------------- ### Generate import blocks with Terrifi CLI Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_policy_order.md This command utilizes the Terrifi CLI to automatically generate import blocks for the `terrifi_firewall_policy_order` resource, simplifying the import process. ```shell terrifi generate-imports terrifi_firewall_policy_order ``` -------------------------------- ### Import Firewall Policy from Non-Default Site Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_policy.md Import a firewall policy from a specific site by providing the site ID along with the policy ID. This ensures correct association with the intended UniFi site. ```shell terraform import terrifi_firewall_policy.example : ``` -------------------------------- ### Build Provider and CLI Binaries Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Builds the provider and CLI binaries using the Task build runner. This command also generates a .terraformrc file for local development overrides. ```sh task build ``` -------------------------------- ### Generate HTML Device Types Page Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/index.md Generate a browsable HTML page with device icons, fuzzy search, and filterable type/vendor dropdowns. The HTML page loads device icons from Ubiquiti's CDN and uses Fuse.js for fuzzy search. ```bash terrifi list-device-types --html ``` -------------------------------- ### Configure Multiple Device Settings Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md Apply various settings including name, LED status, lock status, and SNMP details to a device. ```terraform resource "terrifi_device" "gateway" { mac = "aa:bb:cc:11:22:33" name = "Main Gateway" led_enabled = "on" locked = true snmp_contact = "noc@example.com" snmp_location = "DC1" } ``` -------------------------------- ### Generate Import Blocks for All Firewall Policies Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_policy.md Use the Terrifi CLI to automatically generate Terraform import blocks for all existing firewall policies. This simplifies the process of bringing multiple policies under Terraform management. ```shell terrifi generate-imports terrifi_firewall_policy ``` -------------------------------- ### Import a Client Group Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_group.md Shows how to import an existing client group into Terraform state using its ID. For groups in non-default sites, prepend the site ID. ```shell terraform import terrifi_client_group.smart_plugs ``` ```shell terraform import terrifi_client_group.smart_plugs : ``` -------------------------------- ### Open Guest Network Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/wlan.md Create an open (no password) guest WiFi network. This configuration is suitable for public access points. ```terraform resource "terrifi_wlan" "guest" { name = "Guest" network_id = terrifi_network.guest.id security = "open" } ``` -------------------------------- ### Run Unit Tests Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Executes all unit tests for the provider. These tests are fast and do not require network access. ```sh task test:unit ``` -------------------------------- ### Import a firewall group Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_group.md Shows how to import an existing firewall group into Terraform state using its ID. ```shell terraform import terrifi_firewall_group.web_ports ``` -------------------------------- ### Enable Response Caching via Environment Variable Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/index.md Enable response caching for the Terrifi provider by setting the UNIFI_RESPONSE_CACHING environment variable to true. This is an alternative to configuring it directly within the provider block. ```sh export UNIFI_RESPONSE_CACHING=true ``` -------------------------------- ### Basic Device Configuration Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md Set the name for an adopted UniFi device. The MAC address is required to identify the device. ```terraform resource "terrifi_device" "living_room_ap" { mac = "aa:bb:cc:dd:ee:ff" name = "Living Room AP" } ``` -------------------------------- ### Download Pre-release Provider Binary Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Downloads a specific pre-release version of the Terraform provider binary directly from GitHub releases. Adjust VERSION, OS, and ARCH as needed. ```sh VERSION="0.4.0-RC2" OS="linux" ARCH="amd64" PROVIDER="terraform-provider-terrifi" OWNER="alexklibisz" curl -L "https://github.com/${OWNER}/${PROVIDER}/releases/download/v${VERSION}/${PROVIDER}_${VERSION}_${OS}_${ARCH}.zip" \ -o /tmp/${PROVIDER}-${VERSION}.zip && \ unzip -o /tmp/${PROVIDER}-${VERSION}.zip -d ~/${PROVIDER}-${VERSION}/ ``` -------------------------------- ### Run Single Unit Test Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Runs a specific unit test by providing a filter to the 'go test' command. Replace 'TestCheckV1Meta' with the desired test function name. ```sh task test:unit -- -run TestCheckV1Meta ``` -------------------------------- ### List Device Types to CSV Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/index.md Browse the UniFi controller's fingerprint database to find device type IDs. Outputs CSV by default, which can be used for `dev_id_override` values. ```bash terrifi list-device-types > device_types.csv ``` -------------------------------- ### Generate import blocks using Terrifi CLI Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_group.md Utilizes the Terrifi CLI to automatically generate Terraform import blocks for all firewall groups. ```shell terrifi generate-imports terrifi_firewall_group ``` -------------------------------- ### Configure Terraform for Filesystem Mirror Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/examples/using-pre-release/README.md Add a filesystem mirror configuration to your ~/.terraformrc file to point to the local plugin directory. ```hcl provider_installation { filesystem_mirror { path = "/home//.terraform.d/plugins" } direct {} } ``` -------------------------------- ### Tail UniFi OS Server Logs Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/hardware-testing/unifi-os-server/README.md Use the logs.sh script to tail specific log files for the UniFi Network Application or MongoDB. Alternatively, access Podman container logs directly. ```sh ./logs.sh # tail server.log (UniFi Network Application) ./logs.sh mongod # tail mongod.log ``` ```sh # Podman container logs (startup, systemd) sudo su -s /bin/bash -l uosserver -c 'podman logs -f uosserver' # Application logs inside the container sudo su -s /bin/bash -l uosserver -c 'podman exec uosserver tail -f /usr/lib/unifi/logs/server.log' ``` -------------------------------- ### Configure Terrifi Provider with Explicit Settings Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/index.md Configure the Terrifi provider with explicit settings for API URL, API key, site, and TLS verification. This method allows for more granular control over the provider's connection and authentication. ```terraform provider "terrifi" { api_url = "https://192.168.1.1" api_key = var.unifi_api_key site = "default" allow_insecure = true response_caching = true } ``` -------------------------------- ### Import Device by MAC Address Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md Use this command to import a device into Terraform management using its MAC address. Ensure the MAC address is correctly formatted. ```shell terraform import terrifi_device.ap aa:bb:cc:dd:ee:ff ``` -------------------------------- ### Basic client device alias Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_device.md Use this snippet to set a basic alias for a client device. Requires the client's MAC address and a desired name. ```terraform resource "terrifi_client_device" "printer" { mac = "aa:bb:cc:dd:ee:ff" name = "Office Printer" } ``` -------------------------------- ### Basic WPA2 WiFi Network Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/wlan.md Use this snippet to create a basic WPA2 secured WiFi network. The Wi-Fi passphrase must be set as an environment variable TF_VAR_wifi_passphrase. ```terraform # Set via: export TF_VAR_wifi_passphrase="your-password" variable "wifi_passphrase" { type = string sensitive = true } resource "terrifi_network" "main" { name = "Main" purpose = "corporate" } resource "terrifi_wlan" "home" { name = "Home WiFi" passphrase = var.wifi_passphrase network_id = terrifi_network.main.id } ``` -------------------------------- ### Client device with fixed IP and network Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_device.md Assigns a fixed IP address to a client device within a specified network. Ensure the network is defined using terrifi_network. ```terraform resource "terrifi_network" "lan" { name = "Office LAN" purpose = "corporate" vlan_id = 10 subnet = "192.168.10.1/24" dhcp_enabled = true dhcp_start = "192.168.10.6" dhcp_stop = "192.168.10.254" } resource "terrifi_client_device" "server" { mac = "11:22:33:44:55:66" name = "Home Server" fixed_ip = "192.168.10.50" network_id = terrifi_network.lan.id } ``` -------------------------------- ### Run Linting Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/development.md Performs static code analysis and formatting checks using the configured linter. This helps maintain code quality and consistency. ```sh task lint ``` -------------------------------- ### Set Static Management IP Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md Configure a static IP address, netmask, gateway, and DNS servers for a device's management network. ```terraform resource "terrifi_device" "core_switch" { mac = "11:22:33:44:55:66" name = "Core Switch" config_network = { type = "static" ip = "192.168.1.5" netmask = "255.255.255.0" gateway = "192.168.1.1" dns1 = "1.1.1.1" dns2 = "8.8.8.8" } } ``` -------------------------------- ### Firewall zone with networks Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_zone.md Use this snippet to create a firewall zone and associate it with specific networks. The networks must be defined using the terrifi_network resource. ```terraform resource "terrifi_network" "iot" { name = "IoT" purpose = "corporate" vlan_id = 33 subnet = "192.168.33.1/24" } resource "terrifi_firewall_zone" "iot" { name = "IoT" network_ids = [terrifi_network.iot.id] } ``` -------------------------------- ### Client device with custom device icon Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_device.md Sets a custom device icon for a client device using its `device_type_id`. Use `terrifi list-device-types` to find available IDs. ```terraform resource "terrifi_client_device" "server" { mac = "aa:bb:cc:11:22:33" name = "Proxmox Server" device_type_id = 1084 } ``` -------------------------------- ### Use a firewall group in a policy Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_group.md Demonstrates how to reference a pre-defined firewall group (web_ports) within a firewall policy to control network traffic. ```terraform resource "terrifi_firewall_group" "web_ports" { name = "Web Ports" type = "port-group" members = ["80", "443"] } resource "terrifi_firewall_policy" "allow_web" { name = "Allow Web" action = "ALLOW" source { zone_id = terrifi_firewall_zone.lan.id } destination { zone_id = terrifi_firewall_zone.wan.id port_matching_type = "LIST" port_group_id = terrifi_firewall_group.web_ports.id } } ``` -------------------------------- ### Import a firewall zone Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_zone.md Use this command to import an existing firewall zone into your Terraform state. Replace with the actual zone ID. ```shell terraform import terrifi_firewall_zone.iot ``` -------------------------------- ### Custom schedule (date range with selected days) Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_policy.md This snippet allows for creating a firewall policy that applies only within a specific date range and on selected days of the week. Both `date_start` and `date_end` are required when using `CUSTOM` mode. ```terraform resource "terrifi_firewall_policy" "holiday_block" { name = "Block during holiday hours" action = "BLOCK" source { zone_id = terrifi_firewall_zone.guest.id } destination { zone_id = terrifi_firewall_zone.internal.id } schedule { mode = "CUSTOM" date_start = "2030-12-20" date_end = "2031-01-05" time_range_start = "09:00" time_range_end = "17:00" repeat_on_days = ["mon", "wed", "fri"] } } ``` -------------------------------- ### Basic firewall zone Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_zone.md Use this snippet to create a basic firewall zone. Ensure zone-based firewall is enabled on your UniFi controller. ```terraform resource "terrifi_firewall_zone" "iot" { name = "IoT" } ``` -------------------------------- ### Generate Terraform Imports for Resource Type Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/index.md Generate Terraform import and resource blocks for a given resource type to manage existing infrastructure. Supported resource types include client devices, DNS records, firewalls, networks, and WLANs. ```bash terrifi generate-imports ``` ```bash terrifi generate-imports terrifi_dns_record > imports.tf ``` ```terraform import { id = "abc123" to = terrifi_dns_record.web_example_com } resource "terrifi_dns_record" "web_example_com" { name = "web.example.com" value = "192.168.1.100" record_type = "A" } ``` -------------------------------- ### Assign client device to multiple groups Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_device.md Associates a client device with multiple client groups. Define client groups using `terrifi_client_group` resources. ```terraform resource "terrifi_client_group" "iot" { name = "IoT Devices" } resource "terrifi_client_group" "monitored" { name = "Monitored Devices" } resource "terrifi_client_device" "sensor" { mac = "aa:bb:cc:dd:ee:01" name = "Temperature Sensor" client_group_ids = [terrifi_client_group.iot.id, terrifi_client_group.monitored.id] } ``` -------------------------------- ### Basic Client Group Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_group.md Defines a basic client group with a specified name. Use this to create a new group for organizing client devices. ```terraform resource "terrifi_client_group" "smart_plugs" { name = "WiFi Smart Plugs" } ``` -------------------------------- ### WPA3 Transition Mode WiFi Network Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/wlan.md Enable WPA3 support with WPA3 transition mode, allowing both WPA2 and WPA3 clients to connect. The Wi-Fi passphrase must be set as an environment variable TF_VAR_wifi_passphrase. ```terraform resource "terrifi_wlan" "secure" { name = "Secure WiFi" passphrase = var.wifi_passphrase network_id = terrifi_network.main.id wpa3_support = true wpa3_transition = true } ``` -------------------------------- ### Reduce Terraform Parallelism for Low-End Hardware Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/index.md Limit concurrent API requests to prevent overwhelming the UniFi controller on low-end hardware. Experiment with values like 1, 2, or 5. ```sh tofu plan -parallelism=1 ``` ```sh tofu apply -parallelism=1 ``` -------------------------------- ### Corporate network with VLAN and DHCP Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/network.md Use this snippet to create a corporate network with specific VLAN ID, subnet, and DHCP configurations. Ensure the `purpose` is set to `corporate` and provide necessary DHCP settings if enabled. ```terraform resource "terrifi_network" "iot" { name = "IoT" purpose = "corporate" vlan_id = 33 subnet = "192.168.33.0/24" network_group = "LAN" dhcp_enabled = true dhcp_start = "192.168.33.10" dhcp_stop = "192.168.33.250" dhcp_lease = 86400 dhcp_dns = ["8.8.8.8", "8.8.4.4"] internet_access_enabled = true } ``` -------------------------------- ### Configure Device LED Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/device.md Disable the LED on an access point. Use `led_enabled = false` to turn off LEDs. ```terraform resource "terrifi_device" "office_ap" { mac = "aa:bb:cc:dd:ee:ff" name = "Office AP" led_enabled = false } ``` -------------------------------- ### Client device with local DNS record Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_device.md Assigns a local DNS record to a client device. This requires a fixed IP address to be set for the client. ```terraform resource "terrifi_client_device" "nas" { mac = "aa:bb:cc:11:22:33" name = "NAS" fixed_ip = "192.168.10.100" network_id = terrifi_network.lan.id local_dns_record = "nas.home" } ``` -------------------------------- ### Look up device by name Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/data-sources/device.md Use this snippet to find a UniFi device by its assigned name. ```terraform data "terrifi_device" "living_room_ap" { name = "Living Room AP" } ``` -------------------------------- ### Importing a WLAN Resource Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/wlan.md Import an existing WLAN resource into Terraform state. For non-default sites, use the format ':'. Note that the passphrase cannot be imported. ```shell terraform import terrifi_wlan.home ``` ```shell terraform import terrifi_wlan.home : ``` -------------------------------- ### Create a port group Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/firewall_group.md Defines a firewall group for ports, specifying a name, type, and a list of member ports. ```terraform resource "terrifi_firewall_group" "web_ports" { name = "Web Ports" type = "port-group" members = ["80", "443", "8080"] } ``` -------------------------------- ### Client device with fixed IP using network override Source: https://github.com/alexklibisz/terraform-provider-terrifi/blob/main/docs/resources/client_device.md Configures a fixed IP for a client device using a network override, which provides the network context without needing to explicitly set `network_id`. ```terraform resource "terrifi_client_device" "laptop" { mac = "22:33:44:55:66:77" name = "Work Laptop" fixed_ip = "192.168.10.20" network_override_id = terrifi_network.lan.id } ```