Skip to content

Instantly share code, notes, and snippets.

@rswrz
Last active July 12, 2024 11:32
Show Gist options
  • Select an option

  • Save rswrz/2cdca1a738c247144844c0e4bac34d1f to your computer and use it in GitHub Desktop.

Select an option

Save rswrz/2cdca1a738c247144844c0e4bac34d1f to your computer and use it in GitHub Desktop.

Revisions

  1. rswrz revised this gist Jul 12, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion main.tf
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ resource "azurerm_network_interface" "this" {
    content {
    name = try(ip_configuration.value.name, "ipconfig${try((index(ip_configuration.value.*.name, ip_configuration.value.name) + 1), 1)}")
    private_ip_address_allocation = try(ip_configuration.private_ip_address_allocation, "Dynamic")
    subnet_id = try(ip_configuration.private_ip_address_allocation, null)
    subnet_id = try(ip_configuration.subnet_id, null)
    }
    }
    }
  2. rswrz revised this gist Jul 12, 2024. 2 changed files with 7 additions and 8 deletions.
    8 changes: 0 additions & 8 deletions main.tf
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,3 @@
    variable "location" {
    type = string
    }

    variable "resource_group_name" {
    type = string
    }

    locals {
    network_interfaces = coalescelist(var.network_interfaces, tolist([
    {
    7 changes: 7 additions & 0 deletions variables.tf
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    variable "location" {
    type = string
    }

    variable "resource_group_name" {
    type = string
    }

    variable "network_interfaces" {
    description = <<-EOT
  3. rswrz revised this gist Jul 12, 2024. 2 changed files with 102 additions and 83 deletions.
    102 changes: 102 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -3,3 +3,105 @@
    This is an example of a complex Terraform input variable with a description written in Markdown. [terraform-docs](https://terraform-docs.io/) can then generate a lovely README.

    For complex `description`s, it is recommended to use the terraform-docs formatter [markdown-document](https://terraform-docs.io/reference/markdown-document/).

    <!-- BEGIN_TF_DOCS -->
    ## Required Inputs

    The following input variables are required:

    ### <a name="input_location"></a> [location](#input\_location)

    Type: `string`

    ### <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name)

    Type: `string`

    ## Optional Inputs

    The following input variables are optional (have default values):

    ### <a name="input_network_interfaces"></a> [network\_interfaces](#input\_network\_interfaces)

    Description: A list of network interface objects to be created and attached to the virtual machine.

    Required object parameters:

    - `name` - The name of the Network Interface. Changing this forces a new resource to be created.

    Optional object parameters:

    - `accelerated_networking_enabled` - Should Accelerated Networking be enabled? Defaults to `false`.
    - `auxiliary_mode` - Specifies the auxiliary mode used to enable network high-performance feature on Network Virtual Appliances (NVAs). This feature offers competitive performance in Connections Per Second (CPS) optimization, along with improvements to handling large amounts of simultaneous connections. Possible values are `AcceleratedConnections`, `Floating`, `MaxConnections` and `None`.
    - `auxiliary_sku` - Specifies the SKU used for the network high-performance feature on Network Virtual Appliances (NVAs). Possible values are `A8`, `A4`, `A1`, `A2` and `None`.
    - `dns_servers` - A list of IP Addresses defining the DNS Servers which should be used for this Network Interface.
    - `edge_zone` - Specifies the Edge Zone within the Azure Region where this Network Interface should exist. Changing this forces a new Network Interface to be created.
    - `internal_dns_name_label` - The (relative) DNS Name used for internal communications between Virtual Machines in the same Virtual Network.
    - `ip_forwarding_enabled` - Should IP Forwarding be enabled? Defaults to `false`.
    - `ip_configurations` – A list ip configuration opbjects.

    A `ip_configurations` object supports the following optional parameters:

    - `name` - A name used for this IP Configuration. Default name is `ipconfigN`, where `N` is a consecutive number.
    - `gateway_load_balancer_frontend_ip_configuration_id` - The Frontend IP Configuration ID of a Gateway SKU Load Balancer.
    - `subnet_id` - The ID of the Subnet where this Network Interface should be located in.
    - `private_ip_address_version` - The IP Version to use. Possible values are IPv4 or IPv6. Defaults to IPv4.
    - `private_ip_address_allocation` - The allocation method used for the Private IP Address. Possible values are Dynamic and Static.
    - `public_ip_address_id` - Reference to a Public IP Address to associate with this NIC
    - `primary` - Is this the Primary IP Configuration? Must be true for the first ip\_configuration when multiple are specified. Defaults to false.
    - `private_ip_address` - The Static IP Address which should be used.

    #### Example

    ```hcl
    module "example" {
    source = "cloudeteer/vm/azurerm"
    name = "vm-example-dev-we-01"
    location = azurerm_resource_group.example.location
    resource_group_name = azurerm_resource_group.example.name
    image = "Win2022Datacenter"
    network_interfaces = [
    {
    name = "nic-example-dev-we-01
    ip_configurations = [
    {
    subnet_id = azurerm_subnet.example.id
    }
    ]
    }
    ]
    }
    ```

    Type:

    ```hcl
    list(
    object({
    name = string
    accelerated_networking_enabled = optional(bool)
    auxiliary_mode = optional(string)
    auxiliary_sku = optional(string)
    dns_servers = optional(list(string))
    edge_zone = optional(string)
    internal_dns_name_label = optional(string)
    ip_forwarding_enabled = optional(bool)
    ip_configurations = optional(list(object({
    gateway_load_balancer_frontend_ip_configuration_id = optional(string)
    name = optional(string)
    primary = optional(bool)
    private_ip_address = optional(string)
    private_ip_address_allocation = optional(string)
    private_ip_address_version = optional(string)
    public_ip_address_id = optional(string)
    subnet_id = optional(string)
    })))
    })
    )
    ```

    Default: `[]`
    <!-- END_TF_DOCS -->
    83 changes: 0 additions & 83 deletions variables.md
    Original file line number Diff line number Diff line change
    @@ -1,83 +0,0 @@
    ### <a name="input_network_interfaces"></a> [network\_interfaces](#input\_network\_interfaces)

    Description: A list of network interface objects to be created and attached to the virtual machine.

    Required parameters:

    - `name` - The name of the Network Interface. Changing this forces a new resource to be created.

    Optional parameters:

    - `accelerated_networking_enabled` - Should Accelerated Networking be enabled? Defaults to `false`.
    - `auxiliary_mode` - Specifies the auxiliary mode used to enable network high-performance feature on Network Virtual Appliances (NVAs). This feature offers competitive performance in Connections Per Second (CPS) optimization, along with improvements to handling large amounts of simultaneous connections. Possible values are `AcceleratedConnections`, `Floating`, `MaxConnections` and `None`.
    - `auxiliary_sku` - Specifies the SKU used for the network high-performance feature on Network Virtual Appliances (NVAs). Possible values are `A8`, `A4`, `A1`, `A2` and `None`.
    - `dns_servers` - A list of IP Addresses defining the DNS Servers which should be used for this Network Interface.
    - `edge_zone` - Specifies the Edge Zone within the Azure Region where this Network Interface should exist. Changing this forces a new Network Interface to be created.
    - `internal_dns_name_label` - The (relative) DNS Name used for internal communications between Virtual Machines in the same Virtual Network.
    - `ip_forwarding_enabled` - Should IP Forwarding be enabled? Defaults to `false`.
    - `ip_configurations` – A list ip configuration opbjects.

    A `ip_configurations` object supports the following optional parameters:

    - `name` - A name used for this IP Configuration. Default name is `ipconfigN`, where `N` is a consecutive number.
    - `gateway_load_balancer_frontend_ip_configuration_id` - The Frontend IP Configuration ID of a Gateway SKU Load Balancer.
    - `subnet_id` - The ID of the Subnet where this Network Interface should be located in.
    - `private_ip_address_version` - The IP Version to use. Possible values are IPv4 or IPv6. Defaults to IPv4.
    - `private_ip_address_allocation` - The allocation method used for the Private IP Address. Possible values are Dynamic and Static.
    - `public_ip_address_id` - Reference to a Public IP Address to associate with this NIC
    - `primary` - Is this the Primary IP Configuration? Must be true for the first ip\_configuration when multiple are specified. Defaults to false.
    - `private_ip_address` - The Static IP Address which should be used.

    Example:

    ```hcl
    module "example" {
    source = "cloudeteer/vm/azurerm"
    name = "vm-example-dev-we-01"
    location = azurerm_resource_group.example.location
    resource_group_name = azurerm_resource_group.example.name
    image = "Win2022Datacenter"
    network_interfaces = [
    {
    name = "nic-example-dev-we-01
    ip_configurations = [
    {
    subnet_id = azurerm_subnet.example.id
    }
    ]
    }
    ]
    }
    ```

    Type:

    ```hcl
    list(
    object({
    name = string
    accelerated_networking_enabled = optional(bool)
    auxiliary_mode = optional(string)
    auxiliary_sku = optional(string)
    dns_servers = optional(list(string))
    edge_zone = optional(string)
    internal_dns_name_label = optional(string)
    ip_forwarding_enabled = optional(bool)
    ip_configurations = optional(list(object({
    gateway_load_balancer_frontend_ip_configuration_id = optional(string)
    name = optional(string)
    primary = optional(bool)
    private_ip_address = optional(string)
    private_ip_address_allocation = optional(string)
    private_ip_address_version = optional(string)
    public_ip_address_id = optional(string)
    subnet_id = optional(string)
    })))
    })
    )
    ```

    Default: `[]`
  4. rswrz revised this gist Jul 12, 2024. 1 changed file with 32 additions and 0 deletions.
    32 changes: 32 additions & 0 deletions main.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    variable "location" {
    type = string
    }

    variable "resource_group_name" {
    type = string
    }

    locals {
    network_interfaces = coalescelist(var.network_interfaces, tolist([
    {
    name = "nic-default"
    }
    ]))
    }

    resource "azurerm_network_interface" "this" {
    for_each = { for item in local.network_interfaces : item.name => item }

    name = each.value.name
    location = var.location
    resource_group_name = var.resource_group_name

    dynamic "ip_configuration" {
    for_each = coalescelist(try(each.value.ip_configurations, []), [{ _ : null }])
    content {
    name = try(ip_configuration.value.name, "ipconfig${try((index(ip_configuration.value.*.name, ip_configuration.value.name) + 1), 1)}")
    private_ip_address_allocation = try(ip_configuration.private_ip_address_allocation, "Dynamic")
    subnet_id = try(ip_configuration.private_ip_address_allocation, null)
    }
    }
    }
  5. rswrz revised this gist Jul 12, 2024. No changes.
  6. rswrz revised this gist Jul 12, 2024. 2 changed files with 6 additions and 6 deletions.
    6 changes: 3 additions & 3 deletions variables.md
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,11 @@

    Description: A list of network interface objects to be created and attached to the virtual machine.

    Required object parameters:
    Required parameters:

    - `name` - The name of the Network Interface. Changing this forces a new resource to be created.

    Optional object parameters:
    Optional parameters:

    - `accelerated_networking_enabled` - Should Accelerated Networking be enabled? Defaults to `false`.
    - `auxiliary_mode` - Specifies the auxiliary mode used to enable network high-performance feature on Network Virtual Appliances (NVAs). This feature offers competitive performance in Connections Per Second (CPS) optimization, along with improvements to handling large amounts of simultaneous connections. Possible values are `AcceleratedConnections`, `Floating`, `MaxConnections` and `None`.
    @@ -28,7 +28,7 @@ A `ip_configurations` object supports the following optional parameters:
    - `primary` - Is this the Primary IP Configuration? Must be true for the first ip\_configuration when multiple are specified. Defaults to false.
    - `private_ip_address` - The Static IP Address which should be used.

    #### Example
    Example:

    ```hcl
    module "example" {
    6 changes: 3 additions & 3 deletions variables.tf
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,11 @@ variable "network_interfaces" {
    description = <<-EOT
    A list of network interface objects to be created and attached to the virtual machine.
    Required object parameters:
    Required parameters:
    - `name` - The name of the Network Interface. Changing this forces a new resource to be created.
    Optional object parameters:
    Optional parameters:
    - `accelerated_networking_enabled` - Should Accelerated Networking be enabled? Defaults to `false`.
    - `auxiliary_mode` - Specifies the auxiliary mode used to enable network high-performance feature on Network Virtual Appliances (NVAs). This feature offers competitive performance in Connections Per Second (CPS) optimization, along with improvements to handling large amounts of simultaneous connections. Possible values are `AcceleratedConnections`, `Floating`, `MaxConnections` and `None`.
    @@ -29,7 +29,7 @@ variable "network_interfaces" {
    - `primary` - Is this the Primary IP Configuration? Must be true for the first ip_configuration when multiple are specified. Defaults to false.
    - `private_ip_address` - The Static IP Address which should be used.
    #### Example
    Example:
    ```hcl
    module "example" {
  7. rswrz created this gist Jul 12, 2024.
    5 changes: 5 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    # Complex Terraform Input Variable

    This is an example of a complex Terraform input variable with a description written in Markdown. [terraform-docs](https://terraform-docs.io/) can then generate a lovely README.

    For complex `description`s, it is recommended to use the terraform-docs formatter [markdown-document](https://terraform-docs.io/reference/markdown-document/).
    83 changes: 83 additions & 0 deletions variables.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,83 @@
    ### <a name="input_network_interfaces"></a> [network\_interfaces](#input\_network\_interfaces)

    Description: A list of network interface objects to be created and attached to the virtual machine.

    Required object parameters:

    - `name` - The name of the Network Interface. Changing this forces a new resource to be created.

    Optional object parameters:

    - `accelerated_networking_enabled` - Should Accelerated Networking be enabled? Defaults to `false`.
    - `auxiliary_mode` - Specifies the auxiliary mode used to enable network high-performance feature on Network Virtual Appliances (NVAs). This feature offers competitive performance in Connections Per Second (CPS) optimization, along with improvements to handling large amounts of simultaneous connections. Possible values are `AcceleratedConnections`, `Floating`, `MaxConnections` and `None`.
    - `auxiliary_sku` - Specifies the SKU used for the network high-performance feature on Network Virtual Appliances (NVAs). Possible values are `A8`, `A4`, `A1`, `A2` and `None`.
    - `dns_servers` - A list of IP Addresses defining the DNS Servers which should be used for this Network Interface.
    - `edge_zone` - Specifies the Edge Zone within the Azure Region where this Network Interface should exist. Changing this forces a new Network Interface to be created.
    - `internal_dns_name_label` - The (relative) DNS Name used for internal communications between Virtual Machines in the same Virtual Network.
    - `ip_forwarding_enabled` - Should IP Forwarding be enabled? Defaults to `false`.
    - `ip_configurations` – A list ip configuration opbjects.

    A `ip_configurations` object supports the following optional parameters:

    - `name` - A name used for this IP Configuration. Default name is `ipconfigN`, where `N` is a consecutive number.
    - `gateway_load_balancer_frontend_ip_configuration_id` - The Frontend IP Configuration ID of a Gateway SKU Load Balancer.
    - `subnet_id` - The ID of the Subnet where this Network Interface should be located in.
    - `private_ip_address_version` - The IP Version to use. Possible values are IPv4 or IPv6. Defaults to IPv4.
    - `private_ip_address_allocation` - The allocation method used for the Private IP Address. Possible values are Dynamic and Static.
    - `public_ip_address_id` - Reference to a Public IP Address to associate with this NIC
    - `primary` - Is this the Primary IP Configuration? Must be true for the first ip\_configuration when multiple are specified. Defaults to false.
    - `private_ip_address` - The Static IP Address which should be used.

    #### Example

    ```hcl
    module "example" {
    source = "cloudeteer/vm/azurerm"
    name = "vm-example-dev-we-01"
    location = azurerm_resource_group.example.location
    resource_group_name = azurerm_resource_group.example.name
    image = "Win2022Datacenter"
    network_interfaces = [
    {
    name = "nic-example-dev-we-01
    ip_configurations = [
    {
    subnet_id = azurerm_subnet.example.id
    }
    ]
    }
    ]
    }
    ```

    Type:

    ```hcl
    list(
    object({
    name = string
    accelerated_networking_enabled = optional(bool)
    auxiliary_mode = optional(string)
    auxiliary_sku = optional(string)
    dns_servers = optional(list(string))
    edge_zone = optional(string)
    internal_dns_name_label = optional(string)
    ip_forwarding_enabled = optional(bool)
    ip_configurations = optional(list(object({
    gateway_load_balancer_frontend_ip_configuration_id = optional(string)
    name = optional(string)
    primary = optional(bool)
    private_ip_address = optional(string)
    private_ip_address_allocation = optional(string)
    private_ip_address_version = optional(string)
    public_ip_address_id = optional(string)
    subnet_id = optional(string)
    })))
    })
    )
    ```

    Default: `[]`
    81 changes: 81 additions & 0 deletions variables.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,81 @@

    variable "network_interfaces" {
    description = <<-EOT
    A list of network interface objects to be created and attached to the virtual machine.
    Required object parameters:
    - `name` - The name of the Network Interface. Changing this forces a new resource to be created.
    Optional object parameters:
    - `accelerated_networking_enabled` - Should Accelerated Networking be enabled? Defaults to `false`.
    - `auxiliary_mode` - Specifies the auxiliary mode used to enable network high-performance feature on Network Virtual Appliances (NVAs). This feature offers competitive performance in Connections Per Second (CPS) optimization, along with improvements to handling large amounts of simultaneous connections. Possible values are `AcceleratedConnections`, `Floating`, `MaxConnections` and `None`.
    - `auxiliary_sku` - Specifies the SKU used for the network high-performance feature on Network Virtual Appliances (NVAs). Possible values are `A8`, `A4`, `A1`, `A2` and `None`.
    - `dns_servers` - A list of IP Addresses defining the DNS Servers which should be used for this Network Interface.
    - `edge_zone` - Specifies the Edge Zone within the Azure Region where this Network Interface should exist. Changing this forces a new Network Interface to be created.
    - `internal_dns_name_label` - The (relative) DNS Name used for internal communications between Virtual Machines in the same Virtual Network.
    - `ip_forwarding_enabled` - Should IP Forwarding be enabled? Defaults to `false`.
    - `ip_configurations` – A list ip configuration opbjects.
    A `ip_configurations` object supports the following optional parameters:
    - `name` - A name used for this IP Configuration. Default name is `ipconfigN`, where `N` is a consecutive number.
    - `gateway_load_balancer_frontend_ip_configuration_id` - The Frontend IP Configuration ID of a Gateway SKU Load Balancer.
    - `subnet_id` - The ID of the Subnet where this Network Interface should be located in.
    - `private_ip_address_version` - The IP Version to use. Possible values are IPv4 or IPv6. Defaults to IPv4.
    - `private_ip_address_allocation` - The allocation method used for the Private IP Address. Possible values are Dynamic and Static.
    - `public_ip_address_id` - Reference to a Public IP Address to associate with this NIC
    - `primary` - Is this the Primary IP Configuration? Must be true for the first ip_configuration when multiple are specified. Defaults to false.
    - `private_ip_address` - The Static IP Address which should be used.
    #### Example
    ```hcl
    module "example" {
    source = "cloudeteer/vm/azurerm"
    name = "vm-example-dev-we-01"
    location = azurerm_resource_group.example.location
    resource_group_name = azurerm_resource_group.example.name
    image = "Win2022Datacenter"
    network_interfaces = [
    {
    name = "nic-example-dev-we-01
    ip_configurations = [
    {
    subnet_id = azurerm_subnet.example.id
    }
    ]
    }
    ]
    }
    ```
    EOT
    type = list(
    object({
    name = string
    accelerated_networking_enabled = optional(bool)
    auxiliary_mode = optional(string)
    auxiliary_sku = optional(string)
    dns_servers = optional(list(string))
    edge_zone = optional(string)
    internal_dns_name_label = optional(string)
    ip_forwarding_enabled = optional(bool)

    ip_configurations = optional(list(object({
    gateway_load_balancer_frontend_ip_configuration_id = optional(string)
    name = optional(string)
    primary = optional(bool)
    private_ip_address = optional(string)
    private_ip_address_allocation = optional(string)
    private_ip_address_version = optional(string)
    public_ip_address_id = optional(string)
    subnet_id = optional(string)
    })))
    })
    )
    default = []
    }