Skip to content

Commit

Permalink
Merge pull request #4562 from stack72/f-azurerm-network-security-group
Browse files Browse the repository at this point in the history
provider/azurerm: rename security group to be network security group
  • Loading branch information
jen20 committed Jan 7, 2016
2 parents 98baf47 + f79d951 commit d87f0ca
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 67 deletions.
10 changes: 5 additions & 5 deletions builtin/providers/azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func Provider() terraform.ResourceProvider {
},

ResourcesMap: map[string]*schema.Resource{
"azurerm_resource_group": resourceArmResourceGroup(),
"azurerm_virtual_network": resourceArmVirtualNetwork(),
"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
"azurerm_availability_set": resourceArmAvailabilitySet(),
"azurerm_security_group": resourceArmSecurityGroup(),
"azurerm_resource_group": resourceArmResourceGroup(),
"azurerm_virtual_network": resourceArmVirtualNetwork(),
"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
"azurerm_availability_set": resourceArmAvailabilitySet(),
"azurerm_network_security_group": resourceArmNetworkSecurityGroup(),
},

ConfigureFunc: providerConfigure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
"github.com/hashicorp/terraform/helper/schema"
)

func resourceArmSecurityGroup() *schema.Resource {
func resourceArmNetworkSecurityGroup() *schema.Resource {
return &schema.Resource{
Create: resourceArmSecurityGroupCreate,
Read: resourceArmSecurityGroupRead,
Update: resourceArmSecurityGroupCreate,
Delete: resourceArmSecurityGroupDelete,
Create: resourceArmNetworkSecurityGroupCreate,
Read: resourceArmNetworkSecurityGroupRead,
Update: resourceArmNetworkSecurityGroupCreate,
Delete: resourceArmNetworkSecurityGroupDelete,

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -60,7 +60,7 @@ func resourceArmSecurityGroup() *schema.Resource {
value := v.(string)
if len(value) > 140 {
errors = append(errors, fmt.Errorf(
"The security rule description can be no longer than 140 chars"))
"The network security rule description can be no longer than 140 chars"))
}
return
},
Expand All @@ -69,7 +69,7 @@ func resourceArmSecurityGroup() *schema.Resource {
"protocol": &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validateSecurityRuleProtocol,
ValidateFunc: validateNetworkSecurityRuleProtocol,
},

"source_port_range": &schema.Schema{
Expand All @@ -95,7 +95,7 @@ func resourceArmSecurityGroup() *schema.Resource {
"access": &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validateSecurityRuleAccess,
ValidateFunc: validateNetworkSecurityRuleAccess,
},

"priority": &schema.Schema{
Expand All @@ -114,17 +114,17 @@ func resourceArmSecurityGroup() *schema.Resource {
"direction": &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validateSecurityRuleDirection,
ValidateFunc: validateNetworkSecurityRuleDirection,
},
},
},
Set: resourceArmSecurityGroupRuleHash,
Set: resourceArmNetworkSecurityGroupRuleHash,
},
},
}
}

func resourceArmSecurityGroupCreate(d *schema.ResourceData, meta interface{}) error {
func resourceArmNetworkSecurityGroupCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient)
secClient := client.secGroupClient

Expand All @@ -134,7 +134,7 @@ func resourceArmSecurityGroupCreate(d *schema.ResourceData, meta interface{}) er

sgRules, sgErr := expandAzureRmSecurityGroupRules(d)
if sgErr != nil {
return fmt.Errorf("Error Building list of Security Group Rules: %s", sgErr)
return fmt.Errorf("Error Building list of Network Security Group Rules: %s", sgErr)
}

sg := network.SecurityGroup{
Expand All @@ -152,21 +152,21 @@ func resourceArmSecurityGroupCreate(d *schema.ResourceData, meta interface{}) er

d.SetId(*resp.ID)

log.Printf("[DEBUG] Waiting for Security Group (%s) to become available", name)
log.Printf("[DEBUG] Waiting for Network Security Group (%s) to become available", name)
stateConf := &resource.StateChangeConf{
Pending: []string{"Accepted", "Updating"},
Target: "Succeeded",
Refresh: securityGroupStateRefreshFunc(client, resGroup, name),
Timeout: 10 * time.Minute,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Securty Group (%s) to become available: %s", name, err)
return fmt.Errorf("Error waiting for Network Securty Group (%s) to become available: %s", name, err)
}

return resourceArmSecurityGroupRead(d, meta)
return resourceArmNetworkSecurityGroupRead(d, meta)
}

