Skip to content

Add retry to redis and as #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tencentcloud/extension_as.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ const (
SCALING_GROUP_ACTIVITY_STATUS_FAILED = "FAILED"
SCALING_GROUP_ACTIVITY_STATUS_CANCELLED = "CANCELLED"
)

const AsScheduleNotFound = "ResourceNotFound.ScheduledActionNotFound"
3 changes: 3 additions & 0 deletions tencentcloud/extension_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,6 @@ const (
REDIS_TASK_FAILED = "failed"
REDIS_TASK_ERROR = "error"
)

//sdk redis not found error
const RedisInstanceNotFound = "ResourceNotFound.InstanceNotExists"
33 changes: 27 additions & 6 deletions tencentcloud/resource_tc_as_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package tencentcloud
import (
"context"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -73,12 +74,17 @@ func resourceTencentCloudAsAttachmentRead(d *schema.ResourceData, meta interface
asService := AsService{
client: meta.(*TencentCloudClient).apiV3Conn,
}
instanceIds, err := asService.DescribeAutoScalingAttachment(ctx, scalingGroupId)
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
instanceIds, e := asService.DescribeAutoScalingAttachment(ctx, scalingGroupId)
if e != nil {
return retryError(e)
}
d.Set("instance_ids", instanceIds)
return nil
})
if err != nil {
return err
}
d.Set("instance_ids", instanceIds)

return nil
}

Expand Down Expand Up @@ -126,15 +132,30 @@ func resourceTencentCloudAsAttachmentDelete(d *schema.ResourceData, meta interfa
asService := AsService{
client: meta.(*TencentCloudClient).apiV3Conn,
}
instanceIds, err := asService.DescribeAutoScalingAttachment(ctx, scalingGroupId)
var (
instanceIds []string
e error
)
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
instanceIds, e = asService.DescribeAutoScalingAttachment(ctx, scalingGroupId)
if e != nil {
return retryError(e)
}
return nil
})
if err != nil {
return err
}

err = asService.DetachInstances(ctx, scalingGroupId, instanceIds)
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
e = asService.DetachInstances(ctx, scalingGroupId, instanceIds)
if e != nil {
return retryError(e)
}
return nil
})
if err != nil {
return err
}

