Skip to content

Commit f1f977c

Browse files
authored
Merge pull request #2125 from tencentcloudstack/feate/cynosdb-readonly-vpc
feat: support vpc
2 parents 9c2c255 + 952cdbe commit f1f977c

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

.changelog/2125.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_cynosdb_readonly_instance: Support `vpc_id`, `subnet_id` fields.
3+
```

tencentcloud/resource_tc_cynosdb_readonly_instance.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ func resourceTencentCloudCynosdbReadonlyInstance() *schema.Resource {
6767
Default: false,
6868
Description: "Indicate whether to delete readonly instance directly or not. Default is false. If set true, instance will be deleted instead of staying recycle bin. Note: works for both `PREPAID` and `POSTPAID_BY_HOUR` cluster.",
6969
},
70+
"vpc_id": {
71+
Type: schema.TypeString,
72+
Optional: true,
73+
Computed: true,
74+
Description: "ID of the VPC.",
75+
},
76+
"subnet_id": {
77+
Type: schema.TypeString,
78+
Optional: true,
79+
Computed: true,
80+
Description: "ID of the subnet within this VPC.",
81+
},
7082
}
7183
basic := TencentCynosdbInstanceBaseInfo()
7284
delete(basic, "instance_id")
@@ -108,6 +120,14 @@ func resourceTencentCloudCynosdbReadonlyInstanceCreate(d *schema.ResourceData, m
108120
request.Memory = helper.IntInt64(d.Get("instance_memory_size").(int))
109121
request.ReadOnlyCount = helper.Int64(1)
110122

123+
// vpc
124+
if v, ok := d.GetOk("vpc_id"); ok {
125+
request.VpcId = helper.String(v.(string))
126+
}
127+
if v, ok := d.GetOk("subnet_id"); ok {
128+
request.SubnetId = helper.String(v.(string))
129+
}
130+
111131
var response *cynosdb.AddInstancesResponse
112132
var err error
113133
err = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
@@ -175,6 +195,12 @@ func resourceTencentCloudCynosdbReadonlyInstanceRead(d *schema.ResourceData, met
175195
_ = d.Set("instance_name", instance.InstanceName)
176196
_ = d.Set("instance_status", instance.Status)
177197
_ = d.Set("instance_storage_size", instance.Storage)
198+
if instance.VpcId != nil {
199+
_ = d.Set("vpc_id", instance.VpcId)
200+
}
201+
if instance.SubnetId != nil {
202+
_ = d.Set("subnet_id", instance.SubnetId)
203+
}
178204

179205
maintain, err := cynosdbService.DescribeMaintainPeriod(ctx, id)
180206
if err != nil {
@@ -245,6 +271,10 @@ func resourceTencentCloudCynosdbReadonlyInstanceUpdate(d *schema.ResourceData, m
245271

246272
}
247273

274+
if d.HasChange("vpc_id") || d.HasChange("subnet_id") {
275+
return fmt.Errorf("`vpc_id`, `subnet_id` do not support change now.")
276+
}
277+
248278
d.Partial(false)
249279

250280
return resourceTencentCloudCynosdbReadonlyInstanceRead(d, meta)

tencentcloud/resource_tc_cynosdb_readonly_instance_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func TestAccTencentCloudCynosdbReadonlyInstanceResource(t *testing.T) {
3030
resource.TestCheckResourceAttrSet("tencentcloud_cynosdb_readonly_instance.foo", "instance_memory_size"),
3131
resource.TestCheckResourceAttrSet("tencentcloud_cynosdb_readonly_instance.foo", "instance_status"),
3232
resource.TestCheckResourceAttrSet("tencentcloud_cynosdb_readonly_instance.foo", "instance_storage_size"),
33+
resource.TestCheckResourceAttr("tencentcloud_cynosdb_readonly_instance.foo", "vpc_id", "vpc-4owdpnwr"),
34+
resource.TestCheckResourceAttr("tencentcloud_cynosdb_readonly_instance.foo", "subnet_id", "subnet-m4qpx38w"),
3335
),
3436
},
3537
{
@@ -102,7 +104,13 @@ func testAccCheckCynosdbReadonlyInstanceExists(n string) resource.TestCheckFunc
102104
}
103105
}
104106

105-
const testAccCynosdbReadonlyInstance = testAccCynosdbBasic + `
107+
const readonlyInstanceVar = `
108+
variable "readonly_subnet" {
109+
default = "subnet-m4qpx38w"
110+
}
111+
`
112+
113+
const testAccCynosdbReadonlyInstance = testAccCynosdbBasic + readonlyInstanceVar + `
106114
resource "tencentcloud_cynosdb_cluster" "foo" {
107115
available_zone = var.availability_zone
108116
vpc_id = var.my_vpc
@@ -148,6 +156,8 @@ resource "tencentcloud_cynosdb_readonly_instance" "foo" {
148156
force_delete = true
149157
instance_cpu_core = 1
150158
instance_memory_size = 2
159+
vpc_id = var.my_vpc
160+
subnet_id = var.readonly_subnet
151161
152162
instance_maintain_duration = 3600
153163
instance_maintain_start_time = 10800

tencentcloud/service_tencentcloud_cynosdb.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,13 @@ func (me *CynosdbService) DescribeInstanceById(ctx context.Context, instanceId s
365365
}
366366

367367
instanceInfo = response.Response.Detail
368+
369+
if instanceInfo.VpcId != nil {
370+
instanceInfo.VpcId = instances[0].VpcId
371+
}
372+
if instanceInfo.SubnetId != nil {
373+
instanceInfo.SubnetId = instances[0].SubnetId
374+
}
368375
return
369376
}
370377

website/docs/r/cynosdb_readonly_instance.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ The following arguments are supported:
4747
* `instance_maintain_start_time` - (Optional, Int) Offset time from 00:00, unit in second. For example, 03:00am should be `10800`. `10800` by default.
4848
* `instance_maintain_weekdays` - (Optional, Set: [`String`]) Weekdays for maintenance. `["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]` by default.
4949
* `instance_memory_size` - (Optional, Int) Memory capacity of read-write type instance, unit in GB. Required while creating normal cluster. Note: modification of this field will take effect immediately, if want to upgrade on maintenance window, please upgrade from console.
50+
* `subnet_id` - (Optional, String) ID of the subnet within this VPC.
51+
* `vpc_id` - (Optional, String) ID of the VPC.
5052

5153
## Attributes Reference
5254

0 commit comments

Comments
 (0)