zerotier

package
v0.1.48 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2021 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ZTMember = ValidatedSchema{
	YieldFunc:   ztMemberYield,
	CollectFunc: ztMemberCollect,
	Schema: map[string]*SchemaWrap{
		"network_id": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Required:    true,
				ForceNew:    true,
				Description: "ID of the network this member belongs to",
			},
		},
		"member_id": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Required:    true,
				ForceNew:    true,
				Description: "ID of this member.",
			},
		},
		"name": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Optional:    true,
				Computed:    true,
				Description: "Descriptive name of this member.",
			},
		},
		"description": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Optional:    true,
				Default:     "Managed by Terraform",
				Description: "Text description of this member.",
			},
		},
		"hidden": {
			Schema: &schema.Schema{
				Type:        schema.TypeBool,
				Optional:    true,
				Default:     false,
				Description: "Is this member visible?",
			},
		},
		"authorized": {
			Schema: &schema.Schema{
				Type:        schema.TypeBool,
				Optional:    true,
				Default:     true,
				Description: "Is the member authorized on the network?",
			},
		},
		"allow_ethernet_bridging": {
			Schema: &schema.Schema{
				Type:        schema.TypeBool,
				Optional:    true,
				Default:     false,
				Description: "Is this member allowed to activate ethernet bridging over the ZeroTier network?",
			},
		},
		"no_auto_assign_ips": {
			Schema: &schema.Schema{
				Type:        schema.TypeBool,
				Optional:    true,
				Default:     false,
				Description: "Exempt this member from the IP auto assignment pool on a Network",
			},
		},
		"ip_assignments": {
			Schema: &schema.Schema{
				Type:     schema.TypeList,
				Computed: true,
				Optional: true,
				Elem: &schema.Schema{
					Type: schema.TypeString,
				},
				Description: "List of IP address assignments",
			},
		},
		"capabilities": {
			Schema: &schema.Schema{
				Type:     schema.TypeList,
				Computed: true,
				Optional: true,
				Elem: &schema.Schema{
					Type: schema.TypeInt,
				},
				Description: "List of network capabilities",
			},
		},
	},
}

ZTMember is our internal validated schema. See schemawrap.go.

View Source
var ZTNetwork = ValidatedSchema{
	YieldFunc:   ztNetworkYield,
	CollectFunc: ztNetworkCollect,
	Schema: map[string]*SchemaWrap{
		"id": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Computed:    true,
				Description: "ZeroTier's internal network identifier, aka NetworkID",
			},
		},
		"creation_time": {
			Schema: &schema.Schema{
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "The time at which this network was created, in epoch seconds",
			},
		},
		"tf_last_updated": {
			Schema: &schema.Schema{
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "The time at which this terraform was last updated, in epoch seconds",
			},
		},
		"name": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Required:    true,
				Description: "The name of the network",
			},
			ValidatorFunc: strNonEmpty,
		},
		"description": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Optional:    true,
				Default:     "Managed by Terraform",
				Description: "The description of the network",
			},
		},
		"enable_broadcast": {
			Schema: &schema.Schema{
				Type:        schema.TypeBool,
				Optional:    true,
				Default:     true,
				Description: "Enable broadcast packets on the network",
			},
		},
		"mtu": {
			Schema: &schema.Schema{
				Type:        schema.TypeInt,
				Optional:    true,
				Description: "MTU to set on the client virtual network adapter",
			},
		},
		"multicast_limit": {
			Schema: &schema.Schema{
				Type:        schema.TypeInt,
				Optional:    true,
				Default:     32,
				Description: "Maximum number of recipients per multicast or broadcast. Warning - Setting this to 0 will disable IPv4 communication on your network!",
			},
		},
		"private": {
			Schema: &schema.Schema{
				Type:        schema.TypeBool,
				Optional:    true,
				Default:     false,
				Description: "Whether or not the network is private.  If false, members will *NOT* need to be authorized to join.",
			},
		},
		"route": {
			FromTerraformFunc: mkRoutes,
			ToTerraformFunc:   mktfRoutes,
			Schema: &schema.Schema{
				Type:     schema.TypeSet,
				Optional: true,
				ForceNew: true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"via": {
							Type:        schema.TypeString,
							Optional:    true,
							Description: "Gateway address",
						},
						"target": {
							Type:        schema.TypeString,
							Required:    true,
							Description: "Network to route for",
						},
					},
				},
				Description: "A ipv4 or ipv6 network route",
			},
		},
		"assign_ipv4": {
			FromTerraformFunc: mkipv4assign,
			ToTerraformFunc:   mktfipv4assign,
			Schema: &schema.Schema{
				Type:     schema.TypeMap,
				Optional: true,
				ForceNew: true,
				Elem: &schema.Schema{
					Type:        schema.TypeBool,
					Optional:    true,
					ForceNew:    true,
					Default:     true,
					Description: "Allowed map keys: `zerotier`, which must be true to gain ipv4 addressing automatically",
				},
				Description: "IPv4 Assignment RuleSets",
			},
		},
		"assign_ipv6": {
			FromTerraformFunc: mkipv6assign,
			ToTerraformFunc:   mktfipv6assign,
			Schema: &schema.Schema{
				Type:     schema.TypeMap,
				Optional: true,
				ForceNew: true,
				Elem: &schema.Schema{
					Type:     schema.TypeBool,
					Optional: true,
					ForceNew: true,
					Description: `
					Allowed map keys:
					- zerotier: standard ZeroTier ipv6 1:1 addressing
					- sixplane: 6PLANE assigns every host on a ZeroTier virtual network an IPv6 address within a private /40 network. More information: https://zerotier.atlassian.net/wiki/spaces/SD/pages/7274520/Using+NDP+Emulated+6PLANE+Addressing+With+Docker
					- rfc4193: RFC 4193 support. https://tools.ietf.org/html/rfc4193
					`,
				},
				Description: "IPv6 Assignment RuleSets",
			},
		},
		"assignment_pool": {
			FromTerraformFunc: mkIPRange,
			ToTerraformFunc:   mktfRanges,
			Schema: &schema.Schema{
				Type:     schema.TypeSet,
				Optional: true,
				ForceNew: true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"start": {
							Type:        schema.TypeString,
							Optional:    true,
							Description: "The first address in the assignment rule. This must be the lowest number in the pool. `start` must also be accompanied by `end`.",
						},
						"end": {
							Type:        schema.TypeString,
							Optional:    true,
							Description: "The last address in the assignment rule. This must be the highest number in the pool. end must also be accompanied by start.",
						},
						"cidr": {
							Type:        schema.TypeString,
							Optional:    true,
							Description: "An address range in CIDR notation. This must have no other keys assigned to this block as CIDR denotes the start and end address automatically",
						},
					},
				},
				Description: "Rules regarding IPv4 and IPv6 assignments",
			},
		},
		"flow_rules": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Optional:    true,
				Default:     "accept;",
				Description: "The layer 2 flow rules to apply to packets traveling across this network. Please see https://www.zerotier.com/manual/#3_4_1 for more information.",
			},
		},
	},
}

