You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `tencentcloud_mongodb_sharding_instance` resource manages MongoDB sharding instances through the `ModifyDBInstanceSpec` API. The vendor SDK (`v20190725`) already supports `AddNodeList` and `RemoveNodeList` fields in the `ModifyDBInstanceSpecRequest` struct. The service layer (`MongodbService.UpgradeInstance`) already has handling code for these params via the `params map[string]interface{}` argument. The only missing piece is exposing these parameters in the Terraform resource schema and wiring them through the update function.
4
+
5
+
## Goals / Non-Goals
6
+
7
+
**Goals:**
8
+
- Add `add_node_list` (TypeList) and `remove_node_list` (TypeList) as Optional schema fields
9
+
- Wire these parameters to the existing `UpgradeInstance` service call in the update path
10
+
- Both fields are Optional and preserve full backward compatibility
11
+
12
+
**Non-Goals:**
13
+
- No changes to Create, Read, or Delete paths
14
+
- No new API calls or service methods
15
+
- No modification to the `UpgradeInstance` service method (it already handles these params)
16
+
17
+
## Decisions
18
+
19
+
1.**Schema field structure**: `add_node_list` uses `TypeList` with `MaxItems: 1` containing sub-fields `role` (Required, string) and `zone` (Required, string). `remove_node_list` uses `TypeList` with sub-fields `role` (Required, string), `node_name` (Required, string), and `zone` (Required, string). This mirrors the SDK struct layout exactly.
20
+
21
+
2.**Update trigger**: When `d.HasChange("add_node_list") || d.HasChange("remove_node_list")`, call the existing `UpgradeInstance` service method with these params in the `params` map. The `UpgradeInstance` method already handles constructing `AddNodeList` and `RemoveNodeList` from params.
22
+
23
+
3.**No state management in Read**: The `add_node_list` and `remove_node_list` parameters represent node addition/removal operations (not persistent state). They are not set back in the Read function. This follows the pattern of action-oriented parameters that drive changes but don't represent current state.
24
+
25
+
## Risks / Trade-offs
26
+
27
+
-**Risk**: After successful node addition/removal, the `d.SetId("")` won't be triggered but `add_node_list`/`remove_node_list` values remain in the Terraform config, causing a perpetual diff on next plan. → **Mitigation**: These fields should be documented as operational parameters that users should remove from config after the operation completes, or we can optionally clear them after successful execution.
28
+
-**Risk**: Adding/removing nodes is a long-running async operation that could timeout. → **Mitigation**: The `UpgradeInstance` service method already handles this via `DescribeDBInstanceDeal` polling with retry logic.
The `tencentcloud_mongodb_sharding_instance` resource currently uses `ModifyDBInstanceSpec` API for scaling memory/volume, but does not expose `AddNodeList` and `RemoveNodeList` parameters that allow users to dynamically add or remove nodes (Mongod nodes, read-only nodes, Mongos nodes) from a sharding instance. This prevents Terraform users from managing node topology changes declaratively.
4
+
5
+
## What Changes
6
+
7
+
- Add `add_node_list` parameter (TypeList) to `tencentcloud_mongodb_sharding_instance` resource, supporting the following sub-fields:
8
+
-`role` (TypeString, Required): Node role to add - `SECONDARY`, `READONLY`, or `MONGOS`
9
+
-`zone` (TypeString, Required): Availability zone for the new node
10
+
- Add `remove_node_list` parameter (TypeList) to `tencentcloud_mongodb_sharding_instance` resource, supporting the following sub-fields:
11
+
-`role` (TypeString, Required): Node role to remove - `SECONDARY`, `READONLY`, or `MONGOS`
12
+
-`node_name` (TypeString, Required): Node ID to remove (e.g., `cmgo-xxxx_0-node-readonly0`)
13
+
- Wire these parameters through the existing `ModifyDBInstanceSpec` API call in the update path
14
+
15
+
## Capabilities
16
+
17
+
### New Capabilities
18
+
-`mongodb-sharding-node-list-management`: Ability to add and remove nodes (Mongod, read-only, Mongos) from a MongoDB sharding instance via `add_node_list` and `remove_node_list` parameters in the `ModifyDBInstanceSpec` API.
19
+
20
+
### Modified Capabilities
21
+
<!-- None - this is purely additive, no existing capability requirements change -->
22
+
23
+
## Impact
24
+
25
+
-**Code**: `tencentcloud/services/mongodb/resource_tc_mongodb_sharding_instance.go` - Add schema definitions and wire parameters in the update function
26
+
-**Code**: `tencentcloud/services/mongodb/resource_tc_mongodb_sharding_instance_test.go` - Add test cases for new parameters
27
+
-**Docs**: `tencentcloud/services/mongodb/resource_tc_mongodb_sharding_instance.md` - Add example and parameter documentation
28
+
-**API**: Uses existing `ModifyDBInstanceSpec` API (already available in vendor SDK `v20190725`)
29
+
-**Backward Compatibility**: Fully backward compatible - both new fields are Optional
### Requirement: User can add nodes to a MongoDB sharding instance
4
+
The `tencentcloud_mongodb_sharding_instance` resource SHALL expose an `add_node_list` parameter that allows users to add nodes (SECONDARY, READONLY, or MONGOS) to an existing sharding instance via the `ModifyDBInstanceSpec` API.
5
+
6
+
#### Scenario: Add a read-only node
7
+
-**WHEN** user specifies `add_node_list` with `role = "READONLY"` and `zone = "ap-guangzhou-2"`
8
+
-**THEN** the provider calls `ModifyDBInstanceSpec` with `AddNodeList` containing the specified role and zone, and waits for the operation to complete
9
+
10
+
#### Scenario: Add multiple node types
11
+
-**WHEN** user specifies `add_node_list` with multiple entries (e.g., one SECONDARY and one READONLY)
12
+
-**THEN** the provider calls `ModifyDBInstanceSpec` with `AddNodeList` containing all specified nodes
13
+
14
+
### Requirement: User can remove nodes from a MongoDB sharding instance
15
+
The `tencentcloud_mongodb_sharding_instance` resource SHALL expose a `remove_node_list` parameter that allows users to remove nodes from an existing sharding instance via the `ModifyDBInstanceSpec` API.
16
+
17
+
#### Scenario: Remove a read-only node by node name
18
+
-**WHEN** user specifies `remove_node_list` with `role = "READONLY"`, `node_name = "cmgo-xxxx_0-node-readonly0"`, and `zone = "ap-guangzhou-2"`
19
+
-**THEN** the provider calls `ModifyDBInstanceSpec` with `RemoveNodeList` containing the specified role, node name, and zone, and waits for the operation to complete
20
+
21
+
### Requirement: Backward compatibility
22
+
The `add_node_list` and `remove_node_list` parameters SHALL both be Optional. Existing Terraform configurations that do not use these parameters SHALL continue to work without any changes.
23
+
24
+
#### Scenario: Existing configuration without new parameters
25
+
-**WHEN** user applies an existing `tencentcloud_mongodb_sharding_instance` configuration that does not include `add_node_list` or `remove_node_list`
26
+
-**THEN** the provider behaves identically to before this change, with no diff or modification
-[x] 1.1 Add `add_node_list` TypeList schema field with sub-fields `role` (Required, TypeString) and `zone` (Required, TypeString) to `ResourceTencentCloudMongodbShardingInstance`
4
+
-[x] 1.2 Add `remove_node_list` TypeList schema field with sub-fields `role` (Required, TypeString), `node_name` (Required, TypeString), and `zone` (Required, TypeString) to `ResourceTencentCloudMongodbShardingInstance`
5
+
6
+
## 2. Update Function Wiring
7
+
8
+
-[x] 2.1 Add change detection for `add_node_list` and `remove_node_list` in `resourceMongodbShardingInstanceUpdate`
9
+
-[x] 2.2 Pass `add_node_list` and `remove_node_list` to the existing `UpgradeInstance` service call via the `params` map
10
+
11
+
## 3. Documentation
12
+
13
+
-[x] 3.1 Update `resource_tc_mongodb_sharding_instance.md` with example usage of `add_node_list` and `remove_node_list`
14
+
15
+
## 4. Validation
16
+
17
+
-[x] 4.1 Verify the code compiles correctly
18
+
-[x] 4.2 Review all generated code for correctness and consistency with existing patterns
0 commit comments