-
Notifications
You must be signed in to change notification settings - Fork 9
/
resource_volcengine_volume_attach.go
102 lines (92 loc) · 3.07 KB
/
resource_volcengine_volume_attach.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package volume_attach
import (
"fmt"
"time"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
ve "github.com/volcengine/terraform-provider-volcengine/common"
)
/*
Import
VolumeAttach can be imported using the id, e.g.
```
$ terraform import volcengine_volume_attach.default vol-abc12345:i-abc12345
```
*/
func ResourceVolcengineVolumeAttach() *schema.Resource {
return &schema.Resource{
Create: resourceVolcengineVolumeAttachCreate,
Read: resourceVolcengineVolumeAttachRead,
Update: resourceVolcengineVolumeAttachUpdate,
Delete: resourceVolcengineVolumeAttachDelete,
Importer: &schema.ResourceImporter{
State: importVolumeAttach,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(2 * time.Minute),
Delete: schema.DefaultTimeout(2 * time.Minute),
},
Schema: map[string]*schema.Schema{
"volume_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The Id of Volume.",
},
"instance_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The Id of Instance.",
},
"delete_with_instance": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Delete Volume with Attached Instance." +
"It is not recommended to use this field. If used, please ensure that the value of this field is consistent with the value of `delete_with_instance` in volcengine_volume.",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of Volume.",
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "Creation time of Volume.",
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "Update time of Volume.",
},
},
}
}
func resourceVolcengineVolumeAttachCreate(d *schema.ResourceData, meta interface{}) (err error) {
volumeAttachService := NewVolumeAttachService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Create(volumeAttachService, d, ResourceVolcengineVolumeAttach())
if err != nil {
return fmt.Errorf("error on attach volume %q, %w", d.Id(), err)
}
return resourceVolcengineVolumeAttachRead(d, meta)
}
func resourceVolcengineVolumeAttachRead(d *schema.ResourceData, meta interface{}) (err error) {
volumeAttachService := NewVolumeAttachService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Read(volumeAttachService, d, ResourceVolcengineVolumeAttach())
if err != nil {
return fmt.Errorf("error on reading volume %q, %w", d.Id(), err)
}
return err
}
func resourceVolcengineVolumeAttachUpdate(d *schema.ResourceData, meta interface{}) (err error) {
return resourceVolcengineVolumeAttachRead(d, meta)
}
func resourceVolcengineVolumeAttachDelete(d *schema.ResourceData, meta interface{}) (err error) {
volumeAttachService := NewVolumeAttachService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Delete(volumeAttachService, d, ResourceVolcengineVolumeAttach())
if err != nil {
return fmt.Errorf("error on detach volume %q, %w", d.Id(), err)
}
return err
}