Skip to content

Commit 50fc6ff

Browse files
gitmknanonymous
andauthored
feat: mysql datasource (#1670)
* feat: mysql datasource * feat: add mysql datasource changelog --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent 50da107 commit 50fc6ff

22 files changed

+2056
-0
lines changed

.changelog/1670.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
```release-note:new-data-source
2+
tencentcloud_mysql_backup_overview
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_mysql_backup_summaries
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_mysql_bin_log
11+
```
12+
13+
```release-note:new-data-source
14+
tencentcloud_mysql_binlog_backup_overview
15+
```
16+
17+
```release-note:new-data-source
18+
tencentcloud_mysql_clone_list
19+
```
20+
21+
```release-note:new-data-source
22+
tencentcloud_mysql_data_backup_overview
23+
```
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
Use this data source to query detailed information of mysql backup_overview
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_mysql_backup_overview" "backup_overview" {
8+
product = "mysql"
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
19+
cdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb/v20170320"
20+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
21+
)
22+
23+
func dataSourceTencentCloudMysqlBackupOverview() *schema.Resource {
24+
return &schema.Resource{
25+
Read: dataSourceTencentCloudMysqlBackupOverviewRead,
26+
Schema: map[string]*schema.Schema{
27+
"product": {
28+
Required: true,
29+
Type: schema.TypeString,
30+
Description: "The type of cloud database product to be queried, currently only supports `mysql`.",
31+
},
32+
33+
"backup_count": {
34+
Computed: true,
35+
Type: schema.TypeInt,
36+
Description: "The total number of user backups in the current region (including data backups and log backups).",
37+
},
38+
39+
"backup_volume": {
40+
Computed: true,
41+
Type: schema.TypeInt,
42+
Description: "The total backup capacity of the user in the current region.",
43+
},
44+
45+
"billing_volume": {
46+
Computed: true,
47+
Type: schema.TypeInt,
48+
Description: "The billable capacity of the user&amp;#39;s backup in the current region, that is, the part that exceeds the gifted capacity.",
49+
},
50+
51+
"free_volume": {
52+
Computed: true,
53+
Type: schema.TypeInt,
54+
Description: "The free backup capacity obtained by the user in the current region.",
55+
},
56+
57+
"remote_backup_volume": {
58+
Computed: true,
59+
Type: schema.TypeInt,
60+
Description: "The total capacity of off-site backup of the user in the current region. Note: This field may return null, indicating that no valid value can be obtained.",
61+
},
62+
63+
"backup_archive_volume": {
64+
Computed: true,
65+
Type: schema.TypeInt,
66+
Description: "Archive backup capacity, including data backup and log backup. Note: This field may return null, indicating that no valid value can be obtained.",
67+
},
68+
69+
"backup_standby_volume": {
70+
Computed: true,
71+
Type: schema.TypeInt,
72+
Description: "Standard storage backup capacity, including data backup and log backup. Note: This field may return null, indicating that no valid value can be obtained.",
73+
},
74+
75+
"result_output_file": {
76+
Type: schema.TypeString,
77+
Optional: true,
78+
Description: "Used to save results.",
79+
},
80+
},
81+
}
82+
}
83+
84+
func dataSourceTencentCloudMysqlBackupOverviewRead(d *schema.ResourceData, meta interface{}) error {
85+
defer logElapsed("data_source.tencentcloud_mysql_backup_overview.read")()
86+
defer inconsistentCheck(d, meta)()
87+
88+
logId := getLogId(contextNil)
89+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
90+
91+
product := ""
92+
paramMap := make(map[string]interface{})
93+
if v, ok := d.GetOk("product"); ok {
94+
product = v.(string)
95+
paramMap["Product"] = helper.String(v.(string))
96+
}
97+
98+
var backupCount *cdb.DescribeBackupOverviewResponseParams
99+
service := MysqlService{client: meta.(*TencentCloudClient).apiV3Conn}
100+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
101+
result, e := service.DescribeMysqlBackupOverviewByFilter(ctx, paramMap)
102+
if e != nil {
103+
return retryError(e)
104+
}
105+
backupCount = result
106+
return nil
107+
})
108+
if err != nil {
109+
return err
110+
}
111+
112+
if backupCount.BackupCount != nil {
113+
_ = d.Set("backup_count", backupCount.BackupCount)
114+
}
115+
116+
if backupCount.BackupVolume != nil {
117+
_ = d.Set("backup_volume", backupCount.BackupVolume)
118+
}
119+
120+
if backupCount.BillingVolume != nil {
121+
_ = d.Set("billing_volume", backupCount.BillingVolume)
122+
}
123+
124+
if backupCount.FreeVolume != nil {
125+
_ = d.Set("free_volume", backupCount.FreeVolume)
126+
}
127+
128+
if backupCount.RemoteBackupVolume != nil {
129+
_ = d.Set("remote_backup_volume", backupCount.RemoteBackupVolume)
130+
}
131+
132+
if backupCount.BackupArchiveVolume != nil {
133+
_ = d.Set("backup_archive_volume", backupCount.BackupArchiveVolume)
134+
}
135+
136+
if backupCount.BackupStandbyVolume != nil {
137+
_ = d.Set("backup_standby_volume", backupCount.BackupStandbyVolume)
138+
}
139+
140+
d.SetId(helper.DataResourceIdsHash([]string{product}))
141+
output, ok := d.GetOk("result_output_file")
142+
if ok && output.(string) != "" {
143+
if e := writeToFile(output.(string), backupCount); e != nil {
144+
return e
145+
}
146+
}
147+
return nil
148+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudMysqlBackupOverviewDataSource_basic -v
10+
func TestAccTencentCloudMysqlBackupOverviewDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccPreCheck(t)
15+
},
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccMysqlBackupOverviewDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_mysql_backup_overview.backup_overview"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_backup_overview.backup_overview", "backup_archive_volume"),
23+
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_backup_overview.backup_overview", "backup_count"),
24+
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_backup_overview.backup_overview", "backup_standby_volume"),
25+
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_backup_overview.backup_overview", "backup_volume"),
26+
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_backup_overview.backup_overview", "billing_volume"),
27+
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_backup_overview.backup_overview", "free_volume"),
28+
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_backup_overview.backup_overview", "product"),
29+
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_backup_overview.backup_overview", "remote_backup_volume"),
30+
),
31+
},
32+
},
33+
})
34+
}
35+
36+
const testAccMysqlBackupOverviewDataSource = `
37+
38+
data "tencentcloud_mysql_backup_overview" "backup_overview" {
39+
product = "mysql"
40+
}
41+
42+
`

0 commit comments

Comments
 (0)