Skip to content

Commit

Permalink
service/sfn: Fixes for tfproviderlint R006
Browse files Browse the repository at this point in the history
Reference: #11864

`RetryFunc` should only be used when logic has a retryable condition. In the case of working with the AWS Go SDK, it also arbitrarily restricts the automatic retrying logic of API calls to the timeout, which is generally undesired.

Previously:

```
aws/resource_aws_sfn_activity.go:117:39: R006: RetryFunc should include RetryableError() handling or be removed
aws/resource_aws_sfn_state_machine.go:181:39: R006: RetryFunc should include RetryableError() handling or be removed
```

Output from acceptance testing (unrelated failure present on master due to SFN eventual consistency):

```
--- PASS: TestAccAWSSfnActivity_basic (18.37s)
--- PASS: TestAccAWSSfnActivity_Tags (43.33s)

--- FAIL: TestAccAWSSfnStateMachine_createUpdate (55.52s)
    testing.go:640: Step 1 error: Check failed: Check 5/6 error: aws_sfn_state_machine.foo: Attribute 'definition' didn't match ".*\\\"MaxAttempts\\\": 10.*", got "{\n  \"Comment\": \"A Hello World example of the Amazon States Language using an AWS Lambda Function\",\n  \"StartAt\": \"HelloWorld\",\n  \"States\": {\n    \"HelloWorld\": {\n      \"Type\": \"Task\",\n      \"Resource\": \"arn:aws:lambda:us-west-2:187416307283:function:sfn-uzt6w9nxeb\",\n      \"Retry\": [\n        {\n          \"ErrorEquals\": [\"States.ALL\"],\n          \"IntervalSeconds\": 5,\n          \"MaxAttempts\": 5,\n          \"BackoffRate\": 8.0\n        }\n      ],\n      \"End\": true\n    }\n  }\n}\n"
--- PASS: TestAccAWSSfnStateMachine_Tags (73.52s)
```
  • Loading branch information
bflad committed Feb 13, 2020
1 parent af3cf11 commit f1f397a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
13 changes: 2 additions & 11 deletions aws/resource_aws_sfn_activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/sfn"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
Expand Down Expand Up @@ -114,20 +113,12 @@ func resourceAwsSfnActivityDelete(d *schema.ResourceData, meta interface{}) erro
input := &sfn.DeleteActivityInput{
ActivityArn: aws.String(d.Id()),
}
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteActivity(input)

if err == nil {
return nil
}
_, err := conn.DeleteActivity(input)

return resource.NonRetryableError(err)
})
if isResourceTimeoutError(err) {
_, err = conn.DeleteActivity(input)
}
if err != nil {
return fmt.Errorf("Error deleting SFN Activity: %s", err)
}

return nil
}
12 changes: 2 additions & 10 deletions aws/resource_aws_sfn_state_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,12 @@ func resourceAwsSfnStateMachineDelete(d *schema.ResourceData, meta interface{})
input := &sfn.DeleteStateMachineInput{
StateMachineArn: aws.String(d.Id()),
}
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteStateMachine(input)

if err == nil {
return nil
}
_, err := conn.DeleteStateMachine(input)

return resource.NonRetryableError(err)
})
if isResourceTimeoutError(err) {
_, err = conn.DeleteStateMachine(input)
}
if err != nil {
return fmt.Errorf("Error deleting SFN state machine: %s", err)
}

return nil
}

0 comments on commit f1f397a

Please sign in to comment.