Skip to content

Commit 829f13a

Browse files
authored
Avoid pass BackupId when from_backup_id is absent (#142)
1 parent 14db8aa commit 829f13a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

ucloud/resource_ucloud_db_instance.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ func resourceUCloudDBInstanceCreate(d *schema.ResourceData, meta interface{}) er
238238
req.DBTypeId = ucloud.String(dbTypeId)
239239
req.BackupCount = ucloud.Int(d.Get("backup_count").(int))
240240
req.InstanceType = ucloud.String(dbTypeCvt.convert(dbType.Type))
241-
req.BackupId = ucloud.Int(d.Get("from_backup_id").(int))
241+
242+
if v, ok := d.GetOk("from_backup_id"); ok {
243+
req.BackupId = ucloud.Int(v.(int))
244+
}
242245

243246
password := fmt.Sprintf("%s%s%s",
244247
acctest.RandStringFromCharSet(5, defaultPasswordStr),

website/docs/r/db_instance.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ Provides a Database instance resource.
1515
## Example Usage
1616

1717
```hcl
18-
# Query availability zone
19-
data "ucloud_zones" "default" {
20-
}
2118
2219
# Create database instance
2320
resource "ucloud_db_instance" "master" {
2421
name = "tf-example-db"
22+
availability_zone = "cn-bj2-05"
2523
instance_storage = 20
2624
instance_type = "mysql-ha-1"
2725
engine = "mysql"
@@ -59,7 +57,9 @@ The following arguments are supported:
5957
* `duration` - (Optional, ForceNew) The duration that you will buy the db instance (Default: `1`). The value is `0` when pay by month and the instance will be valid till the last day of that month. It is not required when `dynamic` (pay by hour).
6058
* `vpc_id` - (Optional, ForceNew) The ID of VPC linked to the database instances.
6159
* `subnet_id` - (Optional, ForceNew) The ID of subnet.
62-
* `from_backup_id` - (Optional, ForceNew) Create the database instance with the content of specified backup.
60+
* `from_backup_id` - (Optional, ForceNew) Create the database instance with the
61+
content of specified backup. The backup id can be retrieved from UDB console
62+
or by using the [`ucloud_db_backups`](https://registry.terraform.io/providers/ucloud/ucloud/latest/docs/data-sources/db_backups) datasource.
6363
* `backup_count` - (Optional, ForceNew) Specifies the number of backup saved per week, it is 7 backups saved per week by default.
6464
* `backup_begin_time` - (Optional) Specifies when the backup starts, measured in hour, it starts at one o'clock of 1, 2, 3, 4 in the morning by default.
6565
* `backup_date` - (Optional) Specifies whether the backup took place from Sunday to Saturday by displaying 7 digits. 0 stands for backup disabled and 1 stands for backup enabled. The rightmost digit specifies whether the backup took place on Sunday, and the digits from right to left specify whether the backup took place from Monday to Saturday, it's mandatory required to backup twice per week at least. such as: digits "1100000" stands for the backup took place on Saturday and Friday.

0 commit comments

Comments
 (0)