Skip to content

Commit 0ae4026

Browse files
tongyimingmikatong
andauthored
fix(mongodb): [116051613]support mongodb account import (#2536)
* support mongodb account import * add changelog * update unit test name --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent f5c47c8 commit 0ae4026

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

.changelog/2536.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_mongodb_instance_account: support import
3+
```

tencentcloud/services/mongodb/resource_tc_mongodb_instance_account.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func ResourceTencentCloudMongodbInstanceAccount() *schema.Resource {
2424
Read: resourceTencentCloudMongodbInstanceAccountRead,
2525
Update: resourceTencentCloudMongodbInstanceAccountUpdate,
2626
Delete: resourceTencentCloudMongodbInstanceAccountDelete,
27+
Importer: &schema.ResourceImporter{
28+
State: schema.ImportStatePassthrough,
29+
},
2730
Schema: map[string]*schema.Schema{
2831
"instance_id": {
2932
Required: true,
@@ -40,13 +43,15 @@ func ResourceTencentCloudMongodbInstanceAccount() *schema.Resource {
4043
},
4144

4245
"password": {
43-
Required: true,
46+
Optional: true,
47+
Sensitive: true,
4448
Type: schema.TypeString,
4549
Description: "New account password. Password complexity requirements are as follows: character length range [8,32]. Contains at least letters, numbers and special characters (exclamation point!, at@, pound sign #, percent sign %, caret ^, asterisk *, parentheses (), underscore _).",
4650
},
4751

4852
"mongo_user_password": {
49-
Required: true,
53+
Optional: true,
54+
Sensitive: true,
5055
Type: schema.TypeString,
5156
ForceNew: true,
5257
Description: "The password corresponding to the mongouser account. mongouser is the system default account, which is the password set when creating an instance.",

tencentcloud/services/mongodb/resource_tc_mongodb_instance_account_test.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
99
)
1010

11-
func TestAccTencentCloudNeedFixMongodbInstanceAccountResource_basic(t *testing.T) {
11+
func TestAccTencentCloudMongodbInstanceAccountResource_basic(t *testing.T) {
1212
t.Parallel()
1313
resource.Test(t, resource.TestCase{
1414
PreCheck: func() {
@@ -20,22 +20,39 @@ func TestAccTencentCloudNeedFixMongodbInstanceAccountResource_basic(t *testing.T
2020
Config: testAccMongodbInstanceAccount,
2121
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_mongodb_instance_account.instance_account", "id")),
2222
},
23+
{
24+
ResourceName: "tencentcloud_mongodb_instance_account.instance_account",
25+
ImportState: true,
26+
ImportStateVerifyIgnore: []string{"password", "mongo_user_password"},
27+
},
2328
},
2429
})
2530
}
2631

27-
const testAccMongodbInstanceAccount = `
32+
const testAccMongodbInstanceAccount = tcacctest.DefaultMongoDBSpec + `
33+
resource "tencentcloud_mongodb_instance" "mongodb" {
34+
instance_name = "tf-mongodb-test"
35+
memory = local.memory
36+
volume = local.volume
37+
engine_version = local.engine_version
38+
machine_type = local.machine_type
39+
security_groups = [local.security_group_id]
40+
available_zone = "ap-guangzhou-3"
41+
project_id = 0
42+
password = "test1234"
43+
vpc_id = var.vpc_id
44+
subnet_id = var.subnet_id
45+
}
2846
2947
resource "tencentcloud_mongodb_instance_account" "instance_account" {
30-
instance_id = "cmgo-lxaz2c9b"
48+
instance_id = tencentcloud_mongodb_instance.mongodb.id
3149
user_name = "test_account"
32-
password = "xxxxxxxx"
33-
mongo_user_password = "xxxxxxxxx"
50+
password = "test1234"
51+
mongo_user_password = "test1234"
3452
user_desc = "test account"
3553
auth_role {
3654
mask = 0
3755
namespace = "*"
3856
}
3957
}
40-
4158
`

website/docs/r/mongodb_instance_account.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ resource "tencentcloud_mongodb_instance_account" "instance_account" {
3232
The following arguments are supported:
3333

3434
* `instance_id` - (Required, String, ForceNew) Instance ID, the format is: cmgo-9d0p6umb.Same as the instance ID displayed in the cloud database console page.
35-
* `mongo_user_password` - (Required, String, ForceNew) The password corresponding to the mongouser account. mongouser is the system default account, which is the password set when creating an instance.
36-
* `password` - (Required, String) New account password. Password complexity requirements are as follows: character length range [8,32]. Contains at least letters, numbers and special characters (exclamation point!, at@, pound sign #, percent sign %, caret ^, asterisk *, parentheses (), underscore _).
3735
* `user_name` - (Required, String, ForceNew) The new account name. Its format requirements are as follows: character range [1,32]. Characters in the range of [A,Z], [a,z], [1,9] as well as underscore _ and dash - can be input.
3836
* `auth_role` - (Optional, List) The read and write permission information of the account.
37+
* `mongo_user_password` - (Optional, String, ForceNew) The password corresponding to the mongouser account. mongouser is the system default account, which is the password set when creating an instance.
38+
* `password` - (Optional, String) New account password. Password complexity requirements are as follows: character length range [8,32]. Contains at least letters, numbers and special characters (exclamation point!, at@, pound sign #, percent sign %, caret ^, asterisk *, parentheses (), underscore _).
3939
* `user_desc` - (Optional, String) Account remarks.
4040

4141
The `auth_role` object supports the following:

0 commit comments

Comments
 (0)