github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/hcl2/functions/ipnet/cidrsubnets.mdx (about) 1 --- 2 layout: docs 3 page_title: cidrsubnets - Functions - Configuration Language 4 description: |- 5 The cidrsubnets function calculates a sequence of consecutive IP address 6 ranges within a particular CIDR prefix. 7 --- 8 9 # `cidrsubnets` Function 10 11 `cidrsubnets` calculates a sequence of consecutive IP address ranges within 12 a particular CIDR prefix. 13 14 ```hcl 15 cidrsubnets(prefix, newbits...) 16 ``` 17 18 `prefix` must be given in CIDR notation, as defined in 19 [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1). 20 21 The remaining arguments, indicated as `newbits` above, each specify the number 22 of additional network prefix bits for one returned address range. The return 23 value is therefore a list with one element per `newbits` argument, each 24 a string containing an address range in CIDR notation. 25 26 For more information on IP addressing concepts, see the documentation for the 27 related function [`cidrsubnet`](/docs/job-specification/hcl2/functions/ipnet/cidrsubnet). `cidrsubnet` calculates 28 a single subnet address within a prefix while allowing you to specify its 29 subnet number, while `cidrsubnets` can calculate many at once, potentially of 30 different sizes, and assigns subnet numbers automatically. 31 32 When using this function to partition an address space as part of a network 33 address plan, you must not change any of the existing arguments once network 34 addresses have been assigned to real infrastructure, or else later address 35 assignments will be invalidated. However, you _can_ append new arguments to 36 existing calls safely, as long as there is sufficient address space available. 37 38 This function accepts both IPv6 and IPv4 prefixes, and the result always uses 39 the same addressing scheme as the given prefix. 40 41 ## Examples 42 43 ```shell-session 44 > cidrsubnets("10.1.0.0/16", 4, 4, 8, 4) 45 [ 46 "10.1.0.0/20", 47 "10.1.16.0/20", 48 "10.1.32.0/24", 49 "10.1.48.0/20", 50 ] 51 52 > cidrsubnets("fd00:fd12:3456:7890::/56", 16, 16, 16, 32) 53 [ 54 "fd00:fd12:3456:7800::/72", 55 "fd00:fd12:3456:7800:100::/72", 56 "fd00:fd12:3456:7800:200::/72", 57 "fd00:fd12:3456:7800:300::/88", 58 ] 59 ``` 60 61 You can use nested `cidrsubnets` calls with 62 [`for` expressions](/docs/job-specification/hcl2/expressions#for-expressions) 63 to concisely allocate groups of network address blocks: 64 65 ```shell-session 66 > [for cidr_block in cidrsubnets("10.0.0.0/8", 8, 8, 8, 8) : cidrsubnets(cidr_block, 4, 4)] 67 [ 68 [ 69 "10.0.0.0/20", 70 "10.0.16.0/20", 71 ], 72 [ 73 "10.1.0.0/20", 74 "10.1.16.0/20", 75 ], 76 [ 77 "10.2.0.0/20", 78 "10.2.16.0/20", 79 ], 80 [ 81 "10.3.0.0/20", 82 "10.3.16.0/20", 83 ], 84 ] 85 ``` 86 87 ## Related Functions 88 89 - [`cidrhost`](/docs/job-specification/hcl2/functions/ipnet/cidrhost) calculates the IP address for a single host 90 within a given network address prefix. 91 - [`cidrnetmask`](/docs/job-specification/hcl2/functions/ipnet/cidrnetmask) converts an IPv4 network prefix in CIDR 92 notation into netmask notation. 93 - [`cidrsubnet`](/docs/job-specification/hcl2/functions/ipnet/cidrsubnet) calculates a single subnet address, allowing 94 you to specify its network number.