Skip to content

Commit 58f4127

Browse files
committed
add
1 parent 61ad762 commit 58f4127

File tree

5 files changed

+58
-39
lines changed

5 files changed

+58
-39
lines changed

tencentcloud/provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ TencentDB for Redis(crs)
946946
tencentcloud_redis_security_group_attachment
947947
tencentcloud_redis_connection_config
948948
tencentcloud_redis_log_delivery
949+
tencentcloud_redis_param
949950

950951
Serverless Cloud Function(SCF)
951952
Data Source

tencentcloud/services/crs/resource_tc_redis_param.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,25 @@ func resourceTencentCloudRedisParamCreate(d *schema.ResourceData, meta interface
4545
defer tccommon.InconsistentCheck(d, meta)()
4646

4747
var (
48+
logId = tccommon.GetLogId(tccommon.ContextNil)
49+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
50+
service = RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
4851
instanceId string
4952
)
53+
5054
if v, ok := d.GetOk("instance_id"); ok {
5155
instanceId = v.(string)
5256
}
5357

58+
resp, err := service.DescribeRedisInstanceById(ctx, instanceId)
59+
if err != nil {
60+
return err
61+
}
62+
63+
if resp == nil || resp.InstanceId != nil || *resp.InstanceId != instanceId {
64+
return fmt.Errorf("Illegal `instance_id`")
65+
}
66+
5467
d.SetId(instanceId)
5568

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

63-
logId := tccommon.GetLogId(tccommon.ContextNil)
64-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
65-
66-
service := RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
67-
68-
instanceId := d.Id()
76+
var (
77+
logId = tccommon.GetLogId(tccommon.ContextNil)
78+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
79+
service = RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
80+
instanceId = d.Id()
81+
)
6982

7083
param, err := service.DescribeRedisParamById(ctx, instanceId)
7184
if err != nil {
@@ -88,6 +101,7 @@ func resourceTencentCloudRedisParamRead(d *schema.ResourceData, meta interface{}
88101
} else {
89102
instanceParamsMap = param
90103
}
104+
91105
_ = d.Set("instance_params", instanceParamsMap)
92106

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

100-
logId := tccommon.GetLogId(tccommon.ContextNil)
101-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
114+
var (
115+
logId = tccommon.GetLogId(tccommon.ContextNil)
116+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
117+
service = RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
118+
instanceId = d.Id()
119+
)
102120

103121
request := redis.NewModifyInstanceParamsRequest()
104122
response := redis.NewModifyInstanceParamsResponse()
105-
106-
instanceId := d.Id()
107123
request.InstanceId = &instanceId
108-
109124
if v, ok := d.GetOk("instance_params"); ok {
110-
service := RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
111125
param, err := service.DescribeRedisParamById(ctx, instanceId)
112126
if err != nil && len(param) == 0 {
113127
return fmt.Errorf("[ERROR] resource `RedisParam` [%s] not found, please check if it has been deleted.\n", d.Id())
114128
}
129+
115130
for k, v := range v.(map[string]interface{}) {
116131
if value, ok := param[k]; ok {
117132
if value != v {
@@ -137,16 +152,16 @@ func resourceTencentCloudRedisParamUpdate(d *schema.ResourceData, meta interface
137152
} else {
138153
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
139154
}
155+
140156
response = result
141157
return nil
142158
})
159+
143160
if err != nil {
144161
log.Printf("[CRITAL]%s update redis param failed, reason:%+v", logId, err)
145162
return err
146163
}
147164

148-
service := RedisService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
149-
150165
taskId := *response.Response.TaskId
151166
err = resource.Retry(6*tccommon.ReadRetryTimeout, func() *resource.RetryError {
152167
ok, err := service.DescribeTaskInfo(ctx, instanceId, taskId)

tencentcloud/services/crs/resource_tc_redis_param.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ Provides a resource to create a redis param
33
Example Usage
44

55
```hcl
6-
resource "tencentcloud_redis_param" "param" {
7-
instance_id = "crs-c1nl9rpv"
8-
instance_params = {
9-
"cluster-node-timeout" = "15000"
10-
"disable-command-list" = "\"\""
11-
"hash-max-ziplist-entries" = "512"
12-
"hash-max-ziplist-value" = "64"
13-
"hz" = "10"
14-
"lazyfree-lazy-eviction" = "yes"
15-
"lazyfree-lazy-expire" = "yes"
16-
"lazyfree-lazy-server-del" = "yes"
17-
"maxmemory-policy" = "noeviction"
18-
"notify-keyspace-events" = "\"\""
19-
"proxy-slowlog-log-slower-than" = "500"
20-
"replica-lazy-flush" = "yes"
21-
"sentineauth" = "no"
22-
"set-max-intset-entries" = "512"
23-
"slowlog-log-slower-than" = "10"
24-
"timeout" = "31536000"
25-
"zset-max-ziplist-entries" = "128"
26-
"zset-max-ziplist-value" = "64"
27-
}
6+
resource "tencentcloud_redis_param" "example" {
7+
instance_id = "crs-c1nl9rpv"
8+
instance_params = {
9+
"cluster-node-timeout" = "15000"
10+
"disable-command-list" = "\"\""
11+
"hash-max-ziplist-entries" = "512"
12+
"hash-max-ziplist-value" = "64"
13+
"hz" = "10"
14+
"lazyfree-lazy-eviction" = "yes"
15+
"lazyfree-lazy-expire" = "yes"
16+
"lazyfree-lazy-server-del" = "yes"
17+
"maxmemory-policy" = "noeviction"
18+
"notify-keyspace-events" = "\"\""
19+
"proxy-slowlog-log-slower-than" = "500"
20+
"replica-lazy-flush" = "yes"
21+
"sentineauth" = "no"
22+
"set-max-intset-entries" = "512"
23+
"slowlog-log-slower-than" = "10"
24+
"timeout" = "31536000"
25+
"zset-max-ziplist-entries" = "128"
26+
"zset-max-ziplist-value" = "64"
27+
}
2828
}
2929
```
3030

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

3535
```
36-
terraform import tencentcloud_redis_param.param crs-c1nl9rpv
36+
terraform import tencentcloud_redis_param.example crs-c1nl9rpv
3737
```

website/docs/r/redis_param.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Provides a resource to create a redis param
1414
## Example Usage
1515

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

6161
```
62-
terraform import tencentcloud_redis_param.param crs-c1nl9rpv
62+
terraform import tencentcloud_redis_param.example crs-c1nl9rpv
6363
```
6464

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6112,6 +6112,9 @@
61126112
<li>
61136113
<a href="/docs/providers/tencentcloud/r/redis_maintenance_window.html">tencentcloud_redis_maintenance_window</a>
61146114
</li>
6115+
<li>
6116+
<a href="/docs/providers/tencentcloud/r/redis_param.html">tencentcloud_redis_param</a>
6117+
</li>
61156118
<li>
61166119
<a href="/docs/providers/tencentcloud/r/redis_param_template.html">tencentcloud_redis_param_template</a>
61176120
</li>

0 commit comments

Comments
 (0)