Skip to content

Commit 50062fa

Browse files
Added exportset resource as part of file storage service
1 parent 97c5103 commit 50062fa

File tree

9 files changed

+434
-137
lines changed

9 files changed

+434
-137
lines changed

docs/Table of Contents.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,9 @@ This lists all of the available OCI resources and/or data sources.
5858
* [Namespaces](https://github.com/oracle/terraform-provider-oci/tree/master/docs/object_storage/namespaces.md)
5959
* [Objects](https://github.com/oracle/terraform-provider-oci/tree/master/docs/object_storage/objects.md)
6060
* [Preauthenticated Requests](https://github.com/oracle/terraform-provider-oci/tree/master/docs/object_storage/preauthenticated_requests.md)
61+
* **File Storage**
62+
* [File Systems](https://github.com/oracle/terraform-provider-oci/blob/master/docs/file_storage/file_systems.md)
63+
* [Mount Targets](https://github.com/oracle/terraform-provider-oci/blob/master/docs/file_storage/mount_targets.md)
64+
* [Exports](https://github.com/oracle/terraform-provider-oci/blob/master/docs/file_storage/exports.md)
65+
* [Snapshots](https://github.com/oracle/terraform-provider-oci/blob/master/docs/file_storage/snapshots.md)
66+
* [Export Sets](https://github.com/oracle/terraform-provider-oci/blob/master/docs/file_storage/export_sets.md)

docs/examples/storage/fss/data_sources.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ data "oci_file_storage_exports" "exports" {
4141
}
4242

4343
# Gets a list of snapshots for a particular file system
44-
data "oci_file_storage_snapshots" "test_snapshots" {
44+
data "oci_file_storage_snapshots" "snapshots" {
4545
#Required
4646
file_system_id = "${oci_file_storage_file_system.my_fs_1.id}"
4747

@@ -51,7 +51,7 @@ data "oci_file_storage_snapshots" "test_snapshots" {
5151
}
5252

5353
# Gets a list of export sets in a compartment and availability domain
54-
data "oci_file_storage_export_sets" "my_export_sets" {
54+
data "oci_file_storage_export_sets" "export_sets" {
5555
#Required
5656
availability_domain = "${var.availability_domain}"
5757
compartment_id = "${var.compartment_ocid}"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "oci_file_storage_export_set" "my_export_set_1" {
2+
# Required
3+
mount_target_id = "${oci_file_storage_mount_target.my_mount_target_1.id}"
4+
5+
# Optional
6+
display_name = "${var.export_set_name_1}"
7+
max_fs_stat_bytes = "${var.max_byte}"
8+
max_fs_stat_files = "${var.max_files}"
9+
}
10+
11+
resource "oci_file_storage_export_set" "my_export_set_2" {
12+
# Required
13+
mount_target_id = "${oci_file_storage_mount_target.my_mount_target_2.id}"
14+
15+
# Optional
16+
display_name = "${var.export_set_name_2}"
17+
max_fs_stat_bytes = "${var.max_byte}"
18+
max_fs_stat_files = "${var.max_files}"
19+
}

docs/examples/storage/fss/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,20 @@ variable "export_path_fs2_mt1" {
5454

5555
variable "snapshot_name" {
5656
default = "20180320_daily"
57+
}
58+
59+
variable "export_set_name_1" {
60+
default = "export set for mount target 1"
61+
}
62+
63+
variable "export_set_name_2" {
64+
default = "export set for mount target 2"
65+
}
66+
67+
variable "max_byte" {
68+
default = 23843202333
69+
}
70+
71+
variable "max_files" {
72+
default = 223442
5773
}

docs/file_storage/export_sets.md

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,68 @@
1+
# oci_file_storage_export_set
2+
3+
## ExportSet Resource
4+
5+
### ExportSet Reference
6+
7+
The following attributes are exported:
8+
9+
* `availability_domain` - The availability domain the export set is in. May be unset as a blank or NULL value. Example: `kIdk:PHX-AD-1`
10+
* `compartment_id` - The OCID of the compartment that contains the export set.
11+
* `display_name` - A user-friendly name. It does not have to be unique, and it is changeable. Avoid entering confidential information. Example: `My export set`
12+
* `id` - The OCID of the export set.
13+
* `max_fs_stat_bytes` - Controls the maximum `tbytes`, `fbytes`, and `abytes`, values reported by `NFS FSSTAT` calls through any associated mount targets. This is an advanced feature. For most applications, use the default value. The `tbytes` value reported by `FSSTAT` will be `maxFsStatBytes`. The value of `fbytes` and `abytes` will be `maxFsStatBytes` minus the metered size of the file system. If the metered size is larger than `maxFsStatBytes`, then `fbytes` and `abytes` will both be '0'.
14+
* `max_fs_stat_files` - Controls the maximum `tfiles`, `ffiles`, and `afiles` values reported by `NFS FSSTAT` calls through any associated mount targets. This is an advanced feature. For most applications, use the default value. The `tfiles` value reported by `FSSTAT` will be `maxFsStatFiles`. The value of `ffiles` and `afiles` will be `maxFsStatFiles` minus the metered size of the file system. If the metered size is larger than `maxFsStatFiles`, then `ffiles` and `afiles` will both be '0'.
15+
* `state` - The current state of the export set.
16+
* `time_created` - The date and time the export set was created, expressed in [RFC 3339](https://tools.ietf.org/rfc/rfc3339) timestamp format. Example: `2016-08-25T21:10:29.600Z`
17+
* `vcn_id` - The OCID of the virtual cloud network (VCN) the export set is in.
18+
19+
20+
21+
### Create Operation
22+
23+
The export set resource can neither be directly created, nor destroyed.
24+
25+
An export set is created by the service automatically when a mount target is created.
26+
When a mount target is deleted, the export set associated with it is also deleted automatically.
27+
28+
However, export sets expose a few attributes that can be updated.
29+
30+
Hence we provide this resource for managing the already created export set from within Terraform.
31+
32+
The following arguments are supported:
33+
34+
* `mount_target_id` - (Required) The OCID of the mount target that the export set is associated with
35+
* `display_name` - A user-friendly name. It does not have to be unique, and it is changeable. Avoid entering confidential information. Example: `My export set`
36+
* `max_fs_stat_bytes` - Controls the maximum `tbytes`, `fbytes`, and `abytes`, values reported by `NFS FSSTAT` calls through any associated mount targets. This is an advanced feature. For most applications, use the default value. The `tbytes` value reported by `FSSTAT` will be `maxFsStatBytes`. The value of `fbytes` and `abytes` will be `maxFsStatBytes` minus the metered size of the file system. If the metered size is larger than `maxFsStatBytes`, then `fbytes` and `abytes` will both be '0'.
37+
* `max_fs_stat_files` - Controls the maximum `tfiles`, `ffiles`, and `afiles` values reported by `NFS FSSTAT` calls through any associated mount targets. This is an advanced feature. For most applications, use the default value. The `tfiles` value reported by `FSSTAT` will be `maxFsStatFiles`. The value of `ffiles` and `afiles` will be `maxFsStatFiles` minus the metered size of the file system. If the metered size is larger than `maxFsStatFiles`, then `ffiles` and `afiles` will both be '0'.
38+
39+
40+
### Update Operation
41+
Updates the specified export set's information.
42+
43+
The following arguments support updates:
44+
* `mount_target_id` - (Required) The OCID of the mount target that the export set is associated with
45+
* `display_name` - A user-friendly name. It does not have to be unique, and it is changeable. Avoid entering confidential information. Example: `My export set`
46+
* `max_fs_stat_bytes` - Controls the maximum `tbytes`, `fbytes`, and `abytes`, values reported by `NFS FSSTAT` calls through any associated mount targets. This is an advanced feature. For most applications, use the default value. The `tbytes` value reported by `FSSTAT` will be `maxFsStatBytes`. The value of `fbytes` and `abytes` will be `maxFsStatBytes` minus the metered size of the file system. If the metered size is larger than `maxFsStatBytes`, then `fbytes` and `abytes` will both be '0'.
47+
* `max_fs_stat_files` - Controls the maximum `tfiles`, `ffiles`, and `afiles` values reported by `NFS FSSTAT` calls through any associated mount targets. This is an advanced feature. For most applications, use the default value. The `tfiles` value reported by `FSSTAT` will be `maxFsStatFiles`. The value of `ffiles` and `afiles` will be `maxFsStatFiles` minus the metered size of the file system. If the metered size is larger than `maxFsStatFiles`, then `ffiles` and `afiles` will both be '0'.
48+
49+
50+
** IMPORTANT **
51+
Any change to a property that does not support update will force the destruction and recreation of the resource with the new property values
52+
53+
### Example Usage
54+
55+
```
56+
resource "oci_file_storage_export_set" "test_export_set" {
57+
#Required
58+
mount_target_id = "${oci_file_storage_mount_target.test_mount_target.id}"
59+
60+
#Optional
61+
display_name = "${var.export_set_name}"
62+
max_fs_stat_bytes = 23843202333
63+
max_fs_stat_files = 223442
64+
}
65+
```
166

267
# oci_file_storage_export_sets
368

@@ -10,7 +75,7 @@ Lists the export set resources in the specified compartment.
1075

1176
The following arguments are supported:
1277

13-
* `availability_domain` - (Required) The name of the availability domain. Example: `Uocm:PHX-AD-1`
78+
* `availability_domain` - (Required) The name of the availability domain. Example: `kIdk:PHX-AD-1`
1479
* `compartment_id` - (Required) The OCID of the compartment.
1580
* `display_name` - (Optional) A user-friendly name. It does not have to be unique, and it is changeable. Example: `My resource`
1681
* `id` - (Optional) Filter results by OCID. Must be an OCID of the correct type for the resouce type.
@@ -34,17 +99,4 @@ data "oci_file_storage_export_sets" "test_export_sets" {
3499
id = "${var.export_set_id}"
35100
state = "${var.export_set_state}"
36101
}
37-
```
38-
### ExportSet Reference
39-
40-
The following attributes are exported:
41-
42-
* `availability_domain` - The availability domain the export set is in. May be unset as a blank or NULL value. Example: `Uocm:PHX-AD-1`
43-
* `compartment_id` - The OCID of the compartment that contains the export set.
44-
* `display_name` - A user-friendly name. It does not have to be unique, and it is changeable. Avoid entering confidential information. Example: `My export set`
45-
* `id` - The OCID of the export set.
46-
* `max_fs_stat_bytes` - Controls the maximum `tbytes`, `fbytes`, and `abytes`, values reported by `NFS FSSTAT` calls through any associated mount targets. This is an advanced feature. For most applications, use the default value. The `tbytes` value reported by `FSSTAT` will be `maxFsStatBytes`. The value of `fbytes` and `abytes` will be `maxFsStatBytes` minus the metered size of the file system. If the metered size is larger than `maxFsStatBytes`, then `fbytes` and `abytes` will both be '0'.
47-
* `max_fs_stat_files` - Controls the maximum `ffiles`, `ffiles`, and `afiles` values reported by `NFS FSSTAT` calls through any associated mount targets. This is an advanced feature. For most applications, use the default value. The `tfiles` value reported by `FSSTAT` will be `maxFsStatFiles`. The value of `ffiles` and `afiles` will be `maxFsStatFiles` minus the metered size of the file system. If the metered size is larger than `maxFsStatFiles`, then `ffiles` and `afiles` will both be '0'.
48-
* `state` - The current state of the export set.
49-
* `time_created` - The date and time the export set was created, expressed in [RFC 3339](https://tools.ietf.org/rfc/rfc3339) timestamp format. Example: `2016-08-25T21:10:29.600Z`
50-
* `vcn_id` - The OCID of the virtual cloud network (VCN) the export set is in.
102+
```
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
3+
package provider
4+
5+
import (
6+
"context"
7+
"fmt"
8+
9+
"github.com/hashicorp/terraform/helper/schema"
10+
11+
"github.com/oracle/terraform-provider-oci/crud"
12+
13+
oci_file_storage "github.com/oracle/oci-go-sdk/filestorage"
14+
)
15+
16+
func ExportSetResource() *schema.Resource {
17+
return &schema.Resource{
18+
Importer: &schema.ResourceImporter{
19+
State: schema.ImportStatePassthrough,
20+
},
21+
Timeouts: crud.DefaultTimeout,
22+
Create: createExportSet,
23+
Read: readExportSet,
24+
Update: updateExportSet,
25+
Delete: deleteExportSet,
26+
Schema: map[string]*schema.Schema{
27+
// Required
28+
"mount_target_id": {
29+
Type: schema.TypeString,
30+
Required: true,
31+
ForceNew: true,
32+
},
33+
34+
// Optional
35+
"display_name": {
36+
Type: schema.TypeString,
37+
Optional: true,
38+
Computed: true,
39+
},
40+
"max_fs_stat_bytes": {
41+
Type: schema.TypeInt,
42+
Optional: true,
43+
Computed: true,
44+
},
45+
"max_fs_stat_files": {
46+
Type: schema.TypeInt,
47+
Optional: true,
48+
Computed: true,
49+
},
50+
51+
// Computed
52+
"availability_domain": {
53+
Type: schema.TypeString,
54+
Computed: true,
55+
},
56+
"compartment_id": {
57+
Type: schema.TypeString,
58+
Computed: true,
59+
},
60+
"id": {
61+
Type: schema.TypeString,
62+
Computed: true,
63+
},
64+
"state": {
65+
Type: schema.TypeString,
66+
Computed: true,
67+
},
68+
"time_created": {
69+
Type: schema.TypeString,
70+
Computed: true,
71+
},
72+
"vcn_id": {
73+
Type: schema.TypeString,
74+
Computed: true,
75+
},
76+
},
77+
}
78+
}
79+
80+
func createExportSet(d *schema.ResourceData, m interface{}) error {
81+
sync := &ExportSetResourceCrud{}
82+
sync.D = d
83+
sync.Client = m.(*OracleClients).fileStorageClient
84+
85+
return crud.CreateResource(d, sync)
86+
}
87+
88+
func readExportSet(d *schema.ResourceData, m interface{}) error {
89+
sync := &ExportSetResourceCrud{}
90+
sync.D = d
91+
sync.Client = m.(*OracleClients).fileStorageClient
92+
93+
return crud.ReadResource(sync)
94+
}
95+
96+
func updateExportSet(d *schema.ResourceData, m interface{}) error {
97+
sync := &ExportSetResourceCrud{}
98+
sync.D = d
99+
sync.Client = m.(*OracleClients).fileStorageClient
100+
101+
return crud.UpdateResource(d, sync)
102+
}
103+
104+
func deleteExportSet(d *schema.ResourceData, m interface{}) error {
105+
// Export set is deleted when a mount target is deleted.
106+
return nil
107+
}
108+
109+
type ExportSetResourceCrud struct {
110+
crud.BaseCrud
111+
Client *oci_file_storage.FileStorageClient
112+
Res *oci_file_storage.ExportSet
113+
DisableNotFoundRetries bool
114+
}
115+
116+
func (s *ExportSetResourceCrud) ID() string {
117+
return *s.Res.Id
118+
}
119+
120+
func (s *ExportSetResourceCrud) Create() error {
121+
// We can't really create an ExportSet. We need to get the exportSetId from the MountTarget it is attached to.
122+
if mountTargetId, ok := s.D.GetOkExists("mount_target_id"); ok {
123+
tmp := mountTargetId.(string)
124+
125+
request := oci_file_storage.GetMountTargetRequest{}
126+
request.MountTargetId = &tmp
127+
128+
response, err := s.Client.GetMountTarget(context.Background(), request, getRetryOptions(s.DisableNotFoundRetries, "file_storage")...)
129+
if err != nil {
130+
return fmt.Errorf("getting mount target details failed with error: %s", err.Error())
131+
}
132+
133+
exportSetId := response.MountTarget.ExportSetId
134+
135+
if exportSetId == nil {
136+
return fmt.Errorf("export_set_id is not available in the mount target response")
137+
}
138+
139+
s.D.SetId(*exportSetId)
140+
return s.Update()
141+
}
142+
143+
return fmt.Errorf("no mount_target_id value could be found")
144+
}
145+
146+
func (s *ExportSetResourceCrud) Get() error {
147+
request := oci_file_storage.GetExportSetRequest{}
148+
149+
tmp := s.D.Id()
150+
request.ExportSetId = &tmp
151+
152+
response, err := s.Client.GetExportSet(context.Background(), request, getRetryOptions(s.DisableNotFoundRetries, "file_storage")...)
153+
if err != nil {
154+
return err
155+
}
156+
157+
s.Res = &response.ExportSet
158+
return nil
159+
}
160+
161+
func (s *ExportSetResourceCrud) Update() error {
162+
request := oci_file_storage.UpdateExportSetRequest{}
163+
164+
if displayName, ok := s.D.GetOkExists("display_name"); ok {
165+
tmp := displayName.(string)
166+
request.DisplayName = &tmp
167+
}
168+
169+
tmp := s.D.Id()
170+
request.ExportSetId = &tmp
171+
172+
if maxFsStatBytes, ok := s.D.GetOkExists("max_fs_stat_bytes"); ok {
173+
tmp := maxFsStatBytes.(int)
174+
request.MaxFsStatBytes = &tmp
175+
}
176+
177+
if maxFsStatFiles, ok := s.D.GetOkExists("max_fs_stat_files"); ok {
178+
tmp := maxFsStatFiles.(int)
179+
request.MaxFsStatFiles = &tmp
180+
}
181+
182+
response, err := s.Client.UpdateExportSet(context.Background(), request, getRetryOptions(s.DisableNotFoundRetries, "file_storage")...)
183+
if err != nil {
184+
return err
185+
}
186+
187+
s.Res = &response.ExportSet
188+
return nil
189+
}
190+
191+
func (s *ExportSetResourceCrud) Delete() error {
192+
// Export set is deleted when a mount target is deleted.
193+
return nil
194+
}
195+
196+
func (s *ExportSetResourceCrud) SetData() {
197+
if s.Res.AvailabilityDomain != nil {
198+
s.D.Set("availability_domain", *s.Res.AvailabilityDomain)
199+
}
200+
201+
if s.Res.CompartmentId != nil {
202+
s.D.Set("compartment_id", *s.Res.CompartmentId)
203+
}
204+
205+
if s.Res.DisplayName != nil {
206+
s.D.Set("display_name", *s.Res.DisplayName)
207+
}
208+
209+
if s.Res.Id != nil {
210+
s.D.Set("id", *s.Res.Id)
211+
}
212+
213+
if s.Res.MaxFsStatBytes != nil {
214+
s.D.Set("max_fs_stat_bytes", *s.Res.MaxFsStatBytes)
215+
}
216+
217+
if s.Res.MaxFsStatFiles != nil {
218+
s.D.Set("max_fs_stat_files", *s.Res.MaxFsStatFiles)
219+
}
220+
221+
s.D.Set("state", s.Res.LifecycleState)
222+
223+
s.D.Set("time_created", s.Res.TimeCreated.String())
224+
225+
if s.Res.VcnId != nil {
226+
s.D.Set("vcn_id", *s.Res.VcnId)
227+
}
228+
}

0 commit comments

Comments
 (0)