Skip to content

Commit 88a9383

Browse files
authored
cancel validate required db pwd (#1066)
1 parent d336410 commit 88a9383

9 files changed

+34
-17
lines changed

tencentcloud/extension_mongodb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func TencentMongodbBasicInfo() map[string]*schema.Schema {
146146
},
147147
"password": {
148148
Type: schema.TypeString,
149-
Required: true,
149+
Optional: true,
150150
Sensitive: true,
151151
Description: "Password of this Mongodb account.",
152152
},

tencentcloud/resource_tc_mongodb_instance.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ func mongodbAllInstanceReqSet(requestInter interface{}, d *schema.ResourceData)
9393
mongoVersionInterface = d.Get("engine_version").(string)
9494
zoneInterface = d.Get("available_zone").(string)
9595
machine = d.Get("machine_type").(string)
96-
password = d.Get("password").(string)
9796
instanceType = MONGO_INSTANCE_TYPE_FORMAL
9897
projectId = d.Get("project_id").(int)
98+
password string
9999
)
100100

101101
if machine == MONGODB_MACHINE_TYPE_GIO {
@@ -104,6 +104,12 @@ func mongodbAllInstanceReqSet(requestInter interface{}, d *schema.ResourceData)
104104
machine = MONGODB_MACHINE_TYPE_HIO10G
105105
}
106106

107+
if v, ok := d.GetOk("password"); ok && v.(string) != "" {
108+
password = v.(string)
109+
} else {
110+
return fmt.Errorf("`password` cannot be empty when creating")
111+
}
112+
107113
getType := reflect.TypeOf(requestInter)
108114
value := reflect.ValueOf(requestInter).Elem()
109115

