-
Notifications
You must be signed in to change notification settings - Fork 10
/
resource_volcengine_cloudfs_file_system.go
208 lines (196 loc) · 7.05 KB
/
resource_volcengine_cloudfs_file_system.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package cloudfs_file_system
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"time"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
ve "github.com/volcengine/terraform-provider-volcengine/common"
)
/*
Import
CloudFileSystem can be imported using the FsName, e.g.
```
$ terraform import volcengine_cloudfs_file_system.default tfname
```
*/
func ResourceVolcengineCloudfsFileSystem() *schema.Resource {
resource := &schema.Resource{
Create: resourceVolcengineCloudfsFileSystemCreate,
Read: resourceVolcengineCloudfsFileSystemRead,
Update: resourceVolcengineCloudfsFileSystemUpdate,
Delete: resourceVolcengineCloudfsFileSystemDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},
Schema: map[string]*schema.Schema{
"fs_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The name of file system.",
},
"zone_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The id of zone.",
},
"cache_plan": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"T2", "T4", "DISABLED"}, false),
Description: "The cache plan. The value can be `DISABLED` or `T2` or `T4`. " +
"When expanding the cache size, the cache plan should remain the same. For data lakes, cache must be enabled.",
},
"cache_capacity_tib": {
Type: schema.TypeInt,
Optional: true,
DiffSuppressFunc: diffCache,
Description: "The capacity of cache. This parameter is required when cache acceleration is enabled.",
},
"subnet_id": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: diffCache,
Description: "The id of subnet. This parameter is required when cache acceleration is enabled.",
},
"security_group_id": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: diffCache,
Description: "The id of security group. This parameter is required when cache acceleration is enabled.",
},
"vpc_route_enabled": {
Type: schema.TypeBool,
Optional: true,
DiffSuppressFunc: diffCache,
Description: "Whether enable all vpc route.",
},
"mode": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"HDFS_MODE", "ACC_MODE"}, false),
Description: "The mode of file system. The value can be `HDFS_MODE` or `ACC_MODE`.",
},
"tos_bucket": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "The tos bucket. When importing ACC_MODE resources, this attribute will not be imported.",
},
"tos_prefix": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "The tos prefix. Must not start with /, but must end with /, such as prefix/. When it is empty, it means the root path. " +
"When importing ACC_MODE resources, this attribute will not be imported.",
},
"tos_account_id": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: "When a data lake scenario instance chooses to associate a bucket under another account, you need to set the ID of the account. " +
"When importing resources, this attribute will not be imported.",
},
"tos_ak": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "The tos ak. When the data lake scenario chooses to associate buckets under other accounts, need to set the Access Key ID of the account. " +
"When importing resources, this attribute will not be imported.",
},
"tos_sk": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "The tos sk. When the data lake scenario chooses to associate buckets under other accounts, need to set the Secret Access Key of the account. " +
"When importing resources, this attribute will not be imported.",
},
"read_only": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: "Whether the Namespace created automatically when mounting the TOS Bucket is read-only. " +
"When importing resources, this attribute will not be imported. " +
"If this attribute is set, please use lifecycle and ignore_changes ignore changes in fields.",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of file system.",
},
"created_time": {
Type: schema.TypeString,
Computed: true,
Description: "The creation time.",
},
"mount_point": {
Type: schema.TypeString,
Computed: true,
Description: "The point mount.",
},
"vpc_id": {
Type: schema.TypeString,
Computed: true,
Description: "The id of vpc.",
},
"access_id": {
Type: schema.TypeString,
Computed: true,
Description: "The default vpc access id.",
},
},
}
return resource
}
func resourceVolcengineCloudfsFileSystemCreate(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Create(service, d, ResourceVolcengineCloudfsFileSystem())
if err != nil {
return fmt.Errorf("error on creating file system %q, %s", d.Id(), err)
}
return resourceVolcengineCloudfsFileSystemRead(d, meta)
}
func resourceVolcengineCloudfsFileSystemRead(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Read(service, d, ResourceVolcengineCloudfsFileSystem())
if err != nil {
return fmt.Errorf("error on reading file system %q, %s", d.Id(), err)
}
return err
}
func resourceVolcengineCloudfsFileSystemUpdate(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Update(service, d, ResourceVolcengineCloudfsFileSystem())
if err != nil {
return fmt.Errorf("error on updating file system %q, %s", d.Id(), err)
}
return resourceVolcengineCloudfsFileSystemRead(d, meta)
}
func resourceVolcengineCloudfsFileSystemDelete(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Delete(service, d, ResourceVolcengineCloudfsFileSystem())
if err != nil {
return fmt.Errorf("error on deleting file system %q, %s", d.Id(), err)
}
return err
}
func diffCache(k, old, new string, d *schema.ResourceData) bool {
// 禁用缓存时,不起作用
if d.Get("cache_plan").(string) == "DISABLED" {
return true
}
// cache_plan 没有发生变化,只是扩容,忽略变更
if d.Id() != "" && !d.HasChange("cache_plan") {
if k == "subnet_id" || k == "security_group_id" {
return true
}
}
return false
}