My Terraform-managed Unifi home network as Infrastructure as Code. Feel free to clone this repo to use as base for your project.
Please note that not all GUI functionality has been implemented yet. If you found any errors, feel free to create an issue.
- Set up your environment variable in an
.env
file. Seeexample.env
for example. - Terraform Cloud is used as the backend to store the
tfstate
. Please useterraform login
and configure your backend to your own workspace. - Each site is managed as a module from
main.tf
. Renamesite-modules
to your relevant site name. While it's possible to createsite
resource and manage it fromdefault
. It is easier to manage to hard-code the site ID directly frommain.tf
. - Put all clients in the relevant
site-*/data/$network.csv
. Seeclients.tf
. - If you have existing resources, import the resource in to manage it in Terraform. For example:
env $(cat example.env | xargs) terraform import module.site-neale.unifi_user_group.d80u20 5f10563e8f7939532b7984c1
- The resource
id
can be usually parsed from the browser. For example:
https://unifi.example.com:8443/manage/site/abcdefgh/settings/usergroups/edit/5f10563e8f7939532b7984c1
- This codebase is written for cloud controller
5.x
. Some attributes are deprecated in cloud controller6.x
, ignore any deprecation warning if you are running5.x
controller. - Run
terraform init
each time you add a module.