Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring Network Security Groups / Rules #405

Merged
merged 2 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions azurerm/import_arm_network_security_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,45 @@ func TestAccAzureRMNetworkSecurityGroup_importBasic(t *testing.T) {
},
})
}

func TestAccAzureRMNetworkSecurityGroup_importSingleRule(t *testing.T) {
resourceName := "azurerm_network_security_group.test"
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkSecurityGroup_singleRule(rInt, testLocation()),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMNetworkSecurityGroup_importMultipleRules(t *testing.T) {
resourceName := "azurerm_network_security_group.test"
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkSecurityGroup_anotherRule(rInt, testLocation()),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
26 changes: 0 additions & 26 deletions azurerm/network_security_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,3 @@ func validateNetworkSecurityRuleProtocol(v interface{}, k string) (ws []string,
}
return
}

func validateNetworkSecurityRuleAccess(v interface{}, k string) (ws []string, errors []error) {
value := strings.ToLower(v.(string))
accessTypes := map[string]bool{
"allow": true,
"deny": true,
}

if !accessTypes[value] {
errors = append(errors, fmt.Errorf("Network Security Rule Access can only be Allow or Deny"))
}
return
}

func validateNetworkSecurityRuleDirection(v interface{}, k string) (ws []string, errors []error) {
value := strings.ToLower(v.(string))
directions := map[string]bool{
"inbound": true,
"outbound": true,
}

if !directions[value] {
errors = append(errors, fmt.Errorf("Network Security Rule Directions can only be Inbound or Outbound"))
}
return
}
72 changes: 0 additions & 72 deletions azurerm/network_security_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,75 +41,3 @@ func TestResourceAzureRMNetworkSecurityRuleProtocol_validation(t *testing.T) {
}
}
}

func TestResourceAzureRMNetworkSecurityRuleAccess_validation(t *testing.T) {
cases := []struct {
Value string
ErrCount int
}{
{
Value: "Random",
ErrCount: 1,
},
{
Value: "Allow",
ErrCount: 0,
},
{
Value: "Deny",
ErrCount: 0,
},
{
Value: "ALLOW",
ErrCount: 0,
},
{
Value: "deny",
ErrCount: 0,
},
}

for _, tc := range cases {
_, errors := validateNetworkSecurityRuleAccess(tc.Value, "azurerm_network_security_rule")

if len(errors) != tc.ErrCount {
t.Fatalf("Expected the Azure RM Network Security Rule access to trigger a validation error")
}
}
}

func TestResourceAzureRMNetworkSecurityRuleDirection_validation(t *testing.T) {
cases := []struct {
Value string
ErrCount int
}{
{
Value: "Random",
ErrCount: 1,
},
{
Value: "Inbound",
ErrCount: 0,
},
{
Value: "Outbound",
ErrCount: 0,
},
{
Value: "INBOUND",
ErrCount: 0,
},
{
Value: "Inbound",
ErrCount: 0,
},
}

for _, tc := range cases {
_, errors := validateNetworkSecurityRuleDirection(tc.Value, "azurerm_network_security_rule")

if len(errors) != tc.ErrCount {
t.Fatalf("Expected the Azure RM Network Security Rule direction to trigger a validation error")
}
}
}
Loading