github.com/hugorut/terraform@v1.1.3/website/docs/language/functions/cidrhost.mdx (about)

     1  ---
     2  page_title: cidrhost - Functions - Configuration Language
     3  description: |-
     4    The cidrhost function calculates a full host IP address within a given
     5    IP network address prefix.
     6  ---
     7  
     8  # `cidrhost` Function
     9  
    10  `cidrhost` calculates a full host IP address for a given host number within
    11  a given IP network address prefix.
    12  
    13  ```hcl
    14  cidrhost(prefix, hostnum)
    15  ```
    16  
    17  `prefix` must be given in CIDR notation, as defined in
    18  [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).
    19  
    20  `hostnum` is a whole number that can be represented as a binary integer with
    21  no more than the number of digits remaining in the address after the given
    22  prefix. For more details on how this function interprets CIDR prefixes and
    23  populates host numbers, see the worked example for
    24  [`cidrsubnet`](/language/functions/cidrsubnet).
    25  
    26  Conventionally host number zero is used to represent the address of the
    27  network itself and the host number that would fill all the host bits with
    28  binary 1 represents the network's broadcast address. These numbers should
    29  generally not be used to identify individual hosts except in unusual
    30  situations, such as point-to-point links.
    31  
    32  This function accepts both IPv6 and IPv4 prefixes, and the result always uses
    33  the same addressing scheme as the given prefix.
    34  
    35  -> **Note:** As a historical accident, this function interprets IPv4 address
    36  octets that have leading zeros as decimal numbers, which is contrary to some
    37  other systems which interpret them as octal. We have preserved this behavior
    38  for backward compatibility, but recommend against relying on this behavior.
    39  
    40  ## Examples
    41  
    42  ```
    43  > cidrhost("10.12.112.0/20", 16)
    44  10.12.112.16
    45  > cidrhost("10.12.112.0/20", 268)
    46  10.12.113.12
    47  > cidrhost("fd00:fd12:3456:7890:00a2::/72", 34)
    48  fd00:fd12:3456:7890::22
    49  ```
    50  
    51  ## Related Functions
    52  
    53  * [`cidrsubnet`](/language/functions/cidrsubnet) calculates a subnet address under a given
    54    network address prefix.