Skip to content

Commit

Permalink
Merge pull request #9821 from terraform-providers/rfd-retry-tags
Browse files Browse the repository at this point in the history
Final tag retries
  • Loading branch information
ryndaniels authored Aug 20, 2019
2 parents 415a75e + 9b3ff5f commit a346fef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
24 changes: 16 additions & 8 deletions aws/tagsDynamoDb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ func setTagsDynamoDb(conn *dynamodb.DynamoDB, d *schema.ResourceData) error {

// Set tags
if len(remove) > 0 {
input := &dynamodb.UntagResourceInput{
ResourceArn: aws.String(arn),
TagKeys: remove,
}
err := resource.Retry(2*time.Minute, func() *resource.RetryError {
log.Printf("[DEBUG] Removing tags: %#v from %s", remove, d.Id())
_, err := conn.UntagResource(&dynamodb.UntagResourceInput{
ResourceArn: aws.String(arn),
TagKeys: remove,
})
_, err := conn.UntagResource(input)
if err != nil {
if isAWSErr(err, dynamodb.ErrCodeResourceNotFoundException, "") {
return resource.RetryableError(err)
Expand All @@ -36,17 +37,21 @@ func setTagsDynamoDb(conn *dynamodb.DynamoDB, d *schema.ResourceData) error {
}
return nil
})
if isResourceTimeoutError(err) {
_, err = conn.UntagResource(input)
}
if err != nil {
return err
}
}
if len(create) > 0 {
input := &dynamodb.TagResourceInput{
ResourceArn: aws.String(arn),
Tags: create,
}
err := resource.Retry(2*time.Minute, func() *resource.RetryError {
log.Printf("[DEBUG] Creating tags: %s for %s", create, d.Id())
_, err := conn.TagResource(&dynamodb.TagResourceInput{
ResourceArn: aws.String(arn),
Tags: create,
})
_, err := conn.TagResource(input)
if err != nil {
if isAWSErr(err, dynamodb.ErrCodeResourceNotFoundException, "") {
return resource.RetryableError(err)
Expand All @@ -55,6 +60,9 @@ func setTagsDynamoDb(conn *dynamodb.DynamoDB, d *schema.ResourceData) error {
}
return nil
})
if isResourceTimeoutError(err) {
_, err = conn.TagResource(input)
}
if err != nil {
return err
}
Expand Down
24 changes: 16 additions & 8 deletions aws/tags_sagemaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ func setSagemakerTags(conn *sagemaker.SageMaker, d *schema.ResourceData) error {
create, remove := diffSagemakerTags(tagsFromMapSagemaker(o), tagsFromMapSagemaker(n))

if len(remove) > 0 {
input := &sagemaker.DeleteTagsInput{
ResourceArn: aws.String(d.Get("arn").(string)),
TagKeys: remove,
}
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
log.Printf("[DEBUG] Removing tags: %#v from %s", remove, d.Id())
_, err := conn.DeleteTags(&sagemaker.DeleteTagsInput{
ResourceArn: aws.String(d.Get("arn").(string)),
TagKeys: remove,
})
_, err := conn.DeleteTags(input)
if err != nil {
sagemakerErr, ok := err.(awserr.Error)
if ok && sagemakerErr.Code() == "ResourceNotFound" {
Expand All @@ -61,17 +62,21 @@ func setSagemakerTags(conn *sagemaker.SageMaker, d *schema.ResourceData) error {
}
return nil
})
if isResourceTimeoutError(err) {
_, err = conn.DeleteTags(input)
}
if err != nil {
return err
}
}
if len(create) > 0 {
input := &sagemaker.AddTagsInput{
ResourceArn: aws.String(d.Get("arn").(string)),
Tags: create,
}
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
log.Printf("[DEBUG] Creating tags: %s for %s", create, d.Id())
_, err := conn.AddTags(&sagemaker.AddTagsInput{
ResourceArn: aws.String(d.Get("arn").(string)),
Tags: create,
})
_, err := conn.AddTags(input)
if err != nil {
sagemakerErr, ok := err.(awserr.Error)
if ok && sagemakerErr.Code() == "ResourceNotFound" {
Expand All @@ -81,6 +86,9 @@ func setSagemakerTags(conn *sagemaker.SageMaker, d *schema.ResourceData) error {
}
return nil
})
if isResourceTimeoutError(err) {
_, err = conn.AddTags(input)
}
if err != nil {
return err
}
Expand Down

0 comments on commit a346fef

Please sign in to comment.