provider/aws: Dynamo DB test/destroy updates

This commit is contained in:
clint shryock 2016-01-04 16:56:26 -06:00
parent 89f71d4ec4
commit dd3a2aa4e9
2 changed files with 40 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/hashicorp/terraform/helper/resource"
"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"
@ -660,6 +661,37 @@ func resourceAwsDynamoDbTableDelete(d *schema.ResourceData, meta interface{}) er
if err != nil { if err != nil {
return err return err
} }
params := &dynamodb.DescribeTableInput{
TableName: aws.String(d.Id()),
}
err = resource.Retry(10*time.Minute, func() error {
t, err := dynamodbconn.DescribeTable(params)
if err != nil {
if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "ResourceNotFoundException" {
return nil
}
// Didn't recognize the error, so shouldn't retry.
return resource.RetryError{Err: err}
}
if t != nil {
if t.Table.TableStatus != nil && strings.ToLower(*t.Table.TableStatus) == "deleting" {
log.Printf("[DEBUG] AWS Dynamo DB table (%s) is still deleting", d.Id())
return fmt.Errorf("still deleting")
}
}
// we should be not found or deleting, so error here
return resource.RetryError{Err: fmt.Errorf("[ERR] Error deleting Dynamo DB table, unexpected state: %s", t)}
})
// check error from retry
if err != nil {
return err
}
return nil return nil
} }

View File

@ -2,6 +2,7 @@ package aws
import ( import (
"fmt" "fmt"
"log"
"testing" "testing"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -11,7 +12,7 @@ import (
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccAWSDynamoDbTable(t *testing.T) { func TestAccAWSDynamoDbTable_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,
@ -101,21 +102,23 @@ func testAccCheckAWSDynamoDbTableDestroy(s *terraform.State) error {
continue continue
} }
fmt.Printf("[DEBUG] Checking if DynamoDB table %s exists", rs.Primary.ID) log.Printf("[DEBUG] Checking if DynamoDB table %s exists", rs.Primary.ID)
// Check if queue exists by checking for its attributes // Check if queue exists by checking for its attributes
params := &dynamodb.DescribeTableInput{ params := &dynamodb.DescribeTableInput{
TableName: aws.String(rs.Primary.ID), TableName: aws.String(rs.Primary.ID),
} }
_, err := conn.DescribeTable(params) _, err := conn.DescribeTable(params)
if err == nil { if err == nil {
return fmt.Errorf("DynamoDB table %s still exists. Failing!", rs.Primary.ID) return fmt.Errorf("DynamoDB table %s still exists. Failing!", rs.Primary.ID)
} }
// Verify the error is what we want // Verify the error is what we want
_, ok := err.(awserr.Error) if dbErr, ok := err.(awserr.Error); ok && dbErr.Code() == "ResourceNotFoundException" {
if !ok { return nil
return err
} }
return err
} }
return nil return nil