func resourceArmSecurityGroupRead(d *schema.ResourceData, meta interface{}) error {
func resourceArmNetworkSecurityGroupRead(d *schema.ResourceData, meta interface{}) error {
secGroupClient := meta.(*ArmClient).secGroupClient

id, err := parseAzureResourceID(d.Id())
Expand All @@ -182,13 +182,13 @@ func resourceArmSecurityGroupRead(d *schema.ResourceData, meta interface{}) erro
return nil
}
if err != nil {
return fmt.Errorf("Error making Read request on Azure Security Group %s: %s", name, err)
return fmt.Errorf("Error making Read request on Azure Network Security Group %s: %s", name, err)
}

return nil
}

func resourceArmSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error {
func resourceArmNetworkSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error {
secGroupClient := meta.(*ArmClient).secGroupClient

id, err := parseAzureResourceID(d.Id())
Expand All @@ -203,7 +203,7 @@ func resourceArmSecurityGroupDelete(d *schema.ResourceData, meta interface{}) er
return err
}

func resourceArmSecurityGroupRuleHash(v interface{}) int {
func resourceArmNetworkSecurityGroupRuleHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["protocol"].(string)))
Expand All @@ -222,7 +222,7 @@ func securityGroupStateRefreshFunc(client *ArmClient, resourceGroupName string,
return func() (interface{}, string, error) {
res, err := client.secGroupClient.Get(resourceGroupName, securityGroupName)
if err != nil {
return nil, "", fmt.Errorf("Error issuing read request in securityGroupStateRefreshFunc to Azure ARM for security group '%s' (RG: '%s'): %s", securityGroupName, resourceGroupName, err)
return nil, "", fmt.Errorf("Error issuing read request in securityGroupStateRefreshFunc to Azure ARM for network security group '%s' (RG: '%s'): %s", securityGroupName, resourceGroupName, err)
}

return res, *res.Properties.ProvisioningState, nil
Expand Down Expand Up @@ -269,7 +269,7 @@ func expandAzureRmSecurityGroupRules(d *schema.ResourceData) ([]network.Security
return rules, nil
}

func validateSecurityRuleProtocol(v interface{}, k string) (ws []string, errors []error) {
func validateNetworkSecurityRuleProtocol(v interface{}, k string) (ws []string, errors []error) {
value := strings.ToLower(v.(string))
viewTypes := map[string]bool{
"tcp": true,
Expand All @@ -278,33 +278,33 @@ func validateSecurityRuleProtocol(v interface{}, k string) (ws []string, errors
}

if !viewTypes[value] {
errors = append(errors, fmt.Errorf("Security Rule Protocol can only be Tcp, Udp or *"))
errors = append(errors, fmt.Errorf("Network Security Rule Protocol can only be Tcp, Udp or *"))
}
return
}

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

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

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

if !viewTypes[value] {
errors = append(errors, fmt.Errorf("Security Rule Directions can only be Inbound or Outbound"))
errors = append(errors, fmt.Errorf("Network Security Rule Directions can only be Inbound or Outbound"))
}
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func TestResourceAzureRMSecurityGroupProtocol_validation(t *testing.T) {
func TestResourceAzureRMNetworkSecurityGroupProtocol_validation(t *testing.T) {
cases := []struct {
Value string
ErrCount int
Expand Down Expand Up @@ -41,15 +41,15 @@ func TestResourceAzureRMSecurityGroupProtocol_validation(t *testing.T) {
}

for _, tc := range cases {
_, errors := validateSecurityRuleProtocol(tc.Value, "azurerm_security_group")
_, errors := validateNetworkSecurityRuleProtocol(tc.Value, "azurerm_network_security_group")

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

func TestResourceAzureRMSecurityGroupAccess_validation(t *testing.T) {
func TestResourceAzureRMNetworkSecurityGroupAccess_validation(t *testing.T) {
cases := []struct {
Value string
ErrCount int
Expand Down Expand Up @@ -77,15 +77,15 @@ func TestResourceAzureRMSecurityGroupAccess_validation(t *testing.T) {
}

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

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

func TestResourceAzureRMSecurityGroupDirection_validation(t *testing.T) {
func TestResourceAzureRMNetworkSecurityGroupDirection_validation(t *testing.T) {
cases := []struct {
Value string
ErrCount int
Expand Down Expand Up @@ -113,60 +113,60 @@ func TestResourceAzureRMSecurityGroupDirection_validation(t *testing.T) {
}

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

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

func TestAccAzureRMSecurityGroup_basic(t *testing.T) {
func TestAccAzureRMNetworkSecurityGroup_basic(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSecurityGroupDestroy,
CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAzureRMSecurityGroup_basic,
Config: testAccAzureRMNetworkSecurityGroup_basic,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSecurityGroupExists("azurerm_security_group.test"),
testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
),
},
},
})
}

func TestAccAzureRMSecurityGroup_addingExtraRules(t *testing.T) {
func TestAccAzureRMNetworkSecurityGroup_addingExtraRules(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSecurityGroupDestroy,
CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAzureRMSecurityGroup_basic,
Config: testAccAzureRMNetworkSecurityGroup_basic,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSecurityGroupExists("azurerm_security_group.test"),
testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
resource.TestCheckResourceAttr(
"azurerm_security_group.test", "security_rule.#", "1"),
"azurerm_network_security_group.test", "security_rule.#", "1"),
),
},

resource.TestStep{
Config: testAccAzureRMSecurityGroup_anotherRule,
Config: testAccAzureRMNetworkSecurityGroup_anotherRule,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSecurityGroupExists("azurerm_security_group.test"),
testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
resource.TestCheckResourceAttr(
"azurerm_security_group.test", "security_rule.#", "2"),
"azurerm_network_security_group.test", "security_rule.#", "2"),
),
},
},
})
}

func testCheckAzureRMSecurityGroupExists(name string) resource.TestCheckFunc {
func testCheckAzureRMNetworkSecurityGroupExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {

rs, ok := s.RootModule().Resources[name]
Expand All @@ -177,7 +177,7 @@ func testCheckAzureRMSecurityGroupExists(name string) resource.TestCheckFunc {
sgName := rs.Primary.Attributes["name"]
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
if !hasResourceGroup {
return fmt.Errorf("Bad: no resource group found in state for security group: %s", sgName)
return fmt.Errorf("Bad: no resource group found in state for network security group: %s", sgName)
}

conn := testAccProvider.Meta().(*ArmClient).secGroupClient
Expand All @@ -188,18 +188,18 @@ func testCheckAzureRMSecurityGroupExists(name string) resource.TestCheckFunc {
}

if resp.StatusCode == http.StatusNotFound {
return fmt.Errorf("Bad: Security Group %q (resource group: %q) does not exist", name, resourceGroup)
return fmt.Errorf("Bad: Network Security Group %q (resource group: %q) does not exist", name, resourceGroup)
}

return nil
}
}

func testCheckAzureRMSecurityGroupDestroy(s *terraform.State) error {
func testCheckAzureRMNetworkSecurityGroupDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).secGroupClient

for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_security_group" {
if rs.Type != "azurerm_network_security_group" {
continue
}

Expand All @@ -213,20 +213,20 @@ func testCheckAzureRMSecurityGroupDestroy(s *terraform.State) error {
}

if resp.StatusCode != http.StatusNotFound {
return fmt.Errorf("Security Group still exists:\n%#v", resp.Properties)
return fmt.Errorf("Network Security Group still exists:\n%#v", resp.Properties)
}
}

return nil
}

var testAccAzureRMSecurityGroup_basic = `
var testAccAzureRMNetworkSecurityGroup_basic = `
resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1"
location = "West US"
}
resource "azurerm_security_group" "test" {
resource "azurerm_network_security_group" "test" {
name = "acceptanceTestSecurityGroup1"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
Expand All @@ -245,13 +245,13 @@ resource "azurerm_security_group" "test" {
}
`

var testAccAzureRMSecurityGroup_anotherRule = `
var testAccAzureRMNetworkSecurityGroup_anotherRule = `
resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1"
location = "West US"
}
resource "azurerm_security_group" "test" {
resource "azurerm_network_security_group" "test" {
name = "acceptanceTestSecurityGroup1"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
Expand Down
Loading

0 comments on commit d87f0ca

Please sign in to comment.