Rename the AzureRM Security Group to AzureRM Network Security Group

This commit is contained in:
stack72 2016-01-07 22:32:49 +00:00
parent b96122f24e
commit f79d951524
5 changed files with 67 additions and 67 deletions

View File

@ -39,11 +39,11 @@ func Provider() terraform.ResourceProvider {
}, },
ResourcesMap: map[string]*schema.Resource{ ResourcesMap: map[string]*schema.Resource{
"azurerm_resource_group": resourceArmResourceGroup(), "azurerm_resource_group": resourceArmResourceGroup(),
"azurerm_virtual_network": resourceArmVirtualNetwork(), "azurerm_virtual_network": resourceArmVirtualNetwork(),
"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
"azurerm_availability_set": resourceArmAvailabilitySet(), "azurerm_availability_set": resourceArmAvailabilitySet(),
"azurerm_security_group": resourceArmSecurityGroup(), "azurerm_network_security_group": resourceArmNetworkSecurityGroup(),
}, },
ConfigureFunc: providerConfigure, ConfigureFunc: providerConfigure,

View File

@ -15,12 +15,12 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
func resourceArmSecurityGroup() *schema.Resource { func resourceArmNetworkSecurityGroup() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
Create: resourceArmSecurityGroupCreate, Create: resourceArmNetworkSecurityGroupCreate,
Read: resourceArmSecurityGroupRead, Read: resourceArmNetworkSecurityGroupRead,
Update: resourceArmSecurityGroupCreate, Update: resourceArmNetworkSecurityGroupCreate,
Delete: resourceArmSecurityGroupDelete, Delete: resourceArmNetworkSecurityGroupDelete,
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": &schema.Schema{ "name": &schema.Schema{
@ -60,7 +60,7 @@ func resourceArmSecurityGroup() *schema.Resource {
value := v.(string) value := v.(string)
if len(value) > 140 { if len(value) > 140 {
errors = append(errors, fmt.Errorf( 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 return
}, },
@ -69,7 +69,7 @@ func resourceArmSecurityGroup() *schema.Resource {
"protocol": &schema.Schema{ "protocol": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ValidateFunc: validateSecurityRuleProtocol, ValidateFunc: validateNetworkSecurityRuleProtocol,
}, },
"source_port_range": &schema.Schema{ "source_port_range": &schema.Schema{
@ -95,7 +95,7 @@ func resourceArmSecurityGroup() *schema.Resource {
"access": &schema.Schema{ "access": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ValidateFunc: validateSecurityRuleAccess, ValidateFunc: validateNetworkSecurityRuleAccess,
}, },
"priority": &schema.Schema{ "priority": &schema.Schema{
@ -114,17 +114,17 @@ func resourceArmSecurityGroup() *schema.Resource {
"direction": &schema.Schema{ "direction": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Required: true, 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) client := meta.(*ArmClient)
secClient := client.secGroupClient secClient := client.secGroupClient
@ -134,7 +134,7 @@ func resourceArmSecurityGroupCreate(d *schema.ResourceData, meta interface{}) er
sgRules, sgErr := expandAzureRmSecurityGroupRules(d) sgRules, sgErr := expandAzureRmSecurityGroupRules(d)
if sgErr != nil { 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{ sg := network.SecurityGroup{
@ -152,7 +152,7 @@ func resourceArmSecurityGroupCreate(d *schema.ResourceData, meta interface{}) er
d.SetId(*resp.ID) 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{ stateConf := &resource.StateChangeConf{
Pending: []string{"Accepted", "Updating"}, Pending: []string{"Accepted", "Updating"},
Target: "Succeeded", Target: "Succeeded",
@ -160,13 +160,13 @@ func resourceArmSecurityGroupCreate(d *schema.ResourceData, meta interface{}) er
Timeout: 10 * time.Minute, Timeout: 10 * time.Minute,
} }
if _, err := stateConf.WaitForState(); err != nil { 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 secGroupClient := meta.(*ArmClient).secGroupClient
id, err := parseAzureResourceID(d.Id()) id, err := parseAzureResourceID(d.Id())
@ -182,13 +182,13 @@ func resourceArmSecurityGroupRead(d *schema.ResourceData, meta interface{}) erro
return nil return nil
} }
if err != 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 return nil
} }
func resourceArmSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error { func resourceArmNetworkSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error {
secGroupClient := meta.(*ArmClient).secGroupClient secGroupClient := meta.(*ArmClient).secGroupClient
id, err := parseAzureResourceID(d.Id()) id, err := parseAzureResourceID(d.Id())
@ -203,7 +203,7 @@ func resourceArmSecurityGroupDelete(d *schema.ResourceData, meta interface{}) er
return err return err
} }
func resourceArmSecurityGroupRuleHash(v interface{}) int { func resourceArmNetworkSecurityGroupRuleHash(v interface{}) int {
var buf bytes.Buffer var buf bytes.Buffer
m := v.(map[string]interface{}) m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["protocol"].(string))) buf.WriteString(fmt.Sprintf("%s-", m["protocol"].(string)))
@ -222,7 +222,7 @@ func securityGroupStateRefreshFunc(client *ArmClient, resourceGroupName string,
return func() (interface{}, string, error) { return func() (interface{}, string, error) {
res, err := client.secGroupClient.Get(resourceGroupName, securityGroupName) res, err := client.secGroupClient.Get(resourceGroupName, securityGroupName)
if err != nil { 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 return res, *res.Properties.ProvisioningState, nil
@ -269,7 +269,7 @@ func expandAzureRmSecurityGroupRules(d *schema.ResourceData) ([]network.Security
return rules, nil 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)) value := strings.ToLower(v.(string))
viewTypes := map[string]bool{ viewTypes := map[string]bool{
"tcp": true, "tcp": true,
@ -278,12 +278,12 @@ func validateSecurityRuleProtocol(v interface{}, k string) (ws []string, errors
} }
if !viewTypes[value] { 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 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)) value := strings.ToLower(v.(string))
viewTypes := map[string]bool{ viewTypes := map[string]bool{
"allow": true, "allow": true,
@ -291,12 +291,12 @@ func validateSecurityRuleAccess(v interface{}, k string) (ws []string, errors []
} }
if !viewTypes[value] { 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 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)) value := strings.ToLower(v.(string))
viewTypes := map[string]bool{ viewTypes := map[string]bool{
"inbound": true, "inbound": true,
@ -304,7 +304,7 @@ func validateSecurityRuleDirection(v interface{}, k string) (ws []string, errors
} }
if !viewTypes[value] { 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 return
} }

View File

@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestResourceAzureRMSecurityGroupProtocol_validation(t *testing.T) { func TestResourceAzureRMNetworkSecurityGroupProtocol_validation(t *testing.T) {
cases := []struct { cases := []struct {
Value string Value string
ErrCount int ErrCount int
@ -41,15 +41,15 @@ func TestResourceAzureRMSecurityGroupProtocol_validation(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
_, errors := validateSecurityRuleProtocol(tc.Value, "azurerm_security_group") _, errors := validateNetworkSecurityRuleProtocol(tc.Value, "azurerm_network_security_group")
if len(errors) != tc.ErrCount { 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 { cases := []struct {
Value string Value string
ErrCount int ErrCount int
@ -77,15 +77,15 @@ func TestResourceAzureRMSecurityGroupAccess_validation(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
_, errors := validateSecurityRuleAccess(tc.Value, "azurerm_security_group") _, errors := validateNetworkSecurityRuleAccess(tc.Value, "azurerm_network_security_group")
if len(errors) != tc.ErrCount { 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 { cases := []struct {
Value string Value string
ErrCount int ErrCount int
@ -113,60 +113,60 @@ func TestResourceAzureRMSecurityGroupDirection_validation(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
_, errors := validateSecurityRuleDirection(tc.Value, "azurerm_security_group") _, errors := validateNetworkSecurityRuleDirection(tc.Value, "azurerm_network_security_group")
if len(errors) != tc.ErrCount { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSecurityGroupDestroy, CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccAzureRMSecurityGroup_basic, Config: testAccAzureRMNetworkSecurityGroup_basic,
Check: resource.ComposeTestCheckFunc( 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSecurityGroupDestroy, CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccAzureRMSecurityGroup_basic, Config: testAccAzureRMNetworkSecurityGroup_basic,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSecurityGroupExists("azurerm_security_group.test"), testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"azurerm_security_group.test", "security_rule.#", "1"), "azurerm_network_security_group.test", "security_rule.#", "1"),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccAzureRMSecurityGroup_anotherRule, Config: testAccAzureRMNetworkSecurityGroup_anotherRule,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSecurityGroupExists("azurerm_security_group.test"), testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
resource.TestCheckResourceAttr( 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 { return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name] rs, ok := s.RootModule().Resources[name]
@ -177,7 +177,7 @@ func testCheckAzureRMSecurityGroupExists(name string) resource.TestCheckFunc {
sgName := rs.Primary.Attributes["name"] sgName := rs.Primary.Attributes["name"]
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
if !hasResourceGroup { 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 conn := testAccProvider.Meta().(*ArmClient).secGroupClient
@ -188,18 +188,18 @@ func testCheckAzureRMSecurityGroupExists(name string) resource.TestCheckFunc {
} }
if resp.StatusCode == http.StatusNotFound { 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 return nil
} }
} }
func testCheckAzureRMSecurityGroupDestroy(s *terraform.State) error { func testCheckAzureRMNetworkSecurityGroupDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).secGroupClient conn := testAccProvider.Meta().(*ArmClient).secGroupClient
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_security_group" { if rs.Type != "azurerm_network_security_group" {
continue continue
} }
@ -213,20 +213,20 @@ func testCheckAzureRMSecurityGroupDestroy(s *terraform.State) error {
} }
if resp.StatusCode != http.StatusNotFound { 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 return nil
} }
var testAccAzureRMSecurityGroup_basic = ` var testAccAzureRMNetworkSecurityGroup_basic = `
resource "azurerm_resource_group" "test" { resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1" name = "acceptanceTestResourceGroup1"
location = "West US" location = "West US"
} }
resource "azurerm_security_group" "test" { resource "azurerm_network_security_group" "test" {
name = "acceptanceTestSecurityGroup1" name = "acceptanceTestSecurityGroup1"
location = "West US" location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
@ -245,13 +245,13 @@ resource "azurerm_security_group" "test" {
} }
` `
var testAccAzureRMSecurityGroup_anotherRule = ` var testAccAzureRMNetworkSecurityGroup_anotherRule = `
resource "azurerm_resource_group" "test" { resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1" name = "acceptanceTestResourceGroup1"
location = "West US" location = "West US"
} }
resource "azurerm_security_group" "test" { resource "azurerm_network_security_group" "test" {
name = "acceptanceTestSecurityGroup1" name = "acceptanceTestSecurityGroup1"
location = "West US" location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"

View File

@ -1,7 +1,7 @@
--- ---
layout: "azurerm" layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_security_group" page_title: "Azure Resource Manager: azurerm_network_security_group"
sidebar_current: "docs-azurerm-resource-security-group" sidebar_current: "docs-azurerm-resource-network-security-group"
description: |- description: |-
Create a network security group that contains a list of network security rules. Network security groups enable inbound or outbound traffic to be enabled or denied. Create a network security group that contains a list of network security rules. Network security groups enable inbound or outbound traffic to be enabled or denied.
--- ---
@ -18,7 +18,7 @@ resource "azurerm_resource_group" "test" {
location = "West US" location = "West US"
} }
resource "azurerm_security_group" "test" { resource "azurerm_network_security_group" "test" {
name = "acceptanceTestSecurityGroup1" name = "acceptanceTestSecurityGroup1"
location = "West US" location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"

View File

@ -29,8 +29,8 @@
<a href="/docs/providers/azurerm/r/availability_set.html">azurerm_availability_set</a> <a href="/docs/providers/azurerm/r/availability_set.html">azurerm_availability_set</a>
</li> </li>
<li<%= sidebar_current("docs-azurerm-resource-security-group") %>> <li<%= sidebar_current("docs-azurerm-resource-network-security-group") %>>
<a href="/docs/providers/azurerm/r/security_group.html">azurerm_security_group</a> <a href="/docs/providers/azurerm/r/network_security_group.html">azurerm_network_security_group</a>
</li> </li>
</ul> </ul>