-
Notifications
You must be signed in to change notification settings - Fork 9.2k
/
awserr.go
54 lines (49 loc) · 1.22 KB
/
awserr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package aws
import (
"strings"
"time"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/hashicorp/terraform/helper/resource"
)
func isAWSErr(err error, code string, message string) bool {
if err, ok := err.(awserr.Error); ok {
return err.Code() == code && strings.Contains(err.Message(), message)
}
return false
}
func retryOnAwsCode(code string, f func() (interface{}, error)) (interface{}, error) {
var resp interface{}
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
var err error
resp, err = f()
if err != nil {
awsErr, ok := err.(awserr.Error)
if ok && awsErr.Code() == code {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
return resp, err
}
func retryOnAwsCodes(codes []string, f func() (interface{}, error)) (interface{}, error) {
var resp interface{}
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
var err error
resp, err = f()
if err != nil {
awsErr, ok := err.(awserr.Error)
if ok {
for _, code := range codes {
if awsErr.Code() == code {
return resource.RetryableError(err)
}
}
}
return resource.NonRetryableError(err)
}
return nil
})
return resp, err
}