mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
replace big retry func with resource.Retry
This commit is contained in:
parent
1ddfd7ced3
commit
b51f425dac
@ -59,18 +59,24 @@ func resourceAwsAutoscalingLifecycleHook() *schema.Resource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsAutoscalingLifecycleHookPut(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsAutoscalingLifecycleHookPut(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
conn := meta.(*AWSClient).autoscalingconn
|
||||||
params := getAwsAutoscalingPutLifecycleHookInput(d)
|
params := getAwsAutoscalingPutLifecycleHookInput(d)
|
||||||
|
|
||||||
log.Printf("[DEBUG] AutoScaling PutLifecyleHook: %#v", params)
|
log.Printf("[DEBUG] AutoScaling PutLifecyleHook: %s", params)
|
||||||
stateConf := &resource.StateChangeConf{
|
err := resource.Retry(5*time.Minute, func() error {
|
||||||
Pending: []string{"retrying"},
|
_, err := conn.PutLifecycleHook(¶ms)
|
||||||
Target: "success",
|
|
||||||
Refresh: resourceAwsAutoscalingLifecycleHookRefreshFunc(meta, params),
|
if err != nil {
|
||||||
Timeout: 1 * time.Minute,
|
if awsErr, ok := err.(awserr.Error); ok {
|
||||||
MinTimeout: 3 * time.Second,
|
if strings.Contains(awsErr.Message(), "Unable to publish test message to notification target") {
|
||||||
}
|
return fmt.Errorf("[DEBUG] Retrying AWS AutoScaling Lifecycle Hook: %s", params)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resource.RetryError{Err: fmt.Errorf("Error putting lifecycle hook: %s", err)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
_, err := stateConf.WaitForState()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -80,25 +86,6 @@ func resourceAwsAutoscalingLifecycleHookPut(d *schema.ResourceData, meta interfa
|
|||||||
return resourceAwsAutoscalingLifecycleHookRead(d, meta)
|
return resourceAwsAutoscalingLifecycleHookRead(d, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsAutoscalingLifecycleHookRefreshFunc(
|
|
||||||
meta interface{}, params autoscaling.PutLifecycleHookInput) resource.StateRefreshFunc {
|
|
||||||
return func() (interface{}, string, error) {
|
|
||||||
conn := meta.(*AWSClient).autoscalingconn
|
|
||||||
_, err := conn.PutLifecycleHook(¶ms)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
if awsErr, ok := err.(awserr.Error); ok {
|
|
||||||
if strings.Contains(awsErr.Message(), "Unable to publish test message to notification target") {
|
|
||||||
log.Printf("[DEBUG] Retrying AWS AutoScaling Lifecycle Hook: %s", params)
|
|
||||||
return 41, "retrying", nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, "failed", fmt.Errorf("Error putting lifecycle hook: %s", err)
|
|
||||||
}
|
|
||||||
return 42, "success", nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func resourceAwsAutoscalingLifecycleHookRead(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsAutoscalingLifecycleHookRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
p, err := getAwsAutoscalingLifecycleHook(d, meta)
|
p, err := getAwsAutoscalingLifecycleHook(d, meta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user