Merge pull request #2231 from svanharmelen/b-fixup-tests

provider/azure: update/fix the CheckDestroy functions in the tests
This commit is contained in:
Paul Hinze 2015-06-04 11:15:30 -05:00
commit e2e2cd097e
4 changed files with 20 additions and 36 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/svanharmelen/azure-sdk-for-go/management"
"github.com/svanharmelen/azure-sdk-for-go/management/virtualmachinedisk"
)
@ -155,15 +156,13 @@ func testAccCheckAzureDataDiskDestroy(s *terraform.State) error {
return err
}
req, err := virtualmachinedisk.NewClient(mc).DeleteDataDisk(vm, vm, vm, lun, true)
if err != nil {
return fmt.Errorf("Error deleting Data Disk (%s): %s", rs.Primary.ID, err)
_, err = virtualmachinedisk.NewClient(mc).GetDataDisk(vm, vm, vm, lun)
if err == nil {
return fmt.Errorf("Resource %s still exists", rs.Primary.ID)
}
// Wait until the data disk is deleted
if err := mc.WaitForOperation(req, nil); err != nil {
return fmt.Errorf(
"Error deleting Data Disk (%s): %s", rs.Primary.ID, err)
if !management.IsResourceNotFoundError(err) {
return err
}
}

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/svanharmelen/azure-sdk-for-go/management"
"github.com/svanharmelen/azure-sdk-for-go/management/hostedservice"
"github.com/svanharmelen/azure-sdk-for-go/management/virtualmachine"
)
@ -294,15 +295,13 @@ func testAccCheckAzureInstanceDestroy(s *terraform.State) error {
return fmt.Errorf("No instance ID is set")
}
req, err := hostedservice.NewClient(mc).DeleteHostedService(rs.Primary.ID, true)
if err != nil {
return fmt.Errorf("Error deleting instance (%s): %s", rs.Primary.ID, err)
_, err := hostedservice.NewClient(mc).GetHostedService(rs.Primary.ID)
if err == nil {
return fmt.Errorf("Resource %s still exists", rs.Primary.ID)
}
// Wait until the instance is deleted
if err := mc.WaitForOperation(req, nil); err != nil {
return fmt.Errorf(
"Error deleting instance (%s): %s", rs.Primary.ID, err)
if !management.IsResourceNotFoundError(err) {
return err
}
}

View File

@ -6,6 +6,7 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/svanharmelen/azure-sdk-for-go/management"
"github.com/svanharmelen/azure-sdk-for-go/management/networksecuritygroup"
)
@ -214,15 +215,13 @@ func testAccCheckAzureSecurityGroupDestroy(s *terraform.State) error {
return fmt.Errorf("No Network Security Group ID is set")
}
req, err := networksecuritygroup.NewClient(mc).DeleteNetworkSecurityGroup(rs.Primary.ID)
if err != nil {
return fmt.Errorf("Error deleting Network Security Group (%s): %s", rs.Primary.ID, err)
_, err := networksecuritygroup.NewClient(mc).GetNetworkSecurityGroup(rs.Primary.ID)
if err == nil {
return fmt.Errorf("Resource %s still exists", rs.Primary.ID)
}
// Wait until the instance is deleted
if err := mc.WaitForOperation(req, nil); err != nil {
return fmt.Errorf(
"Error deleting Network Security Group (%s): %s", rs.Primary.ID, err)
if !management.IsResourceNotFoundError(err) {
return err
}
}

View File

@ -188,24 +188,11 @@ func testAccCheckAzureVirtualNetworkDestroy(s *terraform.State) error {
return fmt.Errorf("Error retrieving Virtual Network Configuration: %s", err)
}
filtered := nc.Configuration.VirtualNetworkSites[:0]
for _, n := range nc.Configuration.VirtualNetworkSites {
if n.Name != rs.Primary.ID {
filtered = append(filtered, n)
if n.Name == rs.Primary.ID {
return fmt.Errorf("Resource %s still exists", rs.Primary.ID)
}
}
nc.Configuration.VirtualNetworkSites = filtered
req, err := virtualnetwork.NewClient(mc).SetVirtualNetworkConfiguration(nc)
if err != nil {
return fmt.Errorf("Error deleting Virtual Network %s: %s", rs.Primary.ID, err)
}
// Wait until the virtual network is deleted
if err := mc.WaitForOperation(req, nil); err != nil {
return fmt.Errorf("Error waiting for Virtual Network %s to be deleted: %s", rs.Primary.ID, err)
}
}
return nil