diff --git a/README.md b/README.md
index 9ed1e96..c7ccb45 100644
--- a/README.md
+++ b/README.md
@@ -62,13 +62,16 @@ module "linux_virtual_machine" {
| [suffix](#input\_suffix)| Optional suffix that would be added to the end of resources names. It is recommended to use dash at the beginning of variable (e.x., '-example') | `string` | "" | no |
| [location](#input\_location)| Azure location | `string` | n/a | yes |
| [custom\_virtual\_machine\_name](#input\_custom\_virtual\_machine\_name)| Specifies the name of the virtual machine name resource | `string` | null | no |
-| [custom\_network\_interface\_name](#input\_custom\_network\_interface\_name)| Specifies the name of the virtual machine interface name resource | `string` | null | no |
+| [custom\_network\_interface\_first\_name](#input\_custom\_network\_interface\_first\_name)| Specifies the name of the virtual machine first interface name resource | `string` | null | no |
+| [custom\_network\_interface\_second\_name](#input\_custom\_network\_interface\_second\_name)| Specifies the name of the virtual machine second interface name resource | `string` | null | no |
| [custom\_public\_ip\_name](#input\_custom\_public\_ip\_name)| Specifies the name of the public ip name name resource | `string` | null | no |
| [tags](#input\_tags)| Resource tags | map(any) | {} | no |
-| [subnet\_id](#input\_subnet\_id)| The ID of the Subnet where this Network Interface should be located in. | `string` | n/a | yes |
+| [subnet\_id](#input\_subnet\_id)| The ID of the Subnet where this Network first Interface should be located in. | `string` | n/a | yes |
+| [subnet_id\_second\_nic](#input\_subnet_id\_second\_nic)| The ID of the Subnet where this Network second Interface should be located in. | `string` | "" | no |
| [public\_ip\_enabled](#input\_public\_ip\_enabled)| Boolean flag to enable Public Ip address creation and assignment to Virtual Machine | `bool` | true | no |
| [public\_ip\_allocation\_method](#input\_public\_ip\_allocation_method)| Defines the allocation method for this IP address. Possible values are Static or Dynamic | `string` | Static | no |
-| [network\_interface\_private\_ip_address\_allocation](#input\_network\_interface\_private\_ip_address\_allocation)| The allocation method used for the Private IP Address. | `string` | Dynamic | no |
+| [network\_interface\_private\_ip_address\_allocation](#input\_network\_interface\_private\_ip_address\_allocation)| The allocation method used for the Private IP Address. | `string` | Dynamic | no |
+| [network\_interface\_private\_ip\_address\_allocation\_nic\_second](#input\_network\_interface\_private\_ip\_address\_allocation\_nic\_second)| The allocation method used for second nic the Private IP Address. | `string` | Static | no |
| [vm\_size](#input\_vm\_size)| The SKU which should be used for this Virtual Machine. | `string` | Standard_F2 | no |
| [vm\_admin\_username](#input\_vm\_admin\_username)| The username of the local administrator used for the Virtual Machine. | `string` | adminuser | no |
| [vm\_admin\_password](#input\_vm\_admin\_password)| The password of the local administrator used for the Virtual Machine. | `string` | null | no |
@@ -87,7 +90,8 @@ No modules.
| Name | Type |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| [azurerm_public_ip.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) | resource |
-| [azurerm_network_interface.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) | resource |
+| [azurerm_network_interface.first](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) | resource |
+| [azurerm_network_interface.second](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) | resource |
| [azurerm_linux_virtual_machine.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) | resource |
@@ -98,6 +102,7 @@ No modules.
| [id](#output\_id) | The ID of the Linux Virtual Machine |
| [identity](#output\_identity) | linux virtual machine identity |
| [public\_ip](#output\_public\_ip) | Linux Virtual Machine public IP address |
+| [private\_ip\_second\_nic](#output\_private\_ip\_second\_nic) | Linux Virtual Machine second nic private IP address |
## License
diff --git a/main.tf b/main.tf
index ca7cf24..e68aed7 100644
--- a/main.tf
+++ b/main.tf
@@ -1,8 +1,9 @@
locals {
- suffix = length(var.suffix) == 0 ? "" : "-${var.suffix}"
- virtual_machine_name = var.custom_virtual_machine_name == null ? "vm-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_virtual_machine_name}${local.suffix}"
- network_interface_name = var.custom_network_interface_name == null ? "nic-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_network_interface_name}${local.suffix}"
- public_ip = var.custom_public_ip_name == null ? "ip-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_public_ip_name}${local.suffix}"
+ suffix = length(var.suffix) == 0 ? "" : "-${var.suffix}"
+ virtual_machine_name = var.custom_virtual_machine_name == null ? "vm-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_virtual_machine_name}${local.suffix}"
+ network_interface_first_name = var.custom_network_interface_first_name == null ? "nic-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_network_interface_first_name}${local.suffix}"
+ network_interface_name_second = var.custom_network_interface_second_name == null ? "nic-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_network_interface_second_name}${local.suffix}"
+ public_ip = var.custom_public_ip_name == null ? "ip-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_public_ip_name}${local.suffix}"
}
resource "azurerm_public_ip" "this" {
@@ -14,20 +15,37 @@ resource "azurerm_public_ip" "this" {
allocation_method = var.public_ip_allocation_method
}
-resource "azurerm_network_interface" "this" {
- name = local.network_interface_name
- location = var.location
- resource_group_name = var.resource_group
- tags = var.tags
+resource "azurerm_network_interface" "first" {
+ name = local.network_interface_first_name
+ location = var.location
+ resource_group_name = var.resource_group
+ tags = var.tags
+ enable_ip_forwarding = true
ip_configuration {
- name = "ip-config-${var.project}-${var.env}-${var.location}"
+ name = "ip-config-first-${var.project}-${var.env}-${var.location}"
subnet_id = var.subnet_id
private_ip_address_allocation = var.network_interface_private_ip_address_allocation
public_ip_address_id = try(azurerm_public_ip.this[0].id, null)
}
}
+resource "azurerm_network_interface" "second" {
+ count = length(var.subnet_id_second_nic) != null ? 1 : 0
+
+ name = local.network_interface_name_second
+ location = var.location
+ resource_group_name = var.resource_group
+ tags = var.tags
+ enable_ip_forwarding = true
+
+ ip_configuration {
+ name = "ip-config-second-${var.project}-${var.env}-${var.location}"
+ subnet_id = var.subnet_id_second_nic
+ private_ip_address_allocation = var.network_interface_private_ip_address_allocation_nic_second
+ }
+}
+
resource "azurerm_linux_virtual_machine" "this" {
name = local.virtual_machine_name
resource_group_name = var.resource_group
@@ -35,7 +53,7 @@ resource "azurerm_linux_virtual_machine" "this" {
size = var.vm_size
admin_username = var.vm_admin_username
tags = var.tags
- network_interface_ids = [azurerm_network_interface.this.id]
+ network_interface_ids = [azurerm_network_interface.first.id, try(azurerm_network_interface.second[0].id, "")]
admin_password = var.vm_admin_password
disable_password_authentication = var.password_access_enabled ? false : true
diff --git a/outputs.tf b/outputs.tf
index 50d4fea..db4941c 100644
--- a/outputs.tf
+++ b/outputs.tf
@@ -17,3 +17,8 @@ output "private_ip" {
value = try(azurerm_linux_virtual_machine.this.private_ip_address, null)
description = "Linux Virtual Machine private IP address"
}
+
+output "private_ip_second_nic" {
+ value = try(azurerm_network_interface.second[0].private_ip_address, null)
+ description = "Linux Virtual Machine second nic private IP address"
+}
diff --git a/variables.tf b/variables.tf
index ccb2a2f..cb66323 100644
--- a/variables.tf
+++ b/variables.tf
@@ -30,9 +30,15 @@ variable "custom_virtual_machine_name" {
default = null
}
-variable "custom_network_interface_name" {
+variable "custom_network_interface_first_name" {
type = string
- description = "Specifies the name of the virtual machine interface name resource"
+ description = "Specifies the name of the virtual machine first interface name resource"
+ default = null
+}
+
+variable "custom_network_interface_second_name" {
+ type = string
+ description = "Specifies the name of the virtual machine second interface name resource"
default = null
}
@@ -50,7 +56,13 @@ variable "tags" {
variable "subnet_id" {
type = string
- description = "The ID of the Subnet where this Network Interface should be located in."
+ description = "The ID of the Subnet where this Network first Interface should be located in."
+}
+
+variable "subnet_id_second_nic" {
+ type = string
+ description = "The ID of the Subnet where this Network second Interface should be located in."
+ default = ""
}
variable "public_ip_enabled" {
@@ -71,6 +83,12 @@ variable "network_interface_private_ip_address_allocation" {
default = "Dynamic"
}
+variable "network_interface_private_ip_address_allocation_nic_second" {
+ type = string
+ description = "The allocation method used for second nic the Private IP Address."
+ default = "Static"
+}
+
variable "vm_size" {
type = string
description = "The SKU which should be used for this Virtual Machine."