ZTNetwork is our internal validated schema. See schemawrap.go.

View Source
var ZTNetworkDS = ValidatedSchema{
	YieldFunc:   ztNetworkYield,
	CollectFunc: ztNetworkCollect,
	Schema: map[string]*SchemaWrap{
		"creation_time": {
			Schema: &schema.Schema{
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "The time at which this network was created, in epoch seconds",
			},
		},
		"id": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Optional:    true,
				Description: "ZeroTier's internal network identifier, aka NetworkID",
			},
		},
		"name": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Computed:    true,
				Description: "The name of the network",
			},
		},
		"description": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Computed:    true,
				Description: "The description of the network",
			},
		},
		"enable_broadcast": {
			Schema: &schema.Schema{
				Type:        schema.TypeBool,
				Computed:    true,
				Description: "Enable broadcast packets on the network",
			},
		},
		"mtu": {
			Schema: &schema.Schema{
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "MTU to set on the client virtual network adapter",
			},
		},
		"multicast_limit": {
			Schema: &schema.Schema{
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "Maximum number of recipients per multicast or broadcast. Warning - Setting this to 0 will disable IPv4 communication on your network!",
			},
		},
		"private": {
			Schema: &schema.Schema{
				Type:        schema.TypeBool,
				Computed:    true,
				Description: "Whether or not the network is private.  If false, members will *NOT* need to be authorized to join.",
			},
		},
		"route": {
			FromTerraformFunc: mkRoutes,
			ToTerraformFunc:   mktfRoutes,
			Schema: &schema.Schema{
				Type:     schema.TypeSet,
				Computed: true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"via": {
							Type:        schema.TypeString,
							Computed:    true,
							Description: "Gateway address",
						},
						"target": {
							Type:        schema.TypeString,
							Computed:    true,
							Description: "Network to route for",
						},
					},
				},
				Description: "A ipv4 or ipv6 network route",
			},
		},
		"assign_ipv4": {
			FromTerraformFunc: mkipv4assign,
			ToTerraformFunc:   mktfipv4assign,
			Schema: &schema.Schema{
				Type:     schema.TypeMap,
				Computed: true,
				Elem: &schema.Schema{
					Type:        schema.TypeBool,
					Computed:    true,
					Description: "Allowed map keys: `zerotier`, which must be true to gain ipv4 addressing automatically",
				},
				Description: "IPv4 Assignment RuleSets",
			},
		},
		"assign_ipv6": {
			FromTerraformFunc: mkipv6assign,
			ToTerraformFunc:   mktfipv6assign,
			Schema: &schema.Schema{
				Type:     schema.TypeMap,
				Computed: true,
				Elem: &schema.Schema{
					Type:     schema.TypeBool,
					Computed: true,
					Description: `
					Allowed map keys:
					- zerotier: standard ZeroTier ipv6 1:1 addressing
					- sixplane: 6PLANE assigns every host on a ZeroTier virtual network an IPv6 address within a private /40 network. More information: https://zerotier.atlassian.net/wiki/spaces/SD/pages/7274520/Using+NDP+Emulated+6PLANE+Addressing+With+Docker
					- rfc4193: RFC 4193 support. https://tools.ietf.org/html/rfc4193
					`,
				},
				Description: "IPv6 Assignment RuleSets",
			},
		},
		"assignment_pool": {
			FromTerraformFunc: mkIPRange,
			ToTerraformFunc:   mktfRanges,
			Schema: &schema.Schema{
				Type:     schema.TypeSet,
				Computed: true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"start": {
							Type:        schema.TypeString,
							Computed:    true,
							Description: "The first address in the assignment rule. This must be the lowest number in the pool. `start` must also be accompanied by `end`.",
						},
						"end": {
							Type:        schema.TypeString,
							Computed:    true,
							Description: "The last address in the assignment rule. This must be the highest number in the pool. end must also be accompanied by start.",
						},
						"cidr": {
							Type:        schema.TypeString,
							Computed:    true,
							Description: "An address range in CIDR notation. This must have no other keys assigned to this block as CIDR denotes the start and end address automatically",
						},
					},
				},
				Description: "Rules regarding IPv4 and IPv6 assignments",
			},
		},
		"flow_rules": {
			Schema: &schema.Schema{
				Type:        schema.TypeString,
				Computed:    true,
				Description: "The layer 2 flow rules to apply to packets traveling across this network. Please see https://www.zerotier.com/manual/#3_4_1 for more information.",
			},
		},
	},
}

