zerotier/terraform-provider-zerotier

Networks gets renamed, if sequence of networks change - i.e. Given NW: A,C When B is added then C gets renamed to B

andreasmarkussen opened this issue · 3 comments

We tried the Zerotier Terraform Plugin/module and we have actually put it on pause because of a show stopper for us.

Imagine that we have defined the following networks in Terraform

Customer_A
Customer_C

When we add a new Customer e.g. Customer_B, and we add it to e.g. a customers.tf file alphabetically, then Customer C, gets renamed to Customer_B and a new Customer_C is created.

It would be nice if we could mark that the Name is a unique identifier.

We have done a Plan and Apply so that the state file is correct.

terraform {
  required_providers {
    zerotier = {
      source  = "zerotier/zerotier"
      version = "1.4.2"
    }
  }
}

provider "zerotier" {
  # Configuration options
}

resource "zerotier_network" "customer_network" {
  count = length(var.customers)
  name  = "P${var.customers[count.index]["projectNumber"]} ${var.customers[count.index]["name"]} (${var.customers[count.index]["sequenceNumber"]})"

  route {
    target = "172.29.${var.customers[count.index]["sequenceNumber"]}.0/24"
  }
  assignment_pool {
    start = "172.29.${var.customers[count.index]["sequenceNumber"]}.220"
    end   = "172.29.${var.customers[count.index]["sequenceNumber"]}.250"
  }

  ## Administrators have to be set up manually via http://my.zerotier.com for now
  ## since we can get permissions working, and that is another thing we are missing

}

Hello!
Thank you for using our Terraform provider!

I'd love to help.

Unfortunately, this isn't specific to the ZeroTier provider.... This is a Terraform thing,
You'll have the same problem with any provider.
Long story short: Avoid using count. Count is the devil.

The "Modern Terraform Way" is to iterate over maps/objects, which will yield dynamic resource names, something like this:

resource "zerotier_network" "this" {
  for_each = var.customers_map
  name = each.value.name
  ...
  ...
}

One more thing... as you are aware, the zerotier_network resource is kind of funky to use in its raw form.
We wrote a helper module to make it easier to use cidrhost() and cidrsubnet() Terraform functions.
https://registry.terraform.io/modules/zerotier/network/zerotier/latest

Let me know if I can be of any more assistance!

-s

If you haven't already, check out this repo https://github.com/zerotier/terraform-quickstart

Closing this, as it's inactionable.
Please avoid count and use dynamic keys