Skip to content

Commit

Permalink
Fixed the eventual consistency of the read after delete for SFN funct…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
Ninir committed Jan 31, 2017
1 parent e7e54c3 commit e47b883
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
31 changes: 21 additions & 10 deletions builtin/providers/aws/resource_aws_sfn_activity_test.go
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"time"
)

func TestAccAWSSfnActivity_basic(t *testing.T) {
Expand Down Expand Up @@ -65,19 +66,29 @@ func testAccCheckAWSSfnActivityDestroy(s *terraform.State) error {
continue
}

out, err := conn.DescribeActivity(&sfn.DescribeActivityInput{
ActivityArn: aws.String(rs.Primary.ID),
})
// Retrying as Read after Delete is not always consistent
retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError {
var err error

if err != nil {
if wserr, ok := err.(awserr.Error); ok && wserr.Code() == "ActivityDoesNotExist" {
return nil
_, err = conn.DescribeActivity(&sfn.DescribeActivityInput{
ActivityArn: aws.String(rs.Primary.ID),
})

if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ActivityDoesNotExist" {
return nil
}

return resource.NonRetryableError(err)
}
return err
}

if out != nil {
return fmt.Errorf("Expected AWS Step Function Activity to be destroyed, but was still found")
// If there are no errors, the removal failed
// and the object is not yet removed.
return resource.RetryableError(fmt.Errorf("Expected AWS Step Function Activity to be destroyed, but was still found, retrying"))
})

if retryErr != nil {
return retryErr
}

return nil
Expand Down
3 changes: 3 additions & 0 deletions builtin/providers/aws/resource_aws_sfn_state_machine.go
Expand Up @@ -73,6 +73,9 @@ func resourceAwsSfnStateMachineCreate(d *schema.ResourceData, meta interface{})
activity, err = conn.CreateStateMachine(params)

if err != nil {
// Note: the instance may be in a deleting mode, hence the retry
// when creating the step function. This can happen when we are
// updating the resource (since there is no update API call).
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "StateMachineDeleting" {
return resource.RetryableError(err)
}
Expand Down

0 comments on commit e47b883

Please sign in to comment.