return nil
}
57 changes: 33 additions & 24 deletions tencentcloud/resource_tc_as_lifecycle_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
)
Expand Down Expand Up @@ -157,33 +158,41 @@ func resourceTencentCloudAsLifecycleHookRead(d *schema.ResourceData, meta interf
asService := AsService{
client: meta.(*TencentCloudClient).apiV3Conn,
}
lifecycleHook, err := asService.DescribeLifecycleHookById(ctx, lifecycleHookId)
if err != nil {
return err
}

d.Set("scaling_group_id", *lifecycleHook.AutoScalingGroupId)
d.Set("lifecycle_hook_name", *lifecycleHook.LifecycleHookName)
d.Set("lifecycle_transition", *lifecycleHook.LifecycleTransition)
if lifecycleHook.DefaultResult != nil {
d.Set("default_result", *lifecycleHook.DefaultResult)
}
if lifecycleHook.HeartbeatTimeout != nil {
d.Set("heartbeat_timeout", *lifecycleHook.HeartbeatTimeout)
}
if lifecycleHook.NotificationMetadata != nil {
d.Set("notification_metadata", *lifecycleHook.NotificationMetadata)
}
if lifecycleHook.NotificationTarget != nil {
d.Set("notification_target_type", *lifecycleHook.NotificationTarget.TargetType)
if lifecycleHook.NotificationTarget.QueueName != nil {
d.Set("notification_queue_name", *lifecycleHook.NotificationTarget.QueueName)
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
lifecycleHook, e := asService.DescribeLifecycleHookById(ctx, lifecycleHookId)
if e != nil {
if e.Error() == "lifecycle hook id is not found" {
d.SetId("")
return nil
}
return retryError(e)
}
if lifecycleHook.NotificationTarget.TopicName != nil {
d.Set("notification_topic_name", *lifecycleHook.NotificationTarget.TopicName)
d.Set("scaling_group_id", *lifecycleHook.AutoScalingGroupId)
d.Set("lifecycle_hook_name", *lifecycleHook.LifecycleHookName)
d.Set("lifecycle_transition", *lifecycleHook.LifecycleTransition)
if lifecycleHook.DefaultResult != nil {
d.Set("default_result", *lifecycleHook.DefaultResult)
}
if lifecycleHook.HeartbeatTimeout != nil {
d.Set("heartbeat_timeout", *lifecycleHook.HeartbeatTimeout)
}
if lifecycleHook.NotificationMetadata != nil {
d.Set("notification_metadata", *lifecycleHook.NotificationMetadata)
}
if lifecycleHook.NotificationTarget != nil {
d.Set("notification_target_type", *lifecycleHook.NotificationTarget.TargetType)
if lifecycleHook.NotificationTarget.QueueName != nil {
d.Set("notification_queue_name", *lifecycleHook.NotificationTarget.QueueName)
}
if lifecycleHook.NotificationTarget.TopicName != nil {
d.Set("notification_topic_name", *lifecycleHook.NotificationTarget.TopicName)
}
}
return nil
})
if err != nil {
return err
}

return nil
}

Expand Down
24 changes: 17 additions & 7 deletions tencentcloud/resource_tc_as_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Example Usage
```hcl
resource "tencentcloud_as_notification" "as_notification" {
scaling_group_id = "sg-12af45"
notification_type = ["SCALE_OUT_FAILED", "SCALE_IN_SUCCESSFUL", "SCALE_IN_FAILED", "REPLACE_UNHEALTHY_INSTANCE_FAILED"]
notification_types = ["SCALE_OUT_FAILED", "SCALE_IN_SUCCESSFUL", "SCALE_IN_FAILED", "REPLACE_UNHEALTHY_INSTANCE_FAILED"]
notification_user_group_ids = ["76955"]
}
```
Expand All @@ -18,6 +18,7 @@ import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
)
Expand Down Expand Up @@ -102,15 +103,24 @@ func resourceTencentCloudAsNotificationRead(d *schema.ResourceData, meta interfa
asService := AsService{
client: meta.(*TencentCloudClient).apiV3Conn,
}
notification, err := asService.DescribeNotificationById(ctx, notificationId)
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
notification, e := asService.DescribeNotificationById(ctx, notificationId)
if e != nil {
if e.Error() == "notification id is not found" {
d.SetId("")
return nil
}
return retryError(e)
}

d.Set("scaling_group_id", *notification.AutoScalingGroupId)
d.Set("notification_type", flattenStringList(notification.NotificationTypes))
d.Set("notification_user_group_ids", flattenStringList(notification.NotificationUserGroupIds))
return nil
})
if err != nil {
return err
}

d.Set("scaling_group_id", *notification.AutoScalingGroupId)
d.Set("notification_type", flattenStringList(notification.NotificationTypes))
d.Set("notification_user_group_ids", flattenStringList(notification.NotificationUserGroupIds))

return nil
}