ZTNetworkDS is our internal validated schema for data sources. See schemawrap.go.

Functions

func Provider

func Provider() *schema.Provider

Provider -

Types

type SchemaWrap

type SchemaWrap struct {
	// Schema is the terraform schema.
	Schema *schema.Schema
	// ValidatorFunc is a function, that if supplied, validates the data and
	// yields an error if the function returns one.
	ValidatorFunc func(interface{}) diag.Diagnostics
	// FromTerraformFunc converts data from terraform plans to the Value (see
	// below). It returns an error if it had trouble.
	FromTerraformFunc func(interface{}) (interface{}, diag.Diagnostics)
	// ToTerraformFunc converts data from the Value to the terraform
	// representation. This must *always* succeed (in practice, this has not been
	// an issue at this time)
	ToTerraformFunc func(interface{}) interface{}
	// EqualFunc is used in comparisons, which are used in determining if changes
	// need to be pushed to our API.
	EqualFunc func(interface{}, interface{}) bool
	// Value is the internal value; this is a representation suitable for using
	// in both ValidatedSchema.YieldFunc() and ValidatedSchema.CollectFunc
	// interchangeably, as in, they can be type asserted without panicking.
	Value interface{}
}

SchemaWrap wraps the terraform schema with validators and converters.

func (*SchemaWrap) Clone

func (sw *SchemaWrap) Clone() *SchemaWrap

type ValidatedSchema

type ValidatedSchema struct {
	// Schema is our schema. The key is the name. See SchemaWrap for more information.
	Schema map[string]*SchemaWrap
	// Should be programmed to yield the type at Yield time.
	YieldFunc func(ValidatedSchema) interface{}
	// Should be programmed to populate the validated schema with Set calls.
	CollectFunc func(ValidatedSchema, *schema.ResourceData, interface{}) diag.Diagnostics
}

ValidatedSchema is an internal schema for validating and managing lots of schema parameters. It is intended to be a more-or-less write-through cache of terraform information with validation and conversion along the way.

func (ValidatedSchema) Clone

func (vs ValidatedSchema) Clone() ValidatedSchema

func (ValidatedSchema) CollectFromObject

func (vs ValidatedSchema) CollectFromObject(d *schema.ResourceData, i interface{}) diag.Diagnostics

CollectFromObject is a pre-programmed call on the struct which accepts the known object and sets all the values appropriately.

func (ValidatedSchema) CollectFromTerraform

func (vs ValidatedSchema) CollectFromTerraform(d *schema.ResourceData) diag.Diagnostics

CollectFromTerraform collects all the properties listed in the validated schema, converts & validates them, and makes this object available for further use. Failure to call this method before others on the same transaction may result in undefined behavior.

func (ValidatedSchema) Get

func (vs ValidatedSchema) Get(key string) interface{}

Get retrieves the set value inside the schema.

func (ValidatedSchema) RemoteChanged

func (vs ValidatedSchema) RemoteChanged(d *schema.ResourceData) bool

RemoteChanged reports if our data source has changed. FIXME probably doesn't work yet; coming soon! :D

func (ValidatedSchema) Set

func (vs ValidatedSchema) Set(d *schema.ResourceData, key string, value interface{}) diag.Diagnostics

Set a value in terraform. This goes through our validation & conversion first.

func (ValidatedSchema) TerraformSchema

func (vs ValidatedSchema) TerraformSchema() map[string]*schema.Schema

TerraformSchema returns the unadulterated schema for use by terraform.

func (ValidatedSchema) Yield

func (vs ValidatedSchema) Yield() interface{}

Yield yields the type on request.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL