Skip to content
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

fix(crs): [137091743] tencentcloud_redis_param fix the problem caused by illegal parameter instance_id #3104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .changelog/3104.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_redis_param: fix the problem caused by illegal parameter `instance_id`
```
1 change: 1 addition & 0 deletions tencentcloud/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ TencentDB for Redis(crs)
tencentcloud_redis_security_group_attachment
tencentcloud_redis_connection_config
tencentcloud_redis_log_delivery
tencentcloud_redis_param

Serverless Cloud Function(SCF)
Data Source
Expand Down
43 changes: 29 additions & 14 deletions tencentcloud/services/crs/resource_tc_redis_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,25 @@ func resourceTencentCloudRedisParamCreate(d *schema.ResourceData, meta interface
defer tccommon.InconsistentCheck(d, meta)()

var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
instanceId string
)

if v, ok := d.GetOk("instance_id"); ok {
instanceId = v.(string)
}

resp, err := service.DescribeRedisInstanceById(ctx, instanceId)
if err != nil {
return err
}

if resp == nil || resp.InstanceId != nil || *resp.InstanceId != instanceId {
return fmt.Errorf("Illegal `instance_id`")
}

d.SetId(instanceId)

return resourceTencentCloudRedisParamUpdate(d, meta)
Expand All @@ -60,12 +73,12 @@ func resourceTencentCloudRedisParamRead(d *schema.ResourceData, meta interface{}
defer tccommon.LogElapsed("resource.tencentcloud_redis_param.read")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)

service := RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}

instanceId := d.Id()
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
instanceId = d.Id()
)

param, err := service.DescribeRedisParamById(ctx, instanceId)
if err != nil {
Expand All @@ -88,6 +101,7 @@ func resourceTencentCloudRedisParamRead(d *schema.ResourceData, meta interface{}
} else {
instanceParamsMap = param
}

_ = d.Set("instance_params", instanceParamsMap)

return nil
Expand All @@ -97,21 +111,22 @@ func resourceTencentCloudRedisParamUpdate(d *schema.ResourceData, meta interface
defer tccommon.LogElapsed("resource.tencentcloud_redis_param.update")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
instanceId = d.Id()
)

request := redis.NewModifyInstanceParamsRequest()
response := redis.NewModifyInstanceParamsResponse()

instanceId := d.Id()
request.InstanceId = &instanceId

if v, ok := d.GetOk("instance_params"); ok {
service := RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
param, err := service.DescribeRedisParamById(ctx, instanceId)
if err != nil && len(param) == 0 {
return fmt.Errorf("[ERROR] resource `RedisParam` [%s] not found, please check if it has been deleted.\n", d.Id())
}

for k, v := range v.(map[string]interface{}) {
if value, ok := param[k]; ok {
if value != v {
Expand All @@ -137,16 +152,16 @@ func resourceTencentCloudRedisParamUpdate(d *schema.ResourceData, meta interface
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}

response = result
return nil
})

if err != nil {
log.Printf("[CRITAL]%s update redis param failed, reason:%+v", logId, err)
return err
}

service := RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}

taskId := *response.Response.TaskId
err = resource.Retry(6*tccommon.ReadRetryTimeout, func() *resource.RetryError {
ok, err := service.DescribeTaskInfo(ctx, instanceId, taskId)
Expand Down
46 changes: 23 additions & 23 deletions tencentcloud/services/crs/resource_tc_redis_param.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ Provides a resource to create a redis param
Example Usage

```hcl
resource "tencentcloud_redis_param" "param" {
instance_id = "crs-c1nl9rpv"
instance_params = {
"cluster-node-timeout" = "15000"
"disable-command-list" = "\"\""
"hash-max-ziplist-entries" = "512"
"hash-max-ziplist-value" = "64"
"hz" = "10"
"lazyfree-lazy-eviction" = "yes"
"lazyfree-lazy-expire" = "yes"
"lazyfree-lazy-server-del" = "yes"
"maxmemory-policy" = "noeviction"
"notify-keyspace-events" = "\"\""
"proxy-slowlog-log-slower-than" = "500"
"replica-lazy-flush" = "yes"
"sentineauth" = "no"
"set-max-intset-entries" = "512"
"slowlog-log-slower-than" = "10"
"timeout" = "31536000"
"zset-max-ziplist-entries" = "128"
"zset-max-ziplist-value" = "64"
}
resource "tencentcloud_redis_param" "example" {
instance_id = "crs-c1nl9rpv"
instance_params = {
"cluster-node-timeout" = "15000"
"disable-command-list" = "\"\""
"hash-max-ziplist-entries" = "512"
"hash-max-ziplist-value" = "64"
"hz" = "10"
"lazyfree-lazy-eviction" = "yes"
"lazyfree-lazy-expire" = "yes"
"lazyfree-lazy-server-del" = "yes"
"maxmemory-policy" = "noeviction"
"notify-keyspace-events" = "\"\""
"proxy-slowlog-log-slower-than" = "500"
"replica-lazy-flush" = "yes"
"sentineauth" = "no"
"set-max-intset-entries" = "512"
"slowlog-log-slower-than" = "10"
"timeout" = "31536000"
"zset-max-ziplist-entries" = "128"
"zset-max-ziplist-value" = "64"
}
}
```

Expand All @@ -33,5 +33,5 @@ Import
redis param can be imported using the instanceId, e.g.

```
terraform import tencentcloud_redis_param.param crs-c1nl9rpv
terraform import tencentcloud_redis_param.example crs-c1nl9rpv
```
4 changes: 2 additions & 2 deletions website/docs/r/redis_param.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Provides a resource to create a redis param
## Example Usage

```hcl
resource "tencentcloud_redis_param" "param" {
resource "tencentcloud_redis_param" "example" {
instance_id = "crs-c1nl9rpv"
instance_params = {
"cluster-node-timeout" = "15000"
Expand Down Expand Up @@ -59,6 +59,6 @@ In addition to all arguments above, the following attributes are exported:
redis param can be imported using the instanceId, e.g.

```
terraform import tencentcloud_redis_param.param crs-c1nl9rpv
terraform import tencentcloud_redis_param.example crs-c1nl9rpv
```

3 changes: 3 additions & 0 deletions website/tencentcloud.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6112,6 +6112,9 @@
<li>
<a href="/docs/providers/tencentcloud/r/redis_maintenance_window.html">tencentcloud_redis_maintenance_window</a>
</li>
<li>
<a href="/docs/providers/tencentcloud/r/redis_param.html">tencentcloud_redis_param</a>
</li>
<li>
<a href="/docs/providers/tencentcloud/r/redis_param_template.html">tencentcloud_redis_param_template</a>
</li>
Expand Down
Loading