Expand Down
49 changes: 29 additions & 20 deletions tencentcloud/resource_tc_as_scaling_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
)
Expand Down Expand Up @@ -369,29 +370,37 @@ func resourceTencentCloudAsScalingConfigRead(d *schema.ResourceData, meta interf
asService := AsService{
client: meta.(*TencentCloudClient).apiV3Conn,
}
config, err := asService.DescribeLaunchConfigurationById(ctx, configurationId)
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
config, e := asService.DescribeLaunchConfigurationById(ctx, configurationId)
if e != nil {
if e.Error() == "configuration id is not found" {
d.SetId("")
return nil
}
return retryError(e)
}
d.Set("configuration_name", *config.LaunchConfigurationName)
d.Set("status", *config.LaunchConfigurationStatus)
d.Set("image_id", *config.ImageId)
d.Set("project_id", *config.ProjectId)
d.Set("instance_types", flattenStringList(config.InstanceTypes))
d.Set("system_disk_type", *config.SystemDisk.DiskType)
d.Set("system_disk_size", *config.SystemDisk.DiskSize)
d.Set("data_disk", flattenDataDiskMappings(config.DataDisks))
d.Set("internet_charge_type", *config.InternetAccessible.InternetChargeType)
d.Set("internet_max_bandwidth_out", *config.InternetAccessible.InternetMaxBandwidthOut)
d.Set("public_ip_assigned", *config.InternetAccessible.PublicIpAssigned)
d.Set("login_settings.key_ids", flattenStringList(config.LoginSettings.KeyIds))
d.Set("security_group_ids", flattenStringList(config.SecurityGroupIds))
d.Set("enhanced_security_service", *config.EnhancedService.SecurityService.Enabled)
d.Set("enhanced_monitor_service", *config.EnhancedService.MonitorService.Enabled)
d.Set("user_data", pointerToString(config.UserData))
d.Set("instance_tags", flattenInstanceTagsMapping(config.InstanceTags))
return nil
})
if err != nil {
return err
}

d.Set("configuration_name", *config.LaunchConfigurationName)
d.Set("status", *config.LaunchConfigurationStatus)
d.Set("image_id", *config.ImageId)
d.Set("project_id", *config.ProjectId)
d.Set("instance_types", flattenStringList(config.InstanceTypes))
d.Set("system_disk_type", *config.SystemDisk.DiskType)
d.Set("system_disk_size", *config.SystemDisk.DiskSize)
d.Set("data_disk", flattenDataDiskMappings(config.DataDisks))
d.Set("internet_charge_type", *config.InternetAccessible.InternetChargeType)
d.Set("internet_max_bandwidth_out", *config.InternetAccessible.InternetMaxBandwidthOut)
d.Set("public_ip_assigned", *config.InternetAccessible.PublicIpAssigned)
d.Set("login_settings.key_ids", flattenStringList(config.LoginSettings.KeyIds))
d.Set("security_group_ids", flattenStringList(config.SecurityGroupIds))
d.Set("enhanced_security_service", *config.EnhancedService.SecurityService.Enabled)
d.Set("enhanced_monitor_service", *config.EnhancedService.MonitorService.Enabled)
d.Set("user_data", pointerToString(config.UserData))
d.Set("instance_tags", flattenInstanceTagsMapping(config.InstanceTags))

return nil
}

Expand Down
44 changes: 26 additions & 18 deletions tencentcloud/resource_tc_as_scaling_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
)
Expand Down Expand Up @@ -171,29 +172,36 @@ func resourceTencentCloudAsScalingPolicyRead(d *schema.ResourceData, meta interf
asService := AsService{
client: meta.(*TencentCloudClient).apiV3Conn,
}
scalingPolicy, err := asService.DescribeScalingPolicyById(ctx, scalingPolicyId)
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
scalingPolicy, e := asService.DescribeScalingPolicyById(ctx, scalingPolicyId)
if e != nil {
if e.Error() == "scaling policy id is not found" {
d.SetId("")
return nil
}
return retryError(e)
}
d.Set("scaling_group_id", *scalingPolicy.AutoScalingGroupId)
d.Set("policy_name", *scalingPolicy.ScalingPolicyName)
d.Set("adjustment_type", *scalingPolicy.AdjustmentType)
d.Set("adjustment_value", *scalingPolicy.AdjustmentValue)
d.Set("comparison_operator", *scalingPolicy.MetricAlarm.ComparisonOperator)
d.Set("metric_name", *scalingPolicy.MetricAlarm.MetricName)
d.Set("threshold", *scalingPolicy.MetricAlarm.Threshold)
d.Set("period", *scalingPolicy.MetricAlarm.Period)
d.Set("continuous_time", *scalingPolicy.MetricAlarm.ContinuousTime)
d.Set("statistic", *scalingPolicy.MetricAlarm.Statistic)
d.Set("cooldown", *scalingPolicy.Cooldown)
if scalingPolicy.NotificationUserGroupIds != nil {
d.Set("notification_user_group_ids", flattenStringList(scalingPolicy.NotificationUserGroupIds))
}
return nil
})
if err != nil {
return err
}

