@@ -21,13 +21,8 @@ run "should_use_subnet_id" {
2121 }
2222
2323 assert {
24- condition = length (azurerm_network_security_group. this ) == 1
25- error_message = " Expected the module to create a default network security group when no network_security_group_id is provided."
26- }
27-
28- assert {
29- condition = length (azurerm_network_interface_security_group_association. this ) == 1
30- error_message = " Expected the created network interface to have a network security group association."
24+ condition = length (azurerm_network_interface_security_group_association. this ) == 0
25+ error_message = " Expected no network security group association when network_security_group_id is not provided."
3126 }
3227}
3328
@@ -71,13 +66,35 @@ run "should_use_existing_network_security_group_for_created_network_interface" {
7166 }
7267
7368 assert {
74- condition = length (azurerm_network_security_group. this ) == 0
75- error_message = " Expected no network security group to be created when network_security_group_id is provided."
69+ condition = length (azurerm_network_interface_security_group_association. this ) == 1
70+ error_message = " Expected the created network interface to have a network security group association when network_security_group_id is provided."
71+ }
72+ }
73+
74+ run "should_not_associate_network_security_group_when_not_provided" {
75+ command = plan
76+
77+ variables {
78+ subnet_id = " /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.Network/virtualNetworks/vnet/subnets/snet"
79+ }
80+
81+ assert {
82+ condition = length (azurerm_network_interface_security_group_association. this ) == 0
83+ error_message = " Expected no network security group association when no network_security_group_id is provided."
84+ }
85+ }
86+
87+ run "should_associate_existing_network_security_group_when_provided" {
88+ command = plan
89+
90+ variables {
91+ network_security_group_id = " /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.Network/networkSecurityGroups/nsg-existing"
92+ subnet_id = " /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.Network/virtualNetworks/vnet/subnets/snet"
7693 }
7794
7895 assert {
7996 condition = length (azurerm_network_interface_security_group_association. this ) == 1
80- error_message = " Expected the created network interface to have a network security group association when network_security_group_id is provided ."
97+ error_message = " Expected the provided network_security_group_id to be associated with the created network interface ."
8198 }
8299}
83100
0 commit comments