provider/azurerm: Support Import of `azurerm_virtual_network`

```
% make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMVirtualNetwork_'
==> 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=TestAccAzureRMVirtualNetwork_ -timeout 120m
=== RUN   TestAccAzureRMVirtualNetwork_importBasic
--- PASS: TestAccAzureRMVirtualNetwork_importBasic (129.61s)
=== RUN   TestAccAzureRMVirtualNetwork_basic
--- PASS: TestAccAzureRMVirtualNetwork_basic (128.37s)
=== RUN   TestAccAzureRMVirtualNetwork_withTags
--- PASS: TestAccAzureRMVirtualNetwork_withTags (151.55s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/azurerm
409.541s
```
This commit is contained in:
stack72 2016-07-13 12:32:34 +01:00
parent 9018e073fb
commit dc9dc74026
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,34 @@
package azurerm
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAzureRMVirtualNetwork_importBasic(t *testing.T) {
resourceName := "azurerm_virtual_network.test"
ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMVirtualNetwork_basic, ri, ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualNetworkDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: config,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"resource_group_name"},
},
},
})
}

View File

@ -17,6 +17,9 @@ func resourceArmVirtualNetwork() *schema.Resource {
Read: resourceArmVirtualNetworkRead, Read: resourceArmVirtualNetworkRead,
Update: resourceArmVirtualNetworkCreate, Update: resourceArmVirtualNetworkCreate,
Delete: resourceArmVirtualNetworkDelete, Delete: resourceArmVirtualNetworkDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": { "name": {
@ -139,6 +142,8 @@ func resourceArmVirtualNetworkRead(d *schema.ResourceData, meta interface{}) err
vnet := *resp.Properties vnet := *resp.Properties
// update appropriate values // update appropriate values
d.Set("name", resp.Name)
d.Set("location", resp.Location)
d.Set("address_space", vnet.AddressSpace.AddressPrefixes) d.Set("address_space", vnet.AddressSpace.AddressPrefixes)
subnets := &schema.Set{ subnets := &schema.Set{