d.Set("scaling_group_id", *scalingPolicy.AutoScalingGroupId)
d.Set("policy_name", *scalingPolicy.ScalingPolicyName)
d.Set("adjustment_type", *scalingPolicy.AdjustmentType)
d.Set("adjustment_value", *scalingPolicy.AdjustmentValue)
d.Set("comparison_operator", *scalingPolicy.MetricAlarm.ComparisonOperator)
d.Set("metric_name", *scalingPolicy.MetricAlarm.MetricName)
d.Set("threshold", *scalingPolicy.MetricAlarm.Threshold)
d.Set("period", *scalingPolicy.MetricAlarm.Period)
d.Set("continuous_time", *scalingPolicy.MetricAlarm.ContinuousTime)
d.Set("statistic", *scalingPolicy.MetricAlarm.Statistic)
d.Set("cooldown", *scalingPolicy.Cooldown)
if scalingPolicy.NotificationUserGroupIds != nil {
d.Set("notification_user_group_ids", flattenStringList(scalingPolicy.NotificationUserGroupIds))
}

return nil
}

func resourceTencentCloudAsScalingPolicyUpdate(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_as_scaling_policy.update")()

Expand Down
45 changes: 29 additions & 16 deletions tencentcloud/resource_tc_as_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
)

func resourceTencentCloudAsSchedule() *schema.Resource {
Expand Down Expand Up @@ -137,25 +139,36 @@ func resourceTencentCloudAsScheduleRead(d *schema.ResourceData, meta interface{}
asService := AsService{
client: meta.(*TencentCloudClient).apiV3Conn,
}
scheduledAction, err := asService.DescribeScheduledActionById(ctx, scheduledActionId)
if err != nil {
return err
}
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
scheduledAction, e := asService.DescribeScheduledActionById(ctx, scheduledActionId)
if e != nil {
if sdkErr, ok := e.(*errors.TencentCloudSDKError); ok {
if sdkErr.Code == AsScheduleNotFound {
d.SetId("")
return nil
}
}
return retryError(e)
}

d.Set("scaling_group_id", *scheduledAction.AutoScalingGroupId)
d.Set("schedule_action_name", *scheduledAction.ScheduledActionName)
d.Set("max_size", *scheduledAction.MaxSize)
d.Set("min_size", *scheduledAction.MinSize)
d.Set("desired_capacity", *scheduledAction.DesiredCapacity)
d.Set("start_time", *scheduledAction.StartTime)
d.Set("scaling_group_id", *scheduledAction.AutoScalingGroupId)
d.Set("schedule_action_name", *scheduledAction.ScheduledActionName)
d.Set("max_size", *scheduledAction.MaxSize)
d.Set("min_size", *scheduledAction.MinSize)
d.Set("desired_capacity", *scheduledAction.DesiredCapacity)
d.Set("start_time", *scheduledAction.StartTime)

if scheduledAction.EndTime != nil {
d.Set("end_time", *scheduledAction.EndTime)
}
if scheduledAction.Recurrence != nil {
d.Set("recurrence", *scheduledAction.Recurrence)
if scheduledAction.EndTime != nil {
d.Set("end_time", *scheduledAction.EndTime)
}
if scheduledAction.Recurrence != nil {
d.Set("recurrence", *scheduledAction.Recurrence)
}
return nil
})
if err != nil {
return err
}

return nil
}

Expand Down
Loading