Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions tencentcloud/resource_tc_mysql_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
},
},
}
}

Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 7 additions & 2 deletions tencentcloud/resource_tc_mysql_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/mysql_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```