本文整理匯總了Golang中github.com/hashicorp/terraform/helper/resource.RetryableError函數的典型用法代碼示例。如果您正苦於以下問題:Golang RetryableError函數的具體用法?Golang RetryableError怎麽用?Golang RetryableError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RetryableError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: resourceAwsLambdaEventSourceMappingUpdate
// resourceAwsLambdaEventSourceMappingUpdate maps to:
// UpdateEventSourceMapping in the API / SDK
func resourceAwsLambdaEventSourceMappingUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lambdaconn
log.Printf("[DEBUG] Updating Lambda event source mapping: %s", d.Id())
params := &lambda.UpdateEventSourceMappingInput{
UUID: aws.String(d.Id()),
BatchSize: aws.Int64(int64(d.Get("batch_size").(int))),
FunctionName: aws.String(d.Get("function_name").(string)),
Enabled: aws.Bool(d.Get("enabled").(bool)),
}
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := conn.UpdateEventSourceMapping(params)
if err != nil {
if awserr, ok := err.(awserr.Error); ok {
if awserr.Code() == "InvalidParameterValueException" {
return resource.RetryableError(awserr)
}
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return fmt.Errorf("Error updating Lambda event source mapping: %s", err)
}
return resourceAwsLambdaEventSourceMappingRead(d, meta)
}
示例2: resourceAwsSecurityGroupDelete
func resourceAwsSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
log.Printf("[DEBUG] Security Group destroy: %v", d.Id())
return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteSecurityGroup(&ec2.DeleteSecurityGroupInput{
GroupId: aws.String(d.Id()),
})
if err != nil {
ec2err, ok := err.(awserr.Error)
if !ok {
return resource.RetryableError(err)
}
switch ec2err.Code() {
case "InvalidGroup.NotFound":
return nil
case "DependencyViolation":
// If it is a dependency violation, we want to retry
return resource.RetryableError(err)
default:
// Any other error, we want to quit the retry loop immediately
return resource.NonRetryableError(err)
}
}
return nil
})
}
示例3: resourceVcdNetworkDelete
func resourceVcdNetworkDelete(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*VCDClient)
vcdClient.Mutex.Lock()
defer vcdClient.Mutex.Unlock()
err := vcdClient.OrgVdc.Refresh()
if err != nil {
return fmt.Errorf("Error refreshing vdc: %#v", err)
}
network, err := vcdClient.OrgVdc.FindVDCNetwork(d.Id())
if err != nil {
return fmt.Errorf("Error finding network: %#v", err)
}
err = retryCall(vcdClient.MaxRetryTimeout, func() *resource.RetryError {
task, err := network.Delete()
if err != nil {
return resource.RetryableError(
fmt.Errorf("Error Deleting Network: %#v", err))
}
return resource.RetryableError(task.WaitTaskCompletion())
})
if err != nil {
return err
}
return nil
}
示例4: resourceVcdSNATDelete
func resourceVcdSNATDelete(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*VCDClient)
// Multiple VCD components need to run operations on the Edge Gateway, as
// the edge gatway will throw back an error if it is already performing an
// operation we must wait until we can aquire a lock on the client
vcdClient.Mutex.Lock()
defer vcdClient.Mutex.Unlock()
edgeGateway, err := vcdClient.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string))
if err != nil {
return fmt.Errorf("Unable to find edge gateway: %#v", err)
}
err = retryCall(vcdClient.MaxRetryTimeout, func() *resource.RetryError {
task, err := edgeGateway.RemoveNATMapping("SNAT", d.Get("internal_ip").(string),
d.Get("external_ip").(string),
"")
if err != nil {
return resource.RetryableError(fmt.Errorf("Error setting SNAT rules: %#v", err))
}
return resource.RetryableError(task.WaitTaskCompletion())
})
if err != nil {
return err
}
return nil
}
示例5: resourceVcdSNATCreate
func resourceVcdSNATCreate(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*VCDClient)
// Multiple VCD components need to run operations on the Edge Gateway, as
// the edge gatway will throw back an error if it is already performing an
// operation we must wait until we can aquire a lock on the client
vcdClient.Mutex.Lock()
defer vcdClient.Mutex.Unlock()
// Creating a loop to offer further protection from the edge gateway erroring
// due to being busy eg another person is using another client so wouldn't be
// constrained by out lock. If the edge gateway reurns with a busy error, wait
// 3 seconds and then try again. Continue until a non-busy error or success
edgeGateway, err := vcdClient.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string))
if err != nil {
return fmt.Errorf("Unable to find edge gateway: %#v", err)
}
err = retryCall(vcdClient.MaxRetryTimeout, func() *resource.RetryError {
task, err := edgeGateway.AddNATMapping("SNAT", d.Get("internal_ip").(string),
d.Get("external_ip").(string),
"any")
if err != nil {
return resource.RetryableError(fmt.Errorf("Error setting SNAT rules: %#v", err))
}
return resource.RetryableError(task.WaitTaskCompletion())
})
if err != nil {
return err
}
d.SetId(d.Get("internal_ip").(string))
return nil
}
示例6: resourceAwsElasticacheSecurityGroupDelete
func resourceAwsElasticacheSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).elasticacheconn
log.Printf("[DEBUG] Cache security group delete: %s", d.Id())
return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteCacheSecurityGroup(&elasticache.DeleteCacheSecurityGroupInput{
CacheSecurityGroupName: aws.String(d.Id()),
})
if err != nil {
apierr, ok := err.(awserr.Error)
if !ok {
return resource.RetryableError(err)
}
log.Printf("[DEBUG] APIError.Code: %v", apierr.Code())
switch apierr.Code() {
case "InvalidCacheSecurityGroupState":
return resource.RetryableError(err)
case "DependencyViolation":
// If it is a dependency violation, we want to retry
return resource.RetryableError(err)
default:
return resource.NonRetryableError(err)
}
}
return nil
})
}
示例7: resourceAwsVpnGatewayDelete
func resourceAwsVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
// Detach if it is attached
if err := resourceAwsVpnGatewayDetach(d, meta); err != nil {
return err
}
log.Printf("[INFO] Deleting VPN gateway: %s", d.Id())
return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteVpnGateway(&ec2.DeleteVpnGatewayInput{
VpnGatewayId: aws.String(d.Id()),
})
if err == nil {
return nil
}
ec2err, ok := err.(awserr.Error)
if !ok {
return resource.RetryableError(err)
}
switch ec2err.Code() {
case "InvalidVpnGatewayID.NotFound":
return nil
case "IncorrectState":
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
})
}
示例8: resourceAwsAutoscalingGroupDelete
func resourceAwsAutoscalingGroupDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).autoscalingconn
// Read the autoscaling group first. If it doesn't exist, we're done.
// We need the group in order to check if there are instances attached.
// If so, we need to remove those first.
g, err := getAwsAutoscalingGroup(d.Id(), conn)
if err != nil {
return err
}
if g == nil {
log.Printf("[INFO] Autoscaling Group %q not found", d.Id())
d.SetId("")
return nil
}
if len(g.Instances) > 0 || *g.DesiredCapacity > 0 {
if err := resourceAwsAutoscalingGroupDrain(d, meta); err != nil {
return err
}
}
log.Printf("[DEBUG] AutoScaling Group destroy: %v", d.Id())
deleteopts := autoscaling.DeleteAutoScalingGroupInput{
AutoScalingGroupName: aws.String(d.Id()),
ForceDelete: aws.Bool(d.Get("force_delete").(bool)),
}
// We retry the delete operation to handle InUse/InProgress errors coming
// from scaling operations. We should be able to sneak in a delete in between
// scaling operations within 5m.
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
if _, err := conn.DeleteAutoScalingGroup(&deleteopts); err != nil {
if awserr, ok := err.(awserr.Error); ok {
switch awserr.Code() {
case "InvalidGroup.NotFound":
// Already gone? Sure!
return nil
case "ResourceInUse", "ScalingActivityInProgress":
// These are retryable
return resource.RetryableError(awserr)
}
}
// Didn't recognize the error, so shouldn't retry.
return resource.NonRetryableError(err)
}
// Successful delete
return nil
})
if err != nil {
return err
}
return resource.Retry(5*time.Minute, func() *resource.RetryError {
if g, _ = getAwsAutoscalingGroup(d.Id(), conn); g != nil {
return resource.RetryableError(
fmt.Errorf("Auto Scaling Group still exists"))
}
return nil
})
}
示例9: resourceVcdVAppDelete
func resourceVcdVAppDelete(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*VCDClient)
vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Id())
if err != nil {
return fmt.Errorf("error finding vapp: %s", err)
}
if err != nil {
return fmt.Errorf("Error getting VApp status: %#v", err)
}
_ = retryCall(vcdClient.MaxRetryTimeout, func() *resource.RetryError {
task, err := vapp.Undeploy()
if err != nil {
return resource.RetryableError(fmt.Errorf("Error undeploying: %#v", err))
}
return resource.RetryableError(task.WaitTaskCompletion())
})
err = retryCall(vcdClient.MaxRetryTimeout, func() *resource.RetryError {
task, err := vapp.Delete()
if err != nil {
return resource.RetryableError(fmt.Errorf("Error deleting: %#v", err))
}
return resource.RetryableError(task.WaitTaskCompletion())
})
return err
}
示例10: deleteRunningServer
// deleteRunningServer terminates the server and waits until it is removed.
func deleteRunningServer(scaleway *api.ScalewayAPI, server *api.ScalewayServer) error {
err := scaleway.PostServerAction(server.Identifier, "terminate")
if err != nil {
if serr, ok := err.(api.ScalewayAPIError); ok {
if serr.StatusCode == 404 {
return nil
}
}
return err
}
return resource.Retry(20*time.Minute, func() *resource.RetryError {
_, err := scaleway.GetServer(server.Identifier)
if err == nil {
return resource.RetryableError(fmt.Errorf("Waiting for server %q to be deleted", server.Identifier))
}
if serr, ok := err.(api.ScalewayAPIError); ok {
if serr.StatusCode == 404 {
return nil
}
}
return resource.RetryableError(err)
})
}
示例11: resourceVcdFirewallRulesCreate
func resourceVcdFirewallRulesCreate(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*VCDClient)
vcdClient.Mutex.Lock()
defer vcdClient.Mutex.Unlock()
edgeGateway, err := vcdClient.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string))
if err != nil {
return fmt.Errorf("Unable to find edge gateway: %s", err)
}
err = retryCall(vcdClient.MaxRetryTimeout, func() *resource.RetryError {
edgeGateway.Refresh()
firewallRules, _ := expandFirewallRules(d, edgeGateway.EdgeGateway)
task, err := edgeGateway.CreateFirewallRules(d.Get("default_action").(string), firewallRules)
if err != nil {
log.Printf("[INFO] Error setting firewall rules: %s", err)
return resource.RetryableError(
fmt.Errorf("Error setting firewall rules: %#v", err))
}
return resource.RetryableError(task.WaitTaskCompletion())
})
if err != nil {
return fmt.Errorf("Error completing tasks: %#v", err)
}
d.SetId(d.Get("edge_gateway").(string))
return resourceFirewallRulesRead(d, meta)
}
示例12: subscribeToSNSTopic
func subscribeToSNSTopic(d *schema.ResourceData, snsconn *sns.SNS) (output *sns.SubscribeOutput, err error) {
protocol := d.Get("protocol").(string)
endpoint := d.Get("endpoint").(string)
topic_arn := d.Get("topic_arn").(string)
endpoint_auto_confirms := d.Get("endpoint_auto_confirms").(bool)
confirmation_timeout_in_minutes := d.Get("confirmation_timeout_in_minutes").(int)
if strings.Contains(protocol, "http") && !endpoint_auto_confirms {
return nil, fmt.Errorf("Protocol http/https is only supported for endpoints which auto confirms!")
}
log.Printf("[DEBUG] SNS create topic subscription: %s (%s) @ '%s'", endpoint, protocol, topic_arn)
req := &sns.SubscribeInput{
Protocol: aws.String(protocol),
Endpoint: aws.String(endpoint),
TopicArn: aws.String(topic_arn),
}
output, err = snsconn.Subscribe(req)
if err != nil {
return nil, fmt.Errorf("Error creating SNS topic: %s", err)
}
log.Printf("[DEBUG] Finished subscribing to topic %s with subscription arn %s", topic_arn, *output.SubscriptionArn)
if strings.Contains(protocol, "http") && subscriptionHasPendingConfirmation(output.SubscriptionArn) {
log.Printf("[DEBUG] SNS create topic subscription is pending so fetching the subscription list for topic : %s (%s) @ '%s'", endpoint, protocol, topic_arn)
err = resource.Retry(time.Duration(confirmation_timeout_in_minutes)*time.Minute, func() *resource.RetryError {
subscription, err := findSubscriptionByNonID(d, snsconn)
if subscription != nil {
output.SubscriptionArn = subscription.SubscriptionArn
return nil
}
if err != nil {
return resource.RetryableError(
fmt.Errorf("Error fetching subscriptions for SNS topic %s: %s", topic_arn, err))
}
return resource.RetryableError(
fmt.Errorf("Endpoint (%s) did not autoconfirm the subscription for topic %s", endpoint, topic_arn))
})
if err != nil {
return nil, err
}
}
log.Printf("[DEBUG] Created new subscription! %s", *output.SubscriptionArn)
return output, nil
}
示例13: testAccCheckAWSS3BucketLambdaFunctionConfiguration
func testAccCheckAWSS3BucketLambdaFunctionConfiguration(n, i, t string, events []string, filters *s3.KeyFilter) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, _ := s.RootModule().Resources[n]
funcArn := s.RootModule().Resources[t].Primary.Attributes["arn"]
conn := testAccProvider.Meta().(*AWSClient).s3conn
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
out, err := conn.GetBucketNotificationConfiguration(&s3.GetBucketNotificationConfigurationRequest{
Bucket: aws.String(rs.Primary.ID),
})
if err != nil {
return resource.NonRetryableError(fmt.Errorf("GetBucketNotification error: %v", err))
}
eventSlice := sort.StringSlice(events)
eventSlice.Sort()
outputFunctions := out.LambdaFunctionConfigurations
matched := false
for _, outputFunc := range outputFunctions {
if *outputFunc.Id == i {
matched = true
if *outputFunc.LambdaFunctionArn != funcArn {
return resource.RetryableError(fmt.Errorf("bad lambda function arn, expected: %s, got %#v", funcArn, *outputFunc.LambdaFunctionArn))
}
if filters != nil {
if !reflect.DeepEqual(filters, outputFunc.Filter.Key) {
return resource.RetryableError(fmt.Errorf("bad notification filters, expected: %#v, got %#v", filters, outputFunc.Filter.Key))
}
} else {
if outputFunc.Filter != nil {
return resource.RetryableError(fmt.Errorf("bad notification filters, expected: nil, got %#v", outputFunc.Filter))
}
}
outputEventSlice := sort.StringSlice(aws.StringValueSlice(outputFunc.Events))
outputEventSlice.Sort()
if !reflect.DeepEqual(eventSlice, outputEventSlice) {
return resource.RetryableError(fmt.Errorf("bad notification events, expected: %#v, got %#v", events, outputEventSlice))
}
}
}
if !matched {
return resource.RetryableError(fmt.Errorf("No match lambda function configurations: %#v", out))
}
return nil
})
return err
}
}
示例14: testAccAWSVpnGatewayDisappears
func testAccAWSVpnGatewayDisappears(gateway *ec2.VpnGateway) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
_, err := conn.DetachVpnGateway(&ec2.DetachVpnGatewayInput{
VpnGatewayId: gateway.VpnGatewayId,
VpcId: gateway.VpcAttachments[0].VpcId,
})
if err != nil {
ec2err, ok := err.(awserr.Error)
if ok {
if ec2err.Code() == "InvalidVpnGatewayID.NotFound" {
return nil
} else if ec2err.Code() == "InvalidVpnGatewayAttachment.NotFound" {
return nil
}
}
if err != nil {
return err
}
}
opts := &ec2.DeleteVpnGatewayInput{
VpnGatewayId: gateway.VpnGatewayId,
}
if _, err := conn.DeleteVpnGateway(opts); err != nil {
return err
}
return resource.Retry(40*time.Minute, func() *resource.RetryError {
opts := &ec2.DescribeVpnGatewaysInput{
VpnGatewayIds: []*string{gateway.VpnGatewayId},
}
resp, err := conn.DescribeVpnGateways(opts)
if err != nil {
cgw, ok := err.(awserr.Error)
if ok && cgw.Code() == "InvalidVpnGatewayID.NotFound" {
return nil
}
if ok && cgw.Code() == "IncorrectState" {
return resource.RetryableError(fmt.Errorf(
"Waiting for VPN Gateway to be in the correct state: %v", gateway.VpnGatewayId))
}
return resource.NonRetryableError(
fmt.Errorf("Error retrieving VPN Gateway: %s", err))
}
if *resp.VpnGateways[0].State == "deleted" {
return nil
}
return resource.RetryableError(fmt.Errorf(
"Waiting for VPN Gateway: %v", gateway.VpnGatewayId))
})
}
}
示例15: resourceAwsCustomerGatewayDelete
func resourceAwsCustomerGatewayDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
_, err := conn.DeleteCustomerGateway(&ec2.DeleteCustomerGatewayInput{
CustomerGatewayId: aws.String(d.Id()),
})
if err != nil {
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidCustomerGatewayID.NotFound" {
d.SetId("")
return nil
} else {
log.Printf("[ERROR] Error deleting CustomerGateway: %s", err)
return err
}
}
gatewayFilter := &ec2.Filter{
Name: aws.String("customer-gateway-id"),
Values: []*string{aws.String(d.Id())},
}
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, err := conn.DescribeCustomerGateways(&ec2.DescribeCustomerGatewaysInput{
Filters: []*ec2.Filter{gatewayFilter},
})
if err != nil {
if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "InvalidCustomerGatewayID.NotFound" {
return nil
}
return resource.NonRetryableError(err)
}
if len(resp.CustomerGateways) != 1 {
return resource.RetryableError(fmt.Errorf("[ERROR] Error finding CustomerGateway for delete: %s", d.Id()))
}
switch *resp.CustomerGateways[0].State {
case "pending", "available", "deleting":
return resource.RetryableError(fmt.Errorf("[DEBUG] Gateway (%s) in state (%s), retrying", d.Id(), *resp.CustomerGateways[0].State))
case "deleted":
return nil
default:
return resource.RetryableError(fmt.Errorf("[DEBUG] Unrecognized state (%s) for Customer Gateway delete on (%s)", *resp.CustomerGateways[0].State, d.Id()))
}
})
if err != nil {
return err
}
return nil
}