Skip to content

Commit 7bcb280

Browse files
authored
fix: redis - support no-auth access (#769)
* fix: redis - support no-auth access * fix: auth desc * add no-auth create validation
1 parent 6d04cd6 commit 7bcb280

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

tencentcloud/resource_tc_redis_instance.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,16 @@ func resourceTencentCloudRedisInstance() *schema.Resource {
154154
},
155155
"password": {
156156
Type: schema.TypeString,
157-
Required: true,
157+
Optional: true,
158158
Sensitive: true,
159159
ValidateFunc: validateMysqlPassword,
160-
Description: "Password for a Redis user, which should be 8 to 16 characters.",
160+
Description: "Password for a Redis user, which should be 8 to 16 characters. NOTE: Only `no_auth=true` specified can make password empty.",
161+
},
162+
"no_auth": {
163+
Type: schema.TypeBool,
164+
Optional: true,
165+
ForceNew: true,
166+
Description: "Indicates whether the redis instance support no-auth access. NOTE: Only available in private cloud environment.",
161167
},
162168
"mem_size": {
163169
Type: schema.TypeInt,
@@ -267,6 +273,7 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf
267273
redisShardNum := d.Get("redis_shard_num").(int)
268274
redisReplicasNum := d.Get("redis_replicas_num").(int)
269275
password := d.Get("password").(string)
276+
noAuth := d.Get("no_auth").(bool)
270277
memSize := d.Get("mem_size").(int)
271278
vpcId := d.Get("vpc_id").(string)
272279
subnetId := d.Get("subnet_id").(string)
@@ -288,6 +295,14 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf
288295
return fmt.Errorf("`type_id` and `type` set one item and only one item")
289296
}
290297

298+
if password == "" && !noAuth {
299+
return fmt.Errorf("`password` must not be empty unless `no_auth` is `true`")
300+
}
301+
302+
if noAuth && (vpcId == "" || subnetId == "") {
303+
return fmt.Errorf("cannot set `no_auth=true` if `vpc_id` and `subnet_id` is empty")
304+
}
305+
291306
for id, name := range REDIS_NAMES {
292307
if redisType == name {
293308
typeId = id
@@ -401,6 +416,7 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf
401416
chargeTypeID,
402417
chargePeriod,
403418
nodeInfo,
419+
noAuth,
404420
)
405421

406422
if err != nil {
@@ -519,6 +535,12 @@ func resourceTencentCloudRedisInstanceRead(d *schema.ResourceData, meta interfac
519535
_ = d.Set("port", info.Port)
520536
_ = d.Set("ip", info.WanIp)
521537
_ = d.Set("create_time", info.Createtime)
538+
539+
// only true or user explicit declared will set for import case.
540+
if _, ok := d.GetOk("no_auth"); ok || *info.NoAuth {
541+
_ = d.Set("no_auth", info.NoAuth)
542+
}
543+
522544
if d.Get("vpc_id").(string) != "" {
523545
securityGroups, err := service.DescribeInstanceSecurityGroup(ctx, d.Id())
524546
if err != nil {

tencentcloud/service_tencentcloud_redis.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,12 @@ func (me *RedisService) CreateInstances(ctx context.Context,
244244
memSize, projectId, port int64,
245245
securityGroups []string,
246246
redisShardNum,
247-
redisReplicasNum int, chargeTypeID int64, chargePeriod uint64, nodeInfo []*redis.RedisNodeInfo) (instanceIds []*string, errRet error) {
247+
redisReplicasNum int,
248+
chargeTypeID int64,
249+
chargePeriod uint64,
250+
nodeInfo []*redis.RedisNodeInfo,
251+
noAuth bool,
252+
) (instanceIds []*string, errRet error) {
248253

249254
logId := getLogId(ctx)
250255
request := redis.NewCreateInstancesRequest()
@@ -316,6 +321,10 @@ func (me *RedisService) CreateInstances(ctx context.Context,
316321
request.NodeSet = nodeInfo
317322
}
318323

324+
if noAuth {
325+
request.NoAuth = &noAuth
326+
}
327+
319328
ratelimit.Check(request.GetAction())
320329
response, err := me.client.UseRedisClient().CreateInstances(request)
321330
if err != nil {

website/docs/r/redis_instance.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ The following arguments are supported:
6969

7070
* `availability_zone` - (Required, ForceNew) The available zone ID of an instance to be created, please refer to `tencentcloud_redis_zone_config.list`.
7171
* `mem_size` - (Required) The memory volume of an available instance(in MB), please refer to `tencentcloud_redis_zone_config.list[zone].mem_sizes`. When redis is standard type, it represents total memory size of the instance; when Redis is cluster type, it represents memory size of per sharding.
72-
* `password` - (Required) Password for a Redis user, which should be 8 to 16 characters.
7372
* `charge_type` - (Optional, ForceNew) The charge type of instance. Valid values: `PREPAID` and `POSTPAID`. Default value is `POSTPAID`. Note: TencentCloud International only supports `POSTPAID`. Caution that update operation on this field will delete old instances and create new with new charge type.
7473
* `force_delete` - (Optional) Indicate whether to delete Redis instance directly or not. Default is false. If set true, the instance will be deleted instead of staying recycle bin. Note: only works for `PREPAID` instance.
7574
* `name` - (Optional) Instance name.
75+
* `no_auth` - (Optional, ForceNew) Indicates whether the redis instance support no-auth access. NOTE: Only available in private cloud environment.
76+
* `password` - (Optional) Password for a Redis user, which should be 8 to 16 characters. NOTE: Only `no_auth=true` specified can make password empty.
7677
* `port` - (Optional, ForceNew) The port used to access a redis instance. The default value is 6379. And this value can't be changed after creation, or the Redis instance will be recreated.
7778
* `prepaid_period` - (Optional) The tenancy (time unit is month) of the prepaid instance, NOTE: it only works when charge_type is set to `PREPAID`. Valid values are `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `24`, `36`.
7879
* `project_id` - (Optional) Specifies which project the instance should belong to.

0 commit comments

Comments
 (0)