github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/cidrsubnets.html.md (about) 1 --- 2 layout: "functions" 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 -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and 13 earlier, see 14 [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html). 15 16 `cidrsubnets` calculates a sequence of consecutive IP address ranges within 17 a particular CIDR prefix. 18 19 ```hcl 20 cidrsubnets(prefix, newbits...) 21 ``` 22 23 `prefix` must be given in CIDR notation, as defined in 24 [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1). 25 26 The remaining arguments, indicated as `newbits` above, each specify the number 27 of additional network prefix bits for one returned address range. The return 28 value is therefore a list with one element per `newbits` argument, each 29 a string containing an address range in CIDR notation. 30 31 For more information on IP addressing concepts, see the documentation for the 32 related function [`cidrsubnet`](./cidrsubnet.html). `cidrsubnet` calculates 33 a single subnet address within a prefix while allowing you to specify its 34 subnet number, while `cidrsubnets` can calculate many at once, potentially of 35 different sizes, and assigns subnet numbers automatically. 36 37 When using this function to partition an address space as part of a network 38 address plan, you must not change any of the existing arguments once network 39 addresses have been assigned to real infrastructure, or else later address 40 assignments will be invalidated. However, you _can_ append new arguments to 41 existing calls safely, as long as there is sufficient address space available. 42 43 This function accepts both IPv6 and IPv4 prefixes, and the result always uses 44 the same addressing scheme as the given prefix. 45 46 -> **Note:** [The Terraform module `hashicorp/subnets/cidr`](https://registry.terraform.io/modules/hashicorp/subnets/cidr) 47 wraps `cidrsubnets` to provide additional functionality for assigning symbolic 48 names to your networks and skipping prefixes for obsolete allocations. Its 49 documentation includes usage examples for several popular cloud virtual network 50 platforms. 51 52 ## Examples 53 54 ``` 55 > cidrsubnets("10.1.0.0/16", 4, 4, 8, 4) 56 [ 57 "10.1.0.0/20", 58 "10.1.16.0/20", 59 "10.1.32.0/24", 60 "10.1.48.0/20", 61 ] 62 63 > cidrsubnets("fd00:fd12:3456:7890::/56", 16, 16, 16, 32) 64 [ 65 "fd00:fd12:3456:7800::/72", 66 "fd00:fd12:3456:7800:100::/72", 67 "fd00:fd12:3456:7800:200::/72", 68 "fd00:fd12:3456:7800:300::/88", 69 ] 70 ``` 71 72 You can use nested `cidrsubnets` calls with 73 [`for` expressions](/docs/configuration/expressions.html#for-expressions) 74 to concisely allocate groups of network address blocks: 75 76 ``` 77 > [for cidr_block in cidrsubnets("10.0.0.0/8", 8, 8, 8, 8) : cidrsubnets(cidr_block, 4, 4)] 78 [ 79 [ 80 "10.0.0.0/20", 81 "10.0.16.0/20", 82 ], 83 [ 84 "10.1.0.0/20", 85 "10.1.16.0/20", 86 ], 87 [ 88 "10.2.0.0/20", 89 "10.2.16.0/20", 90 ], 91 [ 92 "10.3.0.0/20", 93 "10.3.16.0/20", 94 ], 95 ] 96 ``` 97 98 ## Related Functions 99 100 * [`cidrhost`](./cidrhost.html) calculates the IP address for a single host 101 within a given network address prefix. 102 * [`cidrnetmask`](./cidrnetmask.html) converts an IPv4 network prefix in CIDR 103 notation into netmask notation. 104 * [`cidrsubnet`](./cidrsubnet.html) calculates a single subnet address, allowing 105 you to specify its network number.