tencentcloud/resource_tc_mongodb_instance_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,18 @@ func TestAccTencentCloudMongodbInstanceResourcePostPaid(t *testing.T) {
111111
func TestAccTencentCloudNeedFixMongodbInstanceResourcePrepaid(t *testing.T) {
112112
// Avoid to set Parallel to make sure EnvVar secure
113113
resource.Test(t, resource.TestCase{
114-
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
115-
Providers: testAccProviders,
116-
CheckDestroy: testAccCheckMongodbInstanceDestroy,
114+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
115+
Providers: testAccProviders,
117116
Steps: []resource.TestStep{
118117
{
119118
Config: testAccMongodbInstancePrepaid,
120119
Check: resource.ComposeTestCheckFunc(
121120
testAccCheckMongodbInstanceExists("tencentcloud_mongodb_instance.mongodb_prepaid"),
122121
resource.TestCheckResourceAttr("tencentcloud_mongodb_instance.mongodb_prepaid", "instance_name", "tf-mongodb-test-prepaid"),
123-
resource.TestCheckResourceAttrSet("tencentcloud_mongodb_instance.mongodb", "memory"),
124-
resource.TestCheckResourceAttrSet("tencentcloud_mongodb_instance.mongodb", "volume"),
125-
resource.TestCheckResourceAttrSet("tencentcloud_mongodb_instance.mongodb", "engine_version"),
126-
resource.TestCheckResourceAttrSet("tencentcloud_mongodb_instance.mongodb", "machine_type"),
122+
resource.TestCheckResourceAttrSet("tencentcloud_mongodb_instance.mongodb_prepaid", "memory"),
123+
resource.TestCheckResourceAttrSet("tencentcloud_mongodb_instance.mongodb_prepaid", "volume"),
124+
resource.TestCheckResourceAttrSet("tencentcloud_mongodb_instance.mongodb_prepaid", "engine_version"),
125+
resource.TestCheckResourceAttrSet("tencentcloud_mongodb_instance.mongodb_prepaid", "machine_type"),
127126
resource.TestCheckResourceAttr("tencentcloud_mongodb_instance.mongodb_prepaid", "available_zone", "ap-guangzhou-6"),
128127
resource.TestCheckResourceAttr("tencentcloud_mongodb_instance.mongodb_prepaid", "project_id", "0"),
129128
resource.TestCheckResourceAttrSet("tencentcloud_mongodb_instance.mongodb_prepaid", "status"),
@@ -147,10 +146,10 @@ func TestAccTencentCloudNeedFixMongodbInstanceResourcePrepaid(t *testing.T) {
147146
),
148147
},
149148
{
150-
ResourceName: "tencentcloud_mongodb_instance.mongodb",
149+
ResourceName: "tencentcloud_mongodb_instance.mongodb_prepaid",
151150
ImportState: true,
152151
ImportStateVerify: true,
153-
ImportStateVerifyIgnore: []string{"security_groups", "password", "auto_renew_flag"},
152+
ImportStateVerifyIgnore: []string{"security_groups", "password", "auto_renew_flag", "prepaid_period"},
154153
},
155154
},
156155
})

tencentcloud/resource_tc_mongodb_sharding_instance.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ func mongodbAllShardingInstanceReqSet(requestInter interface{}, d *schema.Resour
9696
projectId = d.Get("project_id").(int)
9797
)
9898

99+
if v, ok := d.GetOk("password"); ok && v.(string) != "" {
100+
password = v.(string)
101+
} else {
102+
return fmt.Errorf("`password` cannot be empty when creating")
103+
}
104+
99105
if machine == MONGODB_MACHINE_TYPE_GIO {
100106
machine = MONGODB_MACHINE_TYPE_HIO
101107
} else if machine == MONGODB_MACHINE_TYPE_TGIO {

tencentcloud/resource_tc_mongodb_standby_instance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestAccTencentCloudNeedFixMongodbStandbyInstanceResource(t *testing.T) {
5252
ResourceName: "tencentcloud_mongodb_standby_instance.mongodb",
5353
ImportState: true,
5454
ImportStateVerify: true,
55-
ImportStateVerifyIgnore: []string{"security_groups", "auto_renew_flag"},
55+
ImportStateVerifyIgnore: []string{"security_groups", "auto_renew_flag", "password"},
5656
},
5757
{
5858
Config: testAccMongodbStandbyInstancePrepaid,

tencentcloud/resource_tc_mysql_instance.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func resourceTencentCloudMysqlInstance() *schema.Resource {
260260
},
261261
"root_password": {
262262
Type: schema.TypeString,
263-
Required: true,
263+
Optional: true,
264264
Sensitive: true,
265265
ValidateFunc: validateMysqlPassword,
266266
Description: "Password of root account. This parameter can be specified when you purchase master instances, but it should be ignored when you purchase read-only instances or disaster recovery instances.",
@@ -666,12 +666,18 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf
666666
// Initialize mysql instance
667667
var (
668668
version = d.Get("engine_version").(string)
669-
password = d.Get("root_password").(string)
670669
charset = d.Get("parameters.character_set_server").(string)
671670
lowercase = d.Get("parameters.lower_case_table_names").(string)
671+
password string
672672
vPort int
673673
)
674674

675+
if v, ok := d.GetOk("root_password"); ok && v.(string) != "" {
676+
password = v.(string)
677+
} else {
678+
return fmt.Errorf("`root_password` cannot be empty when creating")
679+
}
680+
675681
// 8.0 does not support lower_case_table_names modified, skip this params
676682
if version == "8.0" {
677683
lowercase = ""

website/docs/r/mongodb_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ The following arguments are supported:
3737
* `instance_name` - (Required) Name of the Mongodb instance.
3838
* `machine_type` - (Required, ForceNew) Type of Mongodb instance, and available values include `HIO`(or `GIO` which will be deprecated, represents high IO) and `HIO10G`(or `TGIO` which will be deprecated, represents 10-gigabit high IO).
3939
* `memory` - (Required) Memory size. The minimum value is 2, and unit is GB. Memory and volume must be upgraded or degraded simultaneously.
40-
* `password` - (Required) Password of this Mongodb account.
4140
* `volume` - (Required) Disk size. The minimum value is 25, and unit is GB. Memory and volume must be upgraded or degraded simultaneously.
4241
* `auto_renew_flag` - (Optional) Auto renew flag. Valid values are `0`(NOTIFY_AND_MANUAL_RENEW), `1`(NOTIFY_AND_AUTO_RENEW) and `2`(DISABLE_NOTIFY_AND_MANUAL_RENEW). Default value is `0`. Note: only works for PREPAID instance. Only supports`0` and `1` for creation.
4342
* `charge_type` - (Optional, ForceNew) The charge type of instance. Valid values are `PREPAID` and `POSTPAID_BY_HOUR`. Default value is `POSTPAID_BY_HOUR`. Note: TencentCloud International only supports `POSTPAID_BY_HOUR`. Caution that update operation on this field will delete old instances and create new one with new charge type.
43+
* `password` - (Optional) Password of this Mongodb account.
4444
* `prepaid_period` - (Optional) The tenancy (time unit is month) of the prepaid instance. Valid values are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36. NOTE: it only works when charge_type is set to `PREPAID`.
4545
* `project_id` - (Optional) ID of the project which the instance belongs.
4646
* `security_groups` - (Optional, ForceNew) ID of the security group. NOTE: for instance which `engine_version` is `MONGO_40_WT`, `security_groups` is not supported.

website/docs/r/mongodb_sharding_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ The following arguments are supported:
4040
* `machine_type` - (Required, ForceNew) Type of Mongodb instance, and available values include `HIO`(or `GIO` which will be deprecated, represents high IO) and `HIO10G`(or `TGIO` which will be deprecated, represents 10-gigabit high IO).
4141
* `memory` - (Required) Memory size. The minimum value is 2, and unit is GB. Memory and volume must be upgraded or degraded simultaneously.
4242
* `nodes_per_shard` - (Required, ForceNew) Number of nodes per shard, at least 3(one master and two slaves).
43-
* `password` - (Required) Password of this Mongodb account.
4443
* `shard_quantity` - (Required, ForceNew) Number of sharding.
4544
* `volume` - (Required) Disk size. The minimum value is 25, and unit is GB. Memory and volume must be upgraded or degraded simultaneously.
4645
* `auto_renew_flag` - (Optional) Auto renew flag. Valid values are `0`(NOTIFY_AND_MANUAL_RENEW), `1`(NOTIFY_AND_AUTO_RENEW) and `2`(DISABLE_NOTIFY_AND_MANUAL_RENEW). Default value is `0`. Note: only works for PREPAID instance. Only supports`0` and `1` for creation.
4746
* `charge_type` - (Optional, ForceNew) The charge type of instance. Valid values are `PREPAID` and `POSTPAID_BY_HOUR`. Default value is `POSTPAID_BY_HOUR`. Note: TencentCloud International only supports `POSTPAID_BY_HOUR`. Caution that update operation on this field will delete old instances and create new one with new charge type.
47+
* `password` - (Optional) Password of this Mongodb account.
4848
* `prepaid_period` - (Optional) The tenancy (time unit is month) of the prepaid instance. Valid values are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36. NOTE: it only works when charge_type is set to `PREPAID`.
4949
* `project_id` - (Optional) ID of the project which the instance belongs.
5050
* `security_groups` - (Optional, ForceNew) ID of the security group. NOTE: for instance which `engine_version` is `MONGO_40_WT`, `security_groups` is not supported.

website/docs/r/mysql_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ The following arguments are supported:
5151

5252
* `instance_name` - (Required) The name of a mysql instance.
5353
* `mem_size` - (Required) Memory size (in MB).
54-
* `root_password` - (Required) Password of root account. This parameter can be specified when you purchase master instances, but it should be ignored when you purchase read-only instances or disaster recovery instances.
5554
* `volume_size` - (Required) Disk size (in GB).
5655
* `auto_renew_flag` - (Optional) Auto renew flag. NOTES: Only supported prepaid instance.
5756
* `availability_zone` - (Optional, ForceNew) Indicates which availability zone will be used.
@@ -69,6 +68,7 @@ The following arguments are supported:
6968
* `period` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Please use `prepaid_period` instead. Period of instance. NOTES: Only supported prepaid instance.
7069
* `prepaid_period` - (Optional) Period of instance. NOTES: Only supported prepaid instance.
7170
* `project_id` - (Optional) Project ID, default value is 0.
71+
* `root_password` - (Optional) Password of root account. This parameter can be specified when you purchase master instances, but it should be ignored when you purchase read-only instances or disaster recovery instances.
7272
* `second_slave_zone` - (Optional, ForceNew) Zone information about second slave instance.
7373
* `security_groups` - (Optional) Security groups to use.
7474
* `slave_deploy_mode` - (Optional, ForceNew) Availability zone deployment method. Available values: 0 - Single availability zone; 1 - Multiple availability zones.

0 commit comments

Comments
 (0)