From db698e614131370cdfe2a7617ccb8852b094b799 Mon Sep 17 00:00:00 2001 From: Kagashino Date: Thu, 5 May 2022 15:31:49 +0800 Subject: [PATCH 1/2] feat: mysql - support import --- tencentcloud/resource_tc_mysql_instance.go | 29 ++++++++++++++++--- .../resource_tc_mysql_instance_test.go | 9 ++++-- website/docs/r/mysql_instance.html.markdown | 10 ++++++- .../r/mysql_readonly_instance.html.markdown | 2 +- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/tencentcloud/resource_tc_mysql_instance.go b/tencentcloud/resource_tc_mysql_instance.go index cc078581bb..9ffe59c156 100644 --- a/tencentcloud/resource_tc_mysql_instance.go +++ b/tencentcloud/resource_tc_mysql_instance.go @@ -34,6 +34,15 @@ resource "tencentcloud_mysql_instance" "default" { } } ``` + +Import + +MySQL instance can be imported using the id, e.g. + +``` +$ terraform import tencentcloud_mysql_instance.foo cdb-12345678" +``` + */ package tencentcloud @@ -112,7 +121,7 @@ func TencentMsyqlBasicInfo() map[string]*schema.Schema { Default: 1, ConflictsWith: []string{"pay_type", "period"}, ValidateFunc: validateAllowedIntValue(MYSQL_AVAILABLE_PERIOD), - Description: "Period of instance. NOTES: Only supported prepaid instance.", + Description: "Period of instance. NOTES: Only support prepaid instance.", }, "auto_renew_flag": { Type: schema.TypeInt, @@ -304,8 +313,22 @@ func resourceTencentCloudMysqlInstance() *schema.Resource { Read: resourceTencentCloudMysqlInstanceRead, Update: resourceTencentCloudMysqlInstanceUpdate, Delete: resourceTencentCloudMysqlInstanceDelete, - Schema: specialInfo, + Importer: &schema.ResourceImporter{ + State: func(d *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) { + _ = d.Set("charge_type", MYSQL_CHARGE_TYPE_POSTPAID) + _ = d.Set("prepaid_period", 1) + _ = d.Set("auto_renew_flag", 0) + _ = d.Set("intranet_port", 3306) + _ = d.Set("force_delete", false) + _ = d.Set("internet_service", 0) + _ = d.Set("engine_version", MYSQL_SUPPORTS_ENGINE[len(MYSQL_SUPPORTS_ENGINE)-2]) + _ = d.Set("slave_deploy_mode", 0) + _ = d.Set("slave_sync_mode", 0) + _ = d.Set("project_id", 0) + return []*schema.ResourceData{d}, nil + }, + }, } } @@ -909,13 +932,11 @@ func resourceTencentCloudMysqlInstanceRead(d *schema.ResourceData, meta interfac _ = d.Set("slave_sync_mode", int(*backConfig.Response.ProtectMode)) _ = d.Set("slave_deploy_mode", int(*backConfig.Response.DeployMode)) if backConfig.Response.SlaveConfig != nil && *backConfig.Response.SlaveConfig.Zone != "" { - //if you set ,i set if _, ok := d.GetOk("first_slave_zone"); ok { _ = d.Set("first_slave_zone", *backConfig.Response.SlaveConfig.Zone) } } if backConfig.Response.BackupConfig != nil && *backConfig.Response.BackupConfig.Zone != "" { - //if you set ,i set if _, ok := d.GetOk("second_slave_zone"); ok { _ = d.Set("second_slave_zone", *backConfig.Response.BackupConfig.Zone) } diff --git a/tencentcloud/resource_tc_mysql_instance_test.go b/tencentcloud/resource_tc_mysql_instance_test.go index 7e338307a5..6ad2103c93 100644 --- a/tencentcloud/resource_tc_mysql_instance_test.go +++ b/tencentcloud/resource_tc_mysql_instance_test.go @@ -15,10 +15,9 @@ import ( const TestAccTencentCloudMysqlMasterInstance_availability_zone = "ap-guangzhou-3" const TestAccTencentCloudMysqlInstanceName = "testAccMysql" -const TestAccTencentCloudMysqlInstanceNameVersion1 = "testAccMysql-version1" -const TestAccTencentCloudMysqlInstanceNamePrepaid = "testAccMysqlPrepaid" func init() { + // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_mysql_instance resource.AddTestSweepers("tencentcloud_mysql_instance", &resource.Sweeper{ Name: "tencentcloud_mysql_instance", F: testSweepMySQLInstance, @@ -146,6 +145,12 @@ func TestAccTencentCloudMysqlMasterInstance_basic_and_update(t *testing.T) { resource.TestCheckResourceAttrSet("tencentcloud_mysql_instance.mysql_master", "gtid"), ), }, + { + ResourceName: "tencentcloud_mysql_instance.mysql_master", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"root_password", "prepaid_period", "first_slave_zone", "force_delete"}, + }, // add tag { Config: testAccMysqlMasterInstance_multiTags("master"), diff --git a/website/docs/r/mysql_instance.html.markdown b/website/docs/r/mysql_instance.html.markdown index b8ef386fb0..8dc3d3bd50 100644 --- a/website/docs/r/mysql_instance.html.markdown +++ b/website/docs/r/mysql_instance.html.markdown @@ -65,7 +65,7 @@ The following arguments are supported: * `parameters` - (Optional) List of parameters to use. * `pay_type` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Please use `charge_type` instead. Pay type of instance. Valid values: `0`, `1`. `0`: prepaid, `1`: postpaid. * `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. -* `prepaid_period` - (Optional) Period of instance. NOTES: Only supported prepaid instance. +* `prepaid_period` - (Optional) Period of instance. NOTES: Only support prepaid instance. * `project_id` - (Optional) Project ID, default value is 0. * `second_slave_zone` - (Optional, ForceNew) Zone information about second slave instance. * `security_groups` - (Optional) Security groups to use. @@ -89,3 +89,11 @@ In addition to all arguments above, the following attributes are exported: * `task_status` - Indicates which kind of operations is being executed. +## Import + +MySQL instance can be imported using the id, e.g. + +``` +$ terraform import tencentcloud_mysql_instance.foo cdb-12345678" +``` + diff --git a/website/docs/r/mysql_readonly_instance.html.markdown b/website/docs/r/mysql_readonly_instance.html.markdown index 20e0080fb0..c1dfd95dcd 100644 --- a/website/docs/r/mysql_readonly_instance.html.markdown +++ b/website/docs/r/mysql_readonly_instance.html.markdown @@ -49,7 +49,7 @@ The following arguments are supported: * `master_region` - (Optional, ForceNew) The zone information of the primary instance is required when you purchase a disaster recovery instance. * `pay_type` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Please use `charge_type` instead. Pay type of instance. Valid values: `0`, `1`. `0`: prepaid, `1`: postpaid. * `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. -* `prepaid_period` - (Optional) Period of instance. NOTES: Only supported prepaid instance. +* `prepaid_period` - (Optional) Period of instance. NOTES: Only support prepaid instance. * `security_groups` - (Optional) Security groups to use. * `subnet_id` - (Optional) Private network ID. If `vpc_id` is set, this value is required. * `tags` - (Optional) Instance tags. From 5c3183979554c8ca6841d84df15b739983a28e51 Mon Sep 17 00:00:00 2001 From: Kagashino Date: Tue, 10 May 2022 14:56:53 +0800 Subject: [PATCH 2/2] fix: prepaid desc --- tencentcloud/resource_tc_mysql_instance.go | 2 +- website/docs/r/mysql_instance.html.markdown | 2 +- website/docs/r/mysql_readonly_instance.html.markdown | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tencentcloud/resource_tc_mysql_instance.go b/tencentcloud/resource_tc_mysql_instance.go index 9ffe59c156..f902d065ad 100644 --- a/tencentcloud/resource_tc_mysql_instance.go +++ b/tencentcloud/resource_tc_mysql_instance.go @@ -121,7 +121,7 @@ func TencentMsyqlBasicInfo() map[string]*schema.Schema { Default: 1, ConflictsWith: []string{"pay_type", "period"}, ValidateFunc: validateAllowedIntValue(MYSQL_AVAILABLE_PERIOD), - Description: "Period of instance. NOTES: Only support prepaid instance.", + Description: "Period of instance. NOTES: Only supported prepaid instance.", }, "auto_renew_flag": { Type: schema.TypeInt, diff --git a/website/docs/r/mysql_instance.html.markdown b/website/docs/r/mysql_instance.html.markdown index 8dc3d3bd50..6bcd080528 100644 --- a/website/docs/r/mysql_instance.html.markdown +++ b/website/docs/r/mysql_instance.html.markdown @@ -65,7 +65,7 @@ The following arguments are supported: * `parameters` - (Optional) List of parameters to use. * `pay_type` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Please use `charge_type` instead. Pay type of instance. Valid values: `0`, `1`. `0`: prepaid, `1`: postpaid. * `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. -* `prepaid_period` - (Optional) Period of instance. NOTES: Only support prepaid instance. +* `prepaid_period` - (Optional) Period of instance. NOTES: Only supported prepaid instance. * `project_id` - (Optional) Project ID, default value is 0. * `second_slave_zone` - (Optional, ForceNew) Zone information about second slave instance. * `security_groups` - (Optional) Security groups to use. diff --git a/website/docs/r/mysql_readonly_instance.html.markdown b/website/docs/r/mysql_readonly_instance.html.markdown index c1dfd95dcd..20e0080fb0 100644 --- a/website/docs/r/mysql_readonly_instance.html.markdown +++ b/website/docs/r/mysql_readonly_instance.html.markdown @@ -49,7 +49,7 @@ The following arguments are supported: * `master_region` - (Optional, ForceNew) The zone information of the primary instance is required when you purchase a disaster recovery instance. * `pay_type` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Please use `charge_type` instead. Pay type of instance. Valid values: `0`, `1`. `0`: prepaid, `1`: postpaid. * `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. -* `prepaid_period` - (Optional) Period of instance. NOTES: Only support prepaid instance. +* `prepaid_period` - (Optional) Period of instance. NOTES: Only supported prepaid instance. * `security_groups` - (Optional) Security groups to use. * `subnet_id` - (Optional) Private network ID. If `vpc_id` is set, this value is required. * `tags` - (Optional) Instance tags.