Terraform Quickstart
I think I am
Therefore, I am
I think
#
Welcome!Managing large numbers of setting in a webUI can be a total bummer. It'd be much nicer if we could describe our ZeroTier networks and membership settings as code. That would let us keep them in version control, and integrate them into our software delivery pipelines.
Now we can!
Terraform allows us to talk to the ZeroTier Central API and describe our network infrastructure, as code. This tutorial will walk you though how to get started.
To follow along step by step, you will need:
- A Github account,
- A ZeroTier Central account,
- A Terraform Cloud account.
It should take you about 10 minutes to through this tutorial. It will be done in browser without touching the command line at all.
#
Import the Quickstart repo.Use Github's Import feature to create a private copy of the ZeroTier Terraform Quickstart repo. We will hook this up to a Terraform runner on Terraform Cloud. After that, we will use Github's in-browser editing feature to drive the tutorial.
#
Create a Terraform workspaceNext, we create a Terraform workspace and attach it to our private Github repository. Be sure to select version control workflow, select the correct Github account, (we want the private copy, not the original), and give it a unique name.
#
Create a Central API TokenNext, we create an API token that Terraform will use to drive the ZeroTier Central API. Navigate to Account
-> API Access Tokens
.
#
Add token as a Workspace Environment VariableAdd the token as an Environment Variable to our workspace. This will let the
ZeroTier Terraform Provider
authenticate to the API. The variable must be named
ZEROTIER_CENTRAL_TOKEN
. Be sure to check the Sensitive
box.
#
Hello WorldThis example is probably the simplest thing you can do with
ZeroTier. It creates a single network, then joins two members. The
member_id
settings in the repository are made up, which is good
enough to demonstrate how to drive the API with Terraform. Feel free
to replace them with real Node IDs of any devices you may wish to join
to the networks.
In your Github repo, click on hello.tf
. There will be a little "edit" icon
around the section with the code. Uncomment the Terraform resources
and click the green "commit changes" button.
Queue a plan then "Confirm and Apply".
After Terraform applies the plan, check out the ZeroTier Cental webUI to confirm it was created.
#
Bridging NetworksThe next example manipulates the allow_ethernet_bridging
settings on
the Member objects. When running on machines with multiple physical
Ethernet interfaces, ZeroTier can be configured to pass layer2
traffic such as ARP, NDP, multicast, mDNS, etc.
To make this work, you'll need to go into your router's OS and configure a bridge between a physical interface and the ZeroTier interface.
The ZeroTier Network Terraform module provides a slightly nicer interface, letting us use CIDRs for our subnets.
Repeat the steps from "Hello World" with bridging.tf
After Terraform applies the plan, check out the ZeroTier Cental webUI to confirm it was created.
#
Network SegmentationThe next example creates the networks, red
, green
, and
yellow
. We define two groups. The red team gets access to the red
network, and the green team gets access to the green
network. Red
and green make yellow
.
Repeat the steps from "Hello World" with groups.tf
After Terraform applies the plan, check out the ZeroTier Cental webUI to confirm it was created.
#
Many to ManyIn the last example, show how to assign many members to many networks. This example used the Terraform setproduct function to find all possible combinations of two sets.
The zerotier_identity
resource is a distant cousin of the Terraform tls_private_key
resource. This resource would normally be used to inject secrets into
cloud instances via cloudinit
. We encourage you to use the
Terraform Cloud to keep your Terraform
state safe.
Repeat the steps from "Hello World" with many2many.tf
After Terraform applies the plan, check out the ZeroTier Cental webUI to confirm it was created.
#
Cleaning upWhen you're done experimenting with ZeroTier and Terraform, tear everything down by queueing a destroy plan.
#
That's all folks!If you like this tutorial, check out the ZeroTier Multicloud Terraform Quickstart next!
-s