github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/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:** As a historical accident, this function interprets IPv4 address
    43  octets that have leading zeros as decimal numbers, which is contrary to some
    44  other systems which interpret them as octal. We have preserved this behavior
    45  for backward compatibility, but recommend against relying on this behavior.
    46  
    47  -> **Note:** [The Terraform module `hashicorp/subnets/cidr`](https://registry.terraform.io/modules/hashicorp/subnets/cidr)
    48  wraps `cidrsubnets` to provide additional functionality for assigning symbolic
    49  names to your networks and skipping prefixes for obsolete allocations. Its
    50  documentation includes usage examples for several popular cloud virtual network
    51  platforms.
    52  
    53  ## Examples
    54  
    55  ```
    56  > cidrsubnets("10.1.0.0/16", 4, 4, 8, 4)
    57  [
    58    "10.1.0.0/20",
    59    "10.1.16.0/20",
    60    "10.1.32.0/24",
    61    "10.1.48.0/20",
    62  ]
    63  
    64  > cidrsubnets("fd00:fd12:3456:7890::/56", 16, 16, 16, 32)
    65  [
    66    "fd00:fd12:3456:7800::/72",
    67    "fd00:fd12:3456:7800:100::/72",
    68    "fd00:fd12:3456:7800:200::/72",
    69    "fd00:fd12:3456:7800:300::/88",
    70  ]
    71  ```
    72  
    73  You can use nested `cidrsubnets` calls with
    74  [`for` expressions](/docs/language/expressions/for.html)
    75  to concisely allocate groups of network address blocks:
    76  
    77  ```
    78  > [for cidr_block in cidrsubnets("10.0.0.0/8", 8, 8, 8, 8) : cidrsubnets(cidr_block, 4, 4)]
    79  [
    80    [
    81      "10.0.0.0/20",
    82      "10.0.16.0/20",
    83    ],
    84    [
    85      "10.1.0.0/20",
    86      "10.1.16.0/20",
    87    ],
    88    [
    89      "10.2.0.0/20",
    90      "10.2.16.0/20",
    91    ],
    92    [
    93      "10.3.0.0/20",
    94      "10.3.16.0/20",
    95    ],
    96  ]
    97  ```
    98  
    99  ## Related Functions
   100  
   101  * [`cidrhost`](./cidrhost.html) calculates the IP address for a single host
   102    within a given network address prefix.
   103  * [`cidrnetmask`](./cidrnetmask.html) converts an IPv4 network prefix in CIDR
   104    notation into netmask notation.
   105  * [`cidrsubnet`](./cidrsubnet.html) calculates a single subnet address, allowing
   106    you to specify its network number.