-
Notifications
You must be signed in to change notification settings - Fork 131
/
resource_tc_cos_object_copy_operation.go
73 lines (60 loc) · 2.17 KB
/
resource_tc_cos_object_copy_operation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cos
import (
"context"
"log"
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func ResourceTencentCloudCosObjectCopyOperation() *schema.Resource {
return &schema.Resource{
Create: resourceTencentCloudCosObjectCopyOperationCreate,
Read: resourceTencentCloudCosObjectCopyOperationRead,
Delete: resourceTencentCloudCosObjectCopyOperationDelete,
Schema: map[string]*schema.Schema{
"bucket": {
Required: true,
ForceNew: true,
Type: schema.TypeString,
Description: "Bucket.",
},
"key": {
Required: true,
ForceNew: true,
Type: schema.TypeString,
Description: "Object key.",
},
"source_url": {
Required: true,
ForceNew: true,
Type: schema.TypeString,
Description: "Object key.",
},
},
}
}
func resourceTencentCloudCosObjectCopyOperationCreate(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_cos_object_copy_operation.create")()
defer tccommon.InconsistentCheck(d, meta)()
logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
bucket := d.Get("bucket").(string)
key := d.Get("key").(string)
sourceURL := d.Get("source_url").(string)
_, _, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTencentCosClient(bucket).Object.Copy(ctx, key, sourceURL, nil)
if err != nil {
log.Printf("[CRITAL]%s Restore failed, reason:%+v", logId, err)
return err
}
d.SetId(bucket + tccommon.FILED_SP + key)
return resourceTencentCloudCosObjectCopyOperationRead(d, meta)
}
func resourceTencentCloudCosObjectCopyOperationRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_cos_object_copy_operation.read")()
defer tccommon.InconsistentCheck(d, meta)()
return nil
}
func resourceTencentCloudCosObjectCopyOperationDelete(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_cos_object_copy_operation.delete")()
defer tccommon.InconsistentCheck(d, meta)()
return nil
}