### unifi_setting_teleport Resource Example Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_teleport.md This example demonstrates how to configure the Teleport settings for a UniFi site. It shows how to enable Teleport and optionally specify a subnet and the site. ```terraform resource "unifi_setting_teleport" "example" { # Enable Teleport remote access functionality enabled = true # Optional subnet configuration for Teleport # Specify a CIDR notation subnet for Teleport to use subnet = "192.168.100.0/24" # Specify the site (optional, defaults to site configured in provider, otherwise "default") # site = "default" } ``` -------------------------------- ### Configure guest access settings for your UniFi network Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_guest_access.md This example demonstrates a comprehensive guest portal setup with various authentication options. It covers basic configuration, expiration settings, external captive portal detection, password protection, Google authentication, PayPal payment gateway, redirection, restricted DNS, and detailed portal customization. ```terraform resource "unifi_portal_file" "logo" { file_path = "logo.png" } resource "unifi_setting_guest_access" "guest_portal" { # Basic configuration auth = "hotspot" # Authentication type: none, hotspot, custom, or external portal_enabled = true # Enable the guest portal portal_use_hostname = true # Use hostname for the portal portal_hostname = "guest.example.com" # Portal hostname template_engine = "angular" # Portal template engine (angular or jsp) # Expiration settings for guest access expire = 1440 # Minutes until expiration expire_number = 1 # Number of time units expire_unit = 1440 # Time unit in minutes # Enable external captive portal detection ec_enabled = true # Password protection for guest access password = "guest-access-password" # Google authentication google { client_id = "your-google-client-id" client_secret = "your-google-client-secret" domain = "example.com" # Optional: limit sign-ins to a specific domain scope_email = true # Request email addresses during sign-in } # Payment option (PayPal) payment_gateway = "paypal" paypal { username = "business@example.com" password = "paypal-api-password" signature = "paypal-api-signature" use_sandbox = true # Set to false for production } # Redirecting guests after authentication redirect { url = "https://example.com/welcome" use_https = true to_https = true } # Restricted DNS for guests restricted_dns_servers = [ "1.1.1.1", "8.8.8.8" ] # Portal customization options portal_customization { customized = true # Portal appearance title = "Welcome to Our Guest Network" welcome_text = "Thanks for visiting our location. Please enjoy our complimentary WiFi." welcome_text_enabled = true welcome_text_position = "top" # Color scheme bg_color = "#f5f5f5" text_color = "#333333" link_color = "#0078d4" # Authentication dialog box box_color = "#ffffff" box_text_color = "#333333" box_link_color = "#0078d4" box_opacity = 90 box_radius = 5 # Logo logo_file_id = unifi_portal_file.logo.id # Button styling button_color = "#0078d4" button_text_color = "#ffffff" button_text = "Connect" # Legal information / Terms of Service tos_enabled = true tos = "By using this service, you agree to our terms and conditions. Unauthorized use is prohibited." # Languages supported languages = ["PL"] } } ``` -------------------------------- ### Unifi Setting DPI Example Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_dpi.md This example shows how to enable Deep Packet Inspection and DPI fingerprinting for a UniFi site. The site can be optionally specified. ```terraform resource "unifi_setting_dpi" "example" { # Enable Deep Packet Inspection enabled = true # Enable DPI fingerprinting for more accurate application identification fingerprinting_enabled = true # Specify the site (optional, defaults to site configured in provider, otherwise "default") # site = "default" } ``` -------------------------------- ### unifi_setting_usg Resource Example Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_usg.md This example demonstrates how to configure various advanced settings for a UniFi Security Gateway using the unifi_setting_usg resource. It includes configurations for Geo IP filtering, UPNP, DNS verification, TCP timeouts, ARP cache, DHCP, network tools, protocol modules, ICMP/LLDP, MSS clamping, offload settings, general timeouts, and security features. ```terraform resource "unifi_setting_usg" "example" { # Geo IP Filtering Configuration geo_ip_filtering = { block = "block" # Options: "block" or "allow" countries = ["UK", "CN", "AU"] traffic_direction = "both" # Options: "both", "ingress", or "egress" } # UPNP Configuration upnp = { nat_pmp_enabled = true secure_mode = true wan_interface = "WAN" } # DNS Verification Settings dns_verification = { domain = "example.com" primary_dns_server = "1.1.1.1" secondary_dns_server = "1.0.0.1" setting_preference = "manual" # Options: "auto" or "manual" } # TCP Timeout Settings tcp_timeouts = { close_timeout = 10 established_timeout = 3600 close_wait_timeout = 20 fin_wait_timeout = 30 last_ack_timeout = 30 syn_recv_timeout = 60 syn_sent_timeout = 120 time_wait_timeout = 120 } # ARP Cache Configuration arp_cache_timeout = "custom" # Options: "auto" or "custom" arp_cache_base_reachable = 60 # DHCP Configuration broadcast_ping = true dhcpd_hostfile_update = true dhcpd_use_dnsmasq = true dnsmasq_all_servers = true # DHCP Relay Configuration dhcp_relay = { agents_packets = "forward" # Options: "forward" or "replace" hop_count = 5 } dhcp_relay_servers = ["10.1.2.3", "10.1.2.4"] # Network Tools echo_server = "echo.example.com" # Protocol Modules ftp_module = true gre_module = true tftp_module = true # ICMP & LLDP Settings icmp_timeout = 20 lldp_enable_all = true # MSS Clamp Settings mss_clamp = "auto" # Options: "auto" or "custom" mss_clamp_mss = 1452 # Offload Settings offload_accounting = true offload_l2_blocking = true offload_scheduling = false # Timeout Settings other_timeout = 600 timeout_setting_preference = "auto" # Options: "auto" or "custom" # Security Settings receive_redirects = false send_redirects = true syn_cookies = true # UDP Timeout Settings udp_other_timeout = 30 udp_stream_timeout = 120 # Specify the site (optional) # site = "default" } ``` -------------------------------- ### CSV User Data Example Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/guides/csv-users.md This is an example of the expected CSV file format for managing Unifi users. Ensure your CSV includes 'mac', 'name', and 'note' columns. ```csv mac,name,note 01:23:45:67:89:AB,My Device,custom note ``` -------------------------------- ### unifi_setting_usw Resource Example Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_usw.md Enable DHCP snooping to protect against rogue DHCP servers. Optionally specify the site. ```terraform resource "unifi_setting_usw" "example" { # Enable DHCP snooping to protect against rogue DHCP servers dhcp_snoop = true # Specify the site (optional, defaults to site configured in provider, otherwise "default") # site = "default" } ``` -------------------------------- ### Basic unifi_setting_mgmt Resource Configuration Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_mgmt.md This example shows how to configure basic site-wide management settings, including auto-upgrades and SSH access. It references a specific site and includes optional SSH key configuration. ```terraform resource "unifi_site" "example" { description = "example" } resource "unifi_setting_mgmt" "example" { # Reference a specific site (optional, defaults to site configured in provider, otherwise "default") site = unifi_site.example.name # Auto upgrade settings auto_upgrade = true auto_upgrade_hour = 3 # Device management settings advanced_feature_enabled = true alert_enabled = true boot_sound = false debug_tools_enabled = true direct_connect_enabled = false led_enabled = true outdoor_mode_enabled = false unifi_idp_enabled = false wifiman_enabled = true # SSH access configuration ssh_enabled = true ssh_auth_password_enabled = true ssh_bind_wildcard = false ssh_username = "admin" # Optional: SSH key configuration ssh_key = [ { name = "Admin Key" type = "ssh-rsa" key = "AAAAB3NzaC1yc2EAAAADAQABAAABAQCxxx..." comment = "admin@example.com" } ] } ``` -------------------------------- ### Basic unifi_wlan Resource Configuration Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/wlan.md This example demonstrates how to create a basic wireless network (SSID) with WPA2/WPA3 security, assigning it to a specific network and access point group. ```terraform variable "vlan_id" { default = 10 } data "unifi_ap_group" "default" { } data "unifi_user_group" "default" { } resource "unifi_network" "vlan" { name = "wifi-vlan" purpose = "corporate" subnet = "10.0.0.1/24" vlan_id = var.vlan_id dhcp_start = "10.0.0.6" dhcp_stop = "10.0.0.254" dhcp_enabled = true } resource "unifi_wlan" "wifi" { name = "myssid" passphrase = "12345678" security = "wpapsk" # enable WPA2/WPA3 support wpa3_support = true wpa3_transition = true pmf_mode = "optional" network_id = unifi_network.vlan.id ap_group_ids = [data.unifi_ap_group.default.id] user_group_id = data.unifi_user_group.default.id } ``` -------------------------------- ### Create a unifi_user_group Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/user_group.md Example of creating a user group with specified download and upload bandwidth limits. ```terraform resource "unifi_user_group" "wifi" { name = "wifi" qos_rate_max_down = 2000 # 2mbps qos_rate_max_up = 10 # 10kbps } ``` -------------------------------- ### Basic unifi_user Resource Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/user.md Example of creating a unifi_user resource with essential details like MAC, name, and a fixed IP assignment within a specific network. ```terraform resource "unifi_user" "test" { mac = "01:23:45:67:89:AB" name = "some client" note = "my note" fixed_ip = "10.0.0.50" network_id = unifi_network.my_vlan.id } ``` -------------------------------- ### Basic Dynamic DNS Configuration Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/dynamic_dns.md This example demonstrates a basic configuration for a Dynamic DNS service using DynDNS. It requires the service name, a hostname, and credentials for the DDNS provider. The server field is often optional as the controller typically knows the correct update server for common providers. ```terraform resource "unifi_dynamic_dns" "test" { service = "dyndns" host_name = "my-network.example.com" server = "domains.google.com" login = var.dns_login password = var.dns_password } ``` -------------------------------- ### Example Usage of unifi_setting_auto_speedtest Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_auto_speedtest.md Enables automatic speedtest functionality and schedules it using cron syntax. Optionally specify the site. ```terraform resource "unifi_setting_auto_speedtest" "example" { # Enable automatic speedtest functionality enabled = true # Schedule for running speedtests using cron syntax # This example runs at midnight every day cron = "0 0 * * *" # Specify the site (optional, defaults to site configured in provider, otherwise "default") # site = "default" } ``` -------------------------------- ### Create a Firewall Rule Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/firewall_rule.md This example demonstrates how to create a firewall rule to drop all traffic to a specific IP address from the LAN network. Ensure the `rule_index` is within the recommended range for custom rules. ```terraform variable "ip_address" { type = string } resource "unifi_firewall_rule" "drop_all" { name = "drop all" action = "drop" ruleset = "LAN_IN" rule_index = 2011 protocol = "all" dst_address = var.ip_address } ``` -------------------------------- ### unifi_firewall_zone Resource Example Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/firewall_zone.md Creates a firewall zone named 'my-zone' and associates it with the network defined by 'unifi_network.network'. Ensure the 'unifi_network' resource is defined prior to this one. ```terraform resource "unifi_network" "network" { name = "my-network" purpose = "corporate" subnet = "10.0.10.0/24" vlan_id = "400" } resource "unifi_firewall_zone" "zone" { name = "my-zone" networks = [unifi_network.network.id] } ``` -------------------------------- ### Manage UniFi Device with Port Overrides Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/device.md This example demonstrates how to manage a UniFi device, including configuring specific port overrides for PoE and disabled ports, and setting up port aggregation. It utilizes data sources for port profiles and defines custom port profiles. ```terraform data "unifi_port_profile" "disabled" { # look up the built-in disabled port profile name = "Disabled" } resource "unifi_port_profile" "poe" { name = "poe" forward = "customize" native_networkconf_id = var.native_network_id tagged_networkconf_ids = [ var.some_vlan_network_id, ] poe_mode = "auto" } resource "unifi_device" "us_24_poe" { # optionally specify MAC address to skip manually importing # manual import is the safest way to add a device mac = "01:23:45:67:89:AB" name = "Switch with POE" port_override { number = 1 name = "port w/ poe" port_profile_id = unifi_port_profile.poe.id } port_override { number = 2 name = "disabled" port_profile_id = data.unifi_port_profile.disabled.id } # port aggregation for ports 11 and 12 port_override { number = 11 op_mode = "aggregate" aggregate_num_ports = 2 } } ``` -------------------------------- ### Configure IPS Settings Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_ips.md Example of how to configure IPS settings, including enabling IPS mode, specifying networks, setting advanced filtering, enabling threat categories, configuring ad blocking, setting up honeypots, and defining DNS filters. This snippet demonstrates a comprehensive configuration for network threat protection. ```terraform resource "unifi_network" "test" { name = "My Network" purpose = "corporate" subnet = "192.168.1.0/24" vlan_id = 10 } resource "unifi_setting_ips" "example" { # Set IPS mode to "ips" (Intrusion Prevention System) # Other valid options: "ids" (Intrusion Detection System) or "disabled" ips_mode = "ips" # Networks on which IPS/IDS should be enabled enabled_networks = [unifi_network.test.id] # Advanced filtering preference # Valid options: "disabled", "manual", or "auto" advanced_filtering_preference = "manual" # Categories of threats to detect/prevent enabled_categories = [ "emerging-dos", "emerging-exploit", "emerging-malware" ] # Ad blocking configuration ad_blocked_networks = [unifi_network.test.id] # Honeypot configuration honeypots = [ { ip_address = "192.168.1.10" network_id = unifi_network.test.id } ] # DNS filtering configuration dns_filters = [ { name = "Work Filter" filter = "work" description = "Block non-work related sites" # Sites that are always allowed allowed_sites = [ "example.com", "company.com" ] # Sites that are always blocked blocked_sites = [ "gaming.example.com", "social.example.com" ] # Top-level domains to block blocked_tld = [ "xyz" ] } ] # Specify the site (optional, defaults to site configured in provider, otherwise "default") # site = "default" } ``` -------------------------------- ### Unifi Setting Network Optimization Example Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_network_optimization.md Enables network optimization features for a UniFi site. The site can be optionally specified; otherwise, it defaults to the provider's configured site or 'default'. ```terraform resource "unifi_setting_network_optimization" "example" { # Enable network optimization features enabled = true # Specify the site (optional, defaults to site configured in provider, otherwise "default") # site = "default" } ``` -------------------------------- ### Create a UniFi Wireless Network Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/README.md Example of creating a wireless network (WLAN) with specified security and passphrase, linked to a network ID. Requires a corresponding `unifi_network` resource. ```hcl resource "unifi_wlan" "wifi" { name = "My WiFi Network" security = "wpa2" passphrase = "mystrongpassword" network_id = unifi_network.vlan_50.id } resource "unifi_network" "vlan_50" { name = "VLAN 50" purpose = "corporate" subnet = "10.0.50.0/24" vlan_id = 50 } ``` -------------------------------- ### Import a unifi_user_group Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/user_group.md Example of how to import an existing user group into Terraform state using its ID. ```shell # import using the ID terraform import unifi_user_group.wifi 5fe6261995fe130013456a36 ``` -------------------------------- ### Retrieve network data by ID from a user record Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/data-sources/network.md This example demonstrates fetching network configuration using a network ID obtained from another data source, such as unifi_user. This is useful when the network is associated with a specific device or user. ```terraform #retrieve network data from user record data "unifi_user" "my_device" { mac = "01:23:45:67:89:ab" } data "unifi_network" "my_network" { id = data.unifi_user.my_device.network_id } ``` -------------------------------- ### Import Unifi Network Resource Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/index.md Example of re-importing a network resource using 'terraform import'. This may be necessary for resources with enhanced functionality to reconcile state differences. ```bash terraform import unifi_network.my_network 5dc28e5e9106d105bdc87217 ``` -------------------------------- ### unifi_dns_record Data Source Example Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/data-sources/dns_record.md Use this data source to look up DNS records by their name or record content. It's useful for validating existing DNS configurations or referencing DNS records in other resources. ```terraform data "unifi_dns_record" "by_name" { name = "example.mydomain.com" } data "unifi_dns_record" "by_record" { record = "192.168.0.1" } ``` -------------------------------- ### Install UniFi Terraform Provider Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/README.md Declare the UniFi provider in your Terraform configuration to manage UniFi resources. Ensure you use a recent version. ```hcl terraform { required_providers { unifi = { source = "filipowm/unifi" version = "~> 1.0.0" # Use the latest version } } } ``` -------------------------------- ### Retrieve AP Group ID Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/data-sources/ap_group.md Use this data source to get the ID of an AP group by its name. Leave the name blank to retrieve the default AP group. ```terraform data "unifi_ap_group" "default" { } ``` -------------------------------- ### Configure a WAN Network with PPPoE Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/network.md Sets up a WAN network connection using PPPoE authentication. Requires providing credentials and specifying network group, IP, and egress QoS settings. ```terraform resource "unifi_network" "wan" { name = "wan" purpose = "wan" wan_networkgroup = "WAN" wan_type = "pppoe" wan_ip = "192.168.1.1" wan_egress_qos = 1 wan_username = "username" x_wan_password = "password" } ``` -------------------------------- ### Import Unifi Network from Another Site Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/network.md Import a Unifi network resource from a different site using a site key and network ID. Ensures correct resource association. ```shell # import from another site terraform import unifi_network.mynetwork bfa2l6i7:5dc28e5e9106d105bdc87217 ``` -------------------------------- ### Configure Unifi Provider with API Key Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/index.md Use API Key authentication for the Unifi provider, recommended for newer controller versions. Ensure 'api_url' and 'allow_insecure' are set appropriately. ```hcl provider "unifi" { api_key = var.api_key api_url = var.api_url allow_insecure = var.insecure } ``` -------------------------------- ### Guest Access Configuration Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_guest_access.md This snippet outlines the configurable parameters for guest access, covering authentication, network settings, and portal behavior. ```APIDOC ## Guest Access Configuration ### Description Configure various aspects of guest access, including authentication methods, network restrictions, and portal settings. ### Parameters #### Optional Parameters - `allowed_subnet` (String) - Subnet allowed for guest access. - `auth` (String) - Authentication method for guest access. Valid values: `none`, `hotspot`, `facebook_wifi`, `custom`. - `auth_url` (String) - URL for authentication. Must be a valid URL including the protocol. - `authorize` (Attributes) - Authorize.net payment settings. - `custom_ip` (String) - Custom IP address. Must be a valid IPv4 address. - `ec_enabled` (Boolean) - Enable enterprise controller functionality. - `expire` (Number) - Expiration time for guest access. - `expire_number` (Number) - Number value for the expiration time. - `expire_unit` (Number) - Unit for the expiration time. Valid values: `1` (Minute), `60` (Hour), `1440` (Day), `10080` (Week). - `facebook` (Attributes) - Facebook authentication settings. - `facebook_wifi` (Attributes) - Facebook WiFi authentication settings. - `google` (Attributes) - Google authentication settings. - `ippay` (Attributes) - IPpay Payments settings. - `merchant_warrior` (Attributes) - MerchantWarrior payment settings. - `password` (String, Sensitive) - Password for guest access. - `payment_gateway` (String) - Payment gateway. Valid values: `paypal`, `stripe`, `authorize`, `quickpay`, `merchantwarrior`, `ippay`. - `paypal` (Attributes) - PayPal payment settings. - `portal_customization` (Attributes) - Portal customization settings. - `portal_enabled` (Boolean) - Enable the guest portal. - `portal_hostname` (String) - Hostname to use for the captive portal. - `portal_use_hostname` (Boolean) - Use a custom hostname for the portal. - `quickpay` (Attributes) - QuickPay payment settings. - `radius` (Attributes) - RADIUS authentication settings. - `redirect` (Attributes) - Redirect after authentication settings. - `restricted_subnet` (String) - Subnet for restricted guest access. - `site` (String) - The name of the UniFi site where this resource should be applied. - `stripe` (Attributes) - Stripe payment settings. - `template_engine` (String) - Template engine for the portal. Valid values: `jsp`, `angular`. - `voucher_customized` (Boolean) - Whether vouchers are customized. - `voucher_enabled` (Boolean) - Enable voucher-based authentication for guest access. - `wechat` (Attributes) - WeChat authentication settings. ### Read-Only Parameters - `facebook_enabled` (Boolean) - Whether Facebook authentication for guest access is enabled. - `google_enabled` (Boolean) - Whether Google authentication for guest access is enabled. - `id` (String) - The unique identifier of this resource. - `password_enabled` (Boolean) - Enable password authentication for guest access. - `payment_enabled` (Boolean) - Enable payment for guest access. - `radius_enabled` (Boolean) - Whether RADIUS authentication for guest access is enabled. - `redirect_enabled` (Boolean) - Whether redirect after authentication is enabled. - `restricted_dns_enabled` (Boolean) - Whether restricted DNS servers for guest networks are enabled. - `wechat_enabled` (Boolean) - Whether WeChat authentication for guest access is enabled. ### Nested Schemas #### Nested Schema for `authorize` Required: - `login_id` (String) - Authorize.net login ID for authentication. - `transaction_key` (String) - Authorize.net transaction key for authentication. Optional: - `use_sandbox` (Boolean) - Use sandbox mode for Authorize.net payments. ``` -------------------------------- ### Import Unifi Network by Name Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/network.md Import a Unifi network resource by its name. This method is convenient when the network name is known and unique. ```shell # import network by name terraform import unifi_network.mynetwork name=LAN ``` -------------------------------- ### Create a UniFi Site Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/site.md Use this snippet to create a new UniFi site. The description is used as the display name in the UniFi controller interface. ```terraform resource "unifi_site" "mysite" { description = "mysite" } ``` -------------------------------- ### Basic unifi_portal_file Usage Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/portal_file.md Uploads a file to the UniFi controller. Ensure the file exists on the local filesystem where Terraform is executed. ```terraform resource "unifi_portal_file" "file" { file_path = "/Users/username/Downloads/portal.png" } ``` -------------------------------- ### Configure UniFi Provider with Username/Password Authentication Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/index.md This configuration demonstrates how to authenticate with the UniFi controller using traditional username and password credentials. Environment variables are supported for credentials and controller URL. ```terraform provider "unifi" { username = var.username # optionally use UNIFI_USERNAME env var password = var.password # optionally use UNIFI_PASSWORD env var api_url = var.api_url # optionally use UNIFI_API env var # you may need to allow insecure TLS communications unless you have configured # certificates for your controller allow_insecure = var.insecure # optionally use UNIFI_INSECURE env var # if you are not configuring the default site, you can change the site # site = "foo" or optionally use UNIFI_SITE env var } ``` -------------------------------- ### Configure UniFi Provider Authentication Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/README.md Configure the UniFi provider using environment variables for API key or username/password authentication. Alternatively, set credentials directly in the provider block. Optional settings like `allow_insecure` and `site` can also be configured. ```hcl # Using environment variables (recommended) # Export these variables: # export UNIFI_API_KEY="my-api-key" # export UNIFI_USERNAME="admin" # export UNIFI_PASSWORD="password" # export UNIFI_API="https://unifi.example.com:8443" # export UNIFI_INSECURE=true # Only if using self-signed certificates # Or configure directly in the provider block provider "unifi" { api_key = "my-api-key" # username = "admin" # Use either username/password or API key # password = "password" api_url = "https://unifi.example.com:8443" # Optional settings allow_insecure = true # For self-signed certificates site = "default" # Specify non-default site } ``` -------------------------------- ### Configure Unifi Provider with Username/Password Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/index.md Configure the Unifi provider using traditional username and password authentication. This method is backward compatible. ```hcl provider "unifi" { username = var.username password = var.password api_url = var.api_url allow_insecure = var.insecure } ``` -------------------------------- ### Enable Magic Site-to-Site VPN Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_magic_site_to_site_vpn.md Use this snippet to enable the Magic Site-to-Site VPN functionality. The site can be optionally specified; otherwise, it defaults to the provider's configured site or 'default'. ```terraform resource "unifi_setting_magic_site_to_site_vpn" "example" { # Enable Magic Site-to-Site VPN functionality enabled = true # Specify the site (optional, defaults to site configured in provider, otherwise "default") # site = "default" } ``` -------------------------------- ### Create an A DNS Record Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/dns_record.md Use this snippet to create an A record, mapping a hostname to an IPv4 address. Ensure the 'name' and 'record' fields are correctly set for your desired mapping. ```terraform resource "unifi_dns_record" "a_record" { name = "example.mydomain.com" type = "A" record = "192.168.1.190" } ``` -------------------------------- ### unifi_setting_lcd_monitor Resource Schema Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/setting_lcd_monitor.md Defines the schema for the unifi_setting_lcd_monitor resource, outlining the configurable parameters for LCD display settings. ```APIDOC ## Schema ### Required - `enabled` (Boolean) Whether the LCD display is enabled. ### Optional - `brightness` (Number) The brightness level of the LCD display. Valid values are 1-100. - `idle_timeout` (Number) The time in seconds after which the display turns off when idle. Valid values are 10-3600. - `site` (String) The name of the UniFi site where this resource should be applied. If not specified, the default site will be used. - `sync` (Boolean) Whether to synchronize display settings across multiple devices. - `touch_event` (Boolean) Whether touch interactions with the display are enabled. ### Read-Only - `id` (String) The unique identifier of this resource. ``` -------------------------------- ### Import unifi_firewall_zone Resource Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/resources/firewall_zone.md Imports an existing firewall zone into Terraform state. Can import from the provider's configured site or a specified site. ```shell # import from provider configured site terraform import unifi_firewall_zone.myzone 5dc28e5e9106d105bdc87217 # import from another site terraform import unifi_firewall_zone.myzone another-site:5dc28e5e9106d105bdc87217 ``` -------------------------------- ### Apply Firewall Rule to Multiple Sites Source: https://github.com/filipowm/terraform-provider-unifi/blob/main/docs/guides/multiple-site-firewall.md Use `for_each` to iterate over a list of site IDs and apply the same firewall rule to each site. The `site` attribute is dynamically set using `each.key`. ```terraform resource "unifi_firewall_rule" "rule" { # list of sites for_each = toset(["default", "vq98kwez", "bfa2l6i7"]) # use the key of the list as the site value site = each.key name = "drop all" action = "drop" ruleset = "LAN_IN" rule_index = 2011 protocol = "all" dst_address = var.ip_address } ```