Skip to content

Commit 00a8928

Browse files
authored
redis support change sg (#1336)
* redis support change sg * update changelog
1 parent 9e3e62b commit 00a8928

File tree

7 files changed

+26
-13
lines changed

7 files changed

+26
-13
lines changed

.changelog/1328.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
```release-note:enhancement
2-
resource/tencentcloud_tcm_mesh: support service mash creating/updating
3-
resource/tencentcloud_tcm_cluster_attachment: support for service mesh binding/unbinding of clusters
1+
```release-note:new-resource
2+
tencentcloud_tcm_mesh
3+
tencentcloud_tcm_cluster_attachment
44
```

.changelog/1336.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_redis_instance: support update `security_groups`
3+
```

tencentcloud/basic_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ variable "subnet_id" {
256256
default = "` + defaultSubnetId + `"
257257
}
258258
259+
variable "sg_id" {
260+
default = "` + defaultSecurityGroup + `"
261+
}
262+
259263
variable "subnet_cidr" {
260264
default = "` + defaultSubnetCidr + `"
261265
}

tencentcloud/resource_tc_redis_instance.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ func resourceTencentCloudRedisInstance() *schema.Resource {
196196
"security_groups": {
197197
Type: schema.TypeSet,
198198
Optional: true,
199-
ForceNew: true,
200199
Elem: &schema.Schema{Type: schema.TypeString},
201200
Set: func(v interface{}) int {
202201
return hashcode.String(v.(string))
@@ -681,7 +680,6 @@ func resourceTencentCloudRedisInstanceUpdate(d *schema.ResourceData, meta interf
681680
if err != nil {
682681
return err
683682
}
684-
d.SetPartial("name")
685683
}
686684

687685
// MemSize, ShardNum and ReplicaNum can only change one for each upgrade invoke
@@ -796,7 +794,6 @@ func resourceTencentCloudRedisInstanceUpdate(d *schema.ResourceData, meta interf
796794
log.Printf("[CRITAL]%s redis change password fail, reason:%s\n", logId, err.Error())
797795
return err
798796
}
799-
d.SetPartial("password")
800797
}
801798

802799
if d.HasChange("params_template_id") {
@@ -822,7 +819,18 @@ func resourceTencentCloudRedisInstanceUpdate(d *schema.ResourceData, meta interf
822819
if err != nil {
823820
return err
824821
}
825-
d.SetPartial("project_id")
822+
}
823+
824+
if d.HasChanges("security_groups") {
825+
sgs := d.Get("security_groups").(*schema.Set).List()
826+
var sgIds []*string
827+
for _, sgId := range sgs {
828+
sgIds = append(sgIds, helper.String(sgId.(string)))
829+
}
830+
err := redisService.ModifyDBInstanceSecurityGroups(ctx, "redis", d.Id(), sgIds)
831+
if err != nil {
832+
return err
833+
}
826834
}
827835

828836
if d.HasChange("tags") {
@@ -833,8 +841,6 @@ func resourceTencentCloudRedisInstanceUpdate(d *schema.ResourceData, meta interf
833841
if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil {
834842
return err
835843
}
836-
837-
d.SetPartial("tags")
838844
}
839845

840846
d.Partial(false)

tencentcloud/resource_tc_redis_instance_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func TestAccTencentCloudRedisInstanceBasic(t *testing.T) {
191191
),
192192
},
193193
{
194-
Config: testAccRedisInstanceUpdateMemSizeAndPassword(),
194+
Config: testAccRedisInstanceUpdateMemSizeAndPasswordAndSg(),
195195
Check: resource.ComposeAggregateTestCheckFunc(
196196
testAccTencentCloudRedisInstanceExists("tencentcloud_redis_instance.redis_instance_test"),
197197
resource.TestCheckResourceAttrSet("tencentcloud_redis_instance.redis_instance_test", "ip"),
@@ -549,7 +549,7 @@ resource "tencentcloud_redis_instance" "redis_instance_test" {
549549
}`
550550
}
551551

552-
func testAccRedisInstanceUpdateMemSizeAndPassword() string {
552+
func testAccRedisInstanceUpdateMemSizeAndPasswordAndSg() string {
553553
return defaultVpcVariable + `
554554
resource "tencentcloud_redis_instance" "redis_instance_test" {
555555
availability_zone = "ap-guangzhou-3"
@@ -562,6 +562,7 @@ resource "tencentcloud_redis_instance" "redis_instance_test" {
562562
redis_replicas_num = 1
563563
vpc_id = var.vpc_id
564564
subnet_id = var.subnet_id
565+
security_groups = [var.sg_id]
565566
566567
tags = {
567568
"abc" = "abc"

tencentcloud/service_tencentcloud_redis.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ func (me *RedisService) ModifyInstanceProjectId(ctx context.Context, redisId str
598598
}
599599
errRet = err
600600
return
601-
602601
}
603602

604603
func (me *RedisService) DescribeInstanceSecurityGroup(ctx context.Context, redisId string) (sg []string, errRet error) {

website/docs/r/redis_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The following arguments are supported:
8787
* `redis_shard_num` - (Optional, Int) The number of instance shard, default is 1. This is not required for standalone and master slave versions.
8888
* `replica_zone_ids` - (Optional, List: [`Int`]) ID of replica nodes available zone. This is not required for standalone and master slave versions. NOTE: Removing some of the same zone of replicas (e.g. removing 100001 of [100001, 100001, 100002]) will pick the first hit to remove.
8989
* `replicas_read_only` - (Optional, Bool) Whether copy read-only is supported, Redis 2.8 Standard Edition and CKV Standard Edition do not support replica read-only, turn on replica read-only, the instance will automatically read and write separate, write requests are routed to the primary node, read requests are routed to the replica node, if you need to open replica read-only, the recommended number of replicas >=2.
90-
* `security_groups` - (Optional, Set: [`String`], ForceNew) ID of security group. If both vpc_id and subnet_id are not set, this argument should not be set either.
90+
* `security_groups` - (Optional, Set: [`String`]) ID of security group. If both vpc_id and subnet_id are not set, this argument should not be set either.
9191
* `subnet_id` - (Optional, String, ForceNew) Specifies which subnet the instance should belong to.
9292
* `tags` - (Optional, Map) Instance tags.
9393
* `type_id` - (Optional, Int, ForceNew) Instance type. Available values reference data source `tencentcloud_redis_zone_config` or [document](https://intl.cloud.tencent.com/document/product/239/32069).

0 commit comments

Comments
 (0)