update AWS Service Directory delete method and test
This commit is contained in:
parent
dd3a2aa4e9
commit
1510277f45
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
"github.com/aws/aws-sdk-go/service/directoryservice"
|
"github.com/aws/aws-sdk-go/service/directoryservice"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
)
|
)
|
||||||
|
@ -252,6 +253,8 @@ func resourceAwsDirectoryServiceDirectoryDelete(d *schema.ResourceData, meta int
|
||||||
input := directoryservice.DeleteDirectoryInput{
|
input := directoryservice.DeleteDirectoryInput{
|
||||||
DirectoryId: aws.String(d.Id()),
|
DirectoryId: aws.String(d.Id()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] Delete Directory input: %s", input)
|
||||||
_, err := dsconn.DeleteDirectory(&input)
|
_, err := dsconn.DeleteDirectory(&input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -261,17 +264,20 @@ func resourceAwsDirectoryServiceDirectoryDelete(d *schema.ResourceData, meta int
|
||||||
log.Printf("[DEBUG] Waiting for DS (%q) to be deleted", d.Id())
|
log.Printf("[DEBUG] Waiting for DS (%q) to be deleted", d.Id())
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf := &resource.StateChangeConf{
|
||||||
Pending: []string{"Deleting"},
|
Pending: []string{"Deleting"},
|
||||||
Target: "",
|
Target: "Deleted",
|
||||||
Refresh: func() (interface{}, string, error) {
|
Refresh: func() (interface{}, string, error) {
|
||||||
resp, err := dsconn.DescribeDirectories(&directoryservice.DescribeDirectoriesInput{
|
resp, err := dsconn.DescribeDirectories(&directoryservice.DescribeDirectoriesInput{
|
||||||
DirectoryIds: []*string{aws.String(d.Id())},
|
DirectoryIds: []*string{aws.String(d.Id())},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
if dserr, ok := err.(awserr.Error); ok && dserr.Code() == "EntityDoesNotExistException" {
|
||||||
|
return 42, "Deleted", nil
|
||||||
|
}
|
||||||
|
return nil, "error", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(resp.DirectoryDescriptions) == 0 {
|
if len(resp.DirectoryDescriptions) == 0 {
|
||||||
return nil, "", nil
|
return 42, "Deleted", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ds := resp.DirectoryDescriptions[0]
|
ds := resp.DirectoryDescriptions[0]
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
"github.com/aws/aws-sdk-go/service/directoryservice"
|
"github.com/aws/aws-sdk-go/service/directoryservice"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
@ -65,14 +66,35 @@ func TestAccAWSDirectoryServiceDirectory_withAliasAndSso(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckDirectoryServiceDirectoryDestroy(s *terraform.State) error {
|
func testAccCheckDirectoryServiceDirectoryDestroy(s *terraform.State) error {
|
||||||
if len(s.RootModule().Resources) > 0 {
|
dsconn := testAccProvider.Meta().(*AWSClient).dsconn
|
||||||
return fmt.Errorf("Expected all resources to be gone, but found: %#v",
|
|
||||||
s.RootModule().Resources)
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "aws_directory_service_directory" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
input := directoryservice.DescribeDirectoriesInput{
|
||||||
|
DirectoryIds: []*string{aws.String(rs.Primary.ID)},
|
||||||
|
}
|
||||||
|
out, err := dsconn.DescribeDirectories(&input)
|
||||||
|
if err != nil {
|
||||||
|
// EntityDoesNotExistException means it's gone, this is good
|
||||||
|
if dserr, ok := err.(awserr.Error); ok && dserr.Code() == "EntityDoesNotExistException" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if out != nil && len(out.DirectoryDescriptions) > 0 {
|
||||||
|
return fmt.Errorf("Expected AWS Directory Service Directory to be gone, but was still found")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("Default error in Service Directory Test")
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckServiceDirectoryExists(name string) resource.TestCheckFunc {
|
func testAccCheckServiceDirectoryExists(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]
|
||||||
|
|
Loading…
Reference in New Issue