provider/azurerm: Support Import of `azurerm_network_security_group`

```
% make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMNetworkSecurityGroup_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
TF_ACC=1 go test ./builtin/providers/azurerm -v
-run=TestAccAzureRMNetworkSecurityGroup_ -timeout 120m
=== RUN   TestAccAzureRMNetworkSecurityGroup_importBasic
--- PASS: TestAccAzureRMNetworkSecurityGroup_importBasic (148.03s)
=== RUN   TestAccAzureRMNetworkSecurityGroup_basic
--- PASS: TestAccAzureRMNetworkSecurityGroup_basic (143.72s)
=== RUN   TestAccAzureRMNetworkSecurityGroup_withTags
--- PASS: TestAccAzureRMNetworkSecurityGroup_withTags (180.05s)
=== RUN   TestAccAzureRMNetworkSecurityGroup_addingExtraRules
--- PASS: TestAccAzureRMNetworkSecurityGroup_addingExtraRules (236.28s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/azurerm
708.099s
```
This commit is contained in:
stack72 2016-07-13 13:42:50 +01:00
parent 9018e073fb
commit c0f14840f3
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package azurerm
import (
"testing"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAzureRMNetworkSecurityGroup_importBasic(t *testing.T) {
resourceName := "azurerm_network_security_group.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAzureRMNetworkSecurityGroup_basic,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"resource_group_name"},
},
},
})
}

View File

@ -19,6 +19,9 @@ func resourceArmNetworkSecurityGroup() *schema.Resource {
Read: resourceArmNetworkSecurityGroupRead, Read: resourceArmNetworkSecurityGroupRead,
Update: resourceArmNetworkSecurityGroupCreate, Update: resourceArmNetworkSecurityGroupCreate,
Delete: resourceArmNetworkSecurityGroupDelete, Delete: resourceArmNetworkSecurityGroupDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": { "name": {
@ -200,6 +203,8 @@ func resourceArmNetworkSecurityGroupRead(d *schema.ResourceData, meta interface{
d.Set("security_rule", flattenNetworkSecurityRules(resp.Properties.SecurityRules)) d.Set("security_rule", flattenNetworkSecurityRules(resp.Properties.SecurityRules))
} }
d.Set("name", resp.Name)
d.Set("location", resp.Location)
flattenAndSetTags(d, resp.Tags) flattenAndSetTags(d, resp.Tags)
return nil return nil