VM Not Attached To Network
VMs without NSGs are exposed without traffic control or inspection.
Impact
Recommended Actions
Follow the appropriate remediation steps below to resolve the issue.
Associate an NSG to the VM’s NIC or subnet to control traffic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
resource "azurerm_network_security_group" "example" {
name = "vm-nsg"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_network_interface" "good_example" {
name = "vm-nic"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
network_security_group_id = azurerm_network_security_group.example.id
ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.example.id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_linux_virtual_machine" "good_example" {
name = "good-vm"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
size = "Standard_F2"
admin_username = "adminuser"
network_interface_ids = [
azurerm_network_interface.good_example.id,
]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
resource "azurerm_network_security_group" "example" {
name = "vm-nsg"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_network_interface" "good_example" {
name = "vm-nic"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
network_security_group_id = azurerm_network_security_group.example.id
ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.example.id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_windows_virtual_machine" "good_example" {
name = "good-vm"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
size = "Standard_F2"
admin_username = "adminuser"
admin_password = "P@$$w0rd1234!"
network_interface_ids = [
azurerm_network_interface.good_example.id,
]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
}
|
Links