github.com/iaas-resource-provision/iaas-rpc@v1.0.7-0.20211021023331-ed21f798c408/website/docs/language/functions/cidrsubnets.html.md (about) 1 --- 2 layout: "language" 3 page_title: "cidrsubnets - Functions - Configuration Language" 4 sidebar_current: "docs-funcs-ipnet-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`](./cidrsubnet.html). `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 -> **Note:** [The Terraform module `hashicorp/subnets/cidr`](https://registry.terraform.io/modules/hashicorp/subnets/cidr) 43 wraps `cidrsubnets` to provide additional functionality for assigning symbolic 44 names to your networks and skipping prefixes for obsolete allocations. Its 45 documentation includes usage examples for several popular cloud virtual network 46 platforms. 47 48 ## Examples 49 50 ``` 51 > cidrsubnets("10.1.0.0/16", 4, 4, 8, 4) 52 [ 53 "10.1.0.0/20", 54 "10.1.16.0/20", 55 "10.1.32.0/24", 56 "10.1.48.0/20", 57 ] 58 59 > cidrsubnets("fd00:fd12:3456:7890::/56", 16, 16, 16, 32) 60 [ 61 "fd00:fd12:3456:7800::/72", 62 "fd00:fd12:3456:7800:100::/72", 63 "fd00:fd12:3456:7800:200::/72", 64 "fd00:fd12:3456:7800:300::/88", 65 ] 66 ``` 67 68 You can use nested `cidrsubnets` calls with 69 [`for` expressions](/docs/language/expressions/for.html) 70 to concisely allocate groups of network address blocks: 71 72 ``` 73 > [for cidr_block in cidrsubnets("10.0.0.0/8", 8, 8, 8, 8) : cidrsubnets(cidr_block, 4, 4)] 74 [ 75 [ 76 "10.0.0.0/20", 77 "10.0.16.0/20", 78 ], 79 [ 80 "10.1.0.0/20", 81 "10.1.16.0/20", 82 ], 83 [ 84 "10.2.0.0/20", 85 "10.2.16.0/20", 86 ], 87 [ 88 "10.3.0.0/20", 89 "10.3.16.0/20", 90 ], 91 ] 92 ``` 93 94 ## Related Functions 95 96 * [`cidrhost`](./cidrhost.html) calculates the IP address for a single host 97 within a given network address prefix. 98 * [`cidrnetmask`](./cidrnetmask.html) converts an IPv4 network prefix in CIDR 99 notation into netmask notation. 100 * [`cidrsubnet`](./cidrsubnet.html) calculates a single subnet address, allowing 101 you to specify its network number.