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