|
| 1 | +/* |
| 2 | +Provides a resource to create a lighthouse apply_disk_backup |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +resource "tencentcloud_lighthouse_apply_disk_backup" "apply_disk_backup" { |
| 8 | + disk_id = "lhdisk-xxxxxx" |
| 9 | + disk_backup_id = "lhbak-xxxxxx" |
| 10 | +} |
| 11 | +``` |
| 12 | +*/ |
| 13 | +package tencentcloud |
| 14 | + |
| 15 | +import ( |
| 16 | + "log" |
| 17 | + "time" |
| 18 | + |
| 19 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 20 | + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 21 | + lighthouse "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse/v20200324" |
| 22 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 23 | +) |
| 24 | + |
| 25 | +func resourceTencentCloudLighthouseApplyDiskBackup() *schema.Resource { |
| 26 | + return &schema.Resource{ |
| 27 | + Create: resourceTencentCloudLighthouseApplyDiskBackupCreate, |
| 28 | + Read: resourceTencentCloudLighthouseApplyDiskBackupRead, |
| 29 | + Delete: resourceTencentCloudLighthouseApplyDiskBackupDelete, |
| 30 | + Schema: map[string]*schema.Schema{ |
| 31 | + "disk_id": { |
| 32 | + Required: true, |
| 33 | + ForceNew: true, |
| 34 | + Type: schema.TypeString, |
| 35 | + Description: "Disk ID.", |
| 36 | + }, |
| 37 | + |
| 38 | + "disk_backup_id": { |
| 39 | + Required: true, |
| 40 | + ForceNew: true, |
| 41 | + Type: schema.TypeString, |
| 42 | + Description: "Disk backup ID.", |
| 43 | + }, |
| 44 | + }, |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func resourceTencentCloudLighthouseApplyDiskBackupCreate(d *schema.ResourceData, meta interface{}) error { |
| 49 | + defer logElapsed("resource.tencentcloud_lighthouse_apply_disk_backup.create")() |
| 50 | + defer inconsistentCheck(d, meta)() |
| 51 | + |
| 52 | + logId := getLogId(contextNil) |
| 53 | + |
| 54 | + var ( |
| 55 | + request = lighthouse.NewApplyDiskBackupRequest() |
| 56 | + diskBackupId string |
| 57 | + diskId string |
| 58 | + ) |
| 59 | + if v, ok := d.GetOk("disk_id"); ok { |
| 60 | + diskId = v.(string) |
| 61 | + request.DiskId = helper.String(diskId) |
| 62 | + } |
| 63 | + |
| 64 | + if v, ok := d.GetOk("disk_backup_id"); ok { |
| 65 | + diskBackupId = v.(string) |
| 66 | + request.DiskBackupId = helper.String(diskBackupId) |
| 67 | + } |
| 68 | + |
| 69 | + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { |
| 70 | + result, e := meta.(*TencentCloudClient).apiV3Conn.UseLighthouseClient().ApplyDiskBackup(request) |
| 71 | + if e != nil { |
| 72 | + return retryError(e) |
| 73 | + } else { |
| 74 | + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) |
| 75 | + } |
| 76 | + return nil |
| 77 | + }) |
| 78 | + if err != nil { |
| 79 | + log.Printf("[CRITAL]%s operate lighthouse applyDiskBackup failed, reason:%+v", logId, err) |
| 80 | + return err |
| 81 | + } |
| 82 | + |
| 83 | + d.SetId(diskId + FILED_SP + diskBackupId) |
| 84 | + |
| 85 | + service := LightHouseService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 86 | + |
| 87 | + conf := BuildStateChangeConf([]string{}, []string{"SUCCESS"}, 20*readRetryTimeout, time.Second, service.LighthouseApplyDiskBackupStateRefreshFunc(diskBackupId, []string{})) |
| 88 | + |
| 89 | + if _, e := conf.WaitForState(); e != nil { |
| 90 | + return e |
| 91 | + } |
| 92 | + |
| 93 | + return resourceTencentCloudLighthouseApplyDiskBackupRead(d, meta) |
| 94 | +} |
| 95 | + |
| 96 | +func resourceTencentCloudLighthouseApplyDiskBackupRead(d *schema.ResourceData, meta interface{}) error { |
| 97 | + defer logElapsed("resource.tencentcloud_lighthouse_apply_disk_backup.read")() |
| 98 | + defer inconsistentCheck(d, meta)() |
| 99 | + |
| 100 | + return nil |
| 101 | +} |
| 102 | + |
| 103 | +func resourceTencentCloudLighthouseApplyDiskBackupDelete(d *schema.ResourceData, meta interface{}) error { |
| 104 | + defer logElapsed("resource.tencentcloud_lighthouse_apply_disk_backup.delete")() |
| 105 | + defer inconsistentCheck(d, meta)() |
| 106 | + |
| 107 | + return nil |
| 108 | +} |
0 commit comments