Skip to content

Commit 9af3a29

Browse files
Terraform Team Automationsagarp337
authored andcommitted
Added - Support for File Storage: Clone detach feature
1 parent 6bf4d8d commit 9af3a29

12 files changed

+168
-20
lines changed

examples/storage/fss/file_system_clone.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,27 @@ resource "oci_file_storage_snapshot" "my_snapshot_clone" {
1919
#Required
2020
file_system_id = oci_file_storage_file_system.my_fs_simple.id
2121
name = var.snapshot_name_clone
22+
}
23+
resource "oci_file_storage_file_system" "my_fs_clone_with_detach" {
24+
#Required
25+
availability_domain = data.oci_identity_availability_domain.ad.name
26+
compartment_id = var.compartment_ocid
27+
28+
#Optional
29+
display_name = var.file_system_clone_with_detach_display_name
30+
source_snapshot_id = oci_file_storage_snapshot.my_snapshot_clone_1.id
31+
clone_attach_status = var.clone_attach_status_value
32+
}
33+
resource "oci_file_storage_file_system" "my_fs_simple_1" {
34+
#Required
35+
availability_domain = data.oci_identity_availability_domain.ad.name
36+
compartment_id = var.compartment_ocid
37+
38+
#Optional
39+
display_name = var.file_system_simple_1_display_name
40+
}
41+
resource "oci_file_storage_snapshot" "my_snapshot_clone_1" {
42+
#Required
43+
file_system_id = oci_file_storage_file_system.my_fs_simple_1.id
44+
name = var.snapshot_name_clone_1
2245
}

examples/storage/fss/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,22 @@ variable "file_system_clone_display_name" {
4646
default= "my_fs_clone"
4747
}
4848

49+
variable "file_system_clone_with_detach_display_name" {
50+
default= "my_fs_clone_with_detach"
51+
}
52+
4953
variable "file_system_simple_display_name" {
5054
default= "my_fs_simple"
5155
}
5256

57+
variable "file_system_simple_1_display_name" {
58+
default= "my_fs_simple_1"
59+
}
60+
61+
variable "clone_attach_status_value" {
62+
default= "DETACH"
63+
}
64+
5365
variable "file_system_with_snapshot_policy_display_name" {
5466
default = "my_fs_with_snapshot_policy"
5567
}
@@ -82,6 +94,10 @@ variable "snapshot_name_clone" {
8294
default = "snapshot_clone"
8395
}
8496

97+
variable "snapshot_name_clone_1" {
98+
default = "snapshot_clone_1"
99+
}
100+
85101
variable "export_set_name_1" {
86102
default = "export set for mount target 1"
87103
}

internal/integrationtest/file_storage_file_system_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ var (
4949
FileStorageFileSystemRepresentation = map[string]interface{}{
5050
"availability_domain": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
5151
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
52+
"clone_attach_status": acctest.Representation{RepType: acctest.Optional, Create: `DETACH`},
5253
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
5354
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `media-files-1`, Update: `displayName2`},
5455
"filesystem_snapshot_policy_id": acctest.Representation{RepType: acctest.Optional, Create: `${oci_file_storage_filesystem_snapshot_policy.test_filesystem_snapshot_policy.id}`},
5556
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
5657
"kms_key_id": acctest.Representation{RepType: acctest.Optional, Create: `${oci_kms_key.kms_key_id_for_create.id}`, Update: `${oci_kms_key.kms_key_id_for_update.id}`},
5758
"source_snapshot_id": acctest.Representation{RepType: acctest.Optional, Create: `${oci_file_storage_snapshot.test_snapshot.id}`},
59+
"detach_clone_trigger": acctest.Representation{RepType: acctest.Optional, Create: `0`, Update: `0`},
5860
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: ignoreDefinedTagsDifferencesRepresentation},
5961
}
6062

@@ -123,6 +125,7 @@ func TestFileStorageFileSystemResource_basic(t *testing.T) {
123125
acctest.GenerateResourceFromRepresentationMap("oci_file_storage_file_system", "test_file_system2", acctest.Optional, acctest.Create, FileStorageFileSystemRepresentation),
124126
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
125127
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
128+
resource.TestCheckResourceAttr(resourceName, "clone_attach_status", "ATTACHED"),
126129
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
127130
resource.TestCheckResourceAttr(resourceName, "display_name", "media-files-1"),
128131
resource.TestCheckResourceAttrSet(resourceName, "filesystem_snapshot_policy_id"),
@@ -156,6 +159,7 @@ func TestFileStorageFileSystemResource_basic(t *testing.T) {
156159
})),
157160
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
158161
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
162+
resource.TestCheckResourceAttr(resourceName, "clone_attach_status", "DETACHING"),
159163
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentIdU),
160164
resource.TestCheckResourceAttr(resourceName, "display_name", "media-files-1"),
161165
resource.TestCheckResourceAttrSet(resourceName, "filesystem_snapshot_policy_id"),
@@ -214,6 +218,7 @@ func TestFileStorageFileSystemResource_basic(t *testing.T) {
214218
acctest.GenerateResourceFromRepresentationMap("oci_file_storage_file_system", "test_file_system2", acctest.Optional, acctest.Update, FileStorageFileSystemRepresentation),
215219
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
216220
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
221+
resource.TestCheckResourceAttr(resourceName, "clone_attach_status", "DETACHING"),
217222
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
218223
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
219224
resource.TestCheckResourceAttrSet(resourceName, "filesystem_snapshot_policy_id"),
@@ -254,6 +259,7 @@ func TestFileStorageFileSystemResource_basic(t *testing.T) {
254259

255260
resource.TestCheckResourceAttr(datasourceName, "file_systems.#", "1"),
256261
resource.TestCheckResourceAttrSet(datasourceName, "file_systems.0.availability_domain"),
262+
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.clone_attach_status", "DETACHING"),
257263
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.compartment_id", compartmentId),
258264
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.display_name", "displayName2"),
259265
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.freeform_tags.%", "1"),
@@ -273,7 +279,7 @@ func TestFileStorageFileSystemResource_basic(t *testing.T) {
273279
Config: config + FileStorageFileSystem2RequiredOnlyResource,
274280
ImportState: true,
275281
ImportStateVerify: true,
276-
ImportStateVerifyIgnore: []string{"source_snapshot_id", "parent_file_system_id"},
282+
ImportStateVerifyIgnore: []string{"source_snapshot_id", "parent_file_system_id", "detach_clone_trigger"},
277283
ResourceName: resourceName,
278284
},
279285
})

internal/service/file_storage/file_storage_file_system_resource.go

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package file_storage
55

66
import (
77
"context"
8+
"fmt"
89
"strconv"
910

1011
"github.com/oracle/terraform-provider-oci/internal/client"
@@ -39,6 +40,12 @@ func FileStorageFileSystemResource() *schema.Resource {
3940
},
4041

4142
// Optional
43+
"clone_attach_status": {
44+
Type: schema.TypeString,
45+
Optional: true,
46+
Computed: true,
47+
DiffSuppressFunc: tfresource.AttachDiffSuppressFunction,
48+
},
4249
"defined_tags": {
4350
Type: schema.TypeMap,
4451
Optional: true,
@@ -74,8 +81,16 @@ func FileStorageFileSystemResource() *schema.Resource {
7481
Computed: true,
7582
ForceNew: true,
7683
},
84+
"detach_clone_trigger": {
85+
Type: schema.TypeInt,
86+
Optional: true,
87+
},
7788

7889
// Computed
90+
"clone_count": {
91+
Type: schema.TypeInt,
92+
Computed: true,
93+
},
7994
"is_clone_parent": {
8095
Type: schema.TypeBool,
8196
Computed: true,
@@ -138,7 +153,18 @@ func createFileStorageFileSystem(d *schema.ResourceData, m interface{}) error {
138153
sync.D = d
139154
sync.Client = m.(*client.OracleClients).FileStorageClient()
140155

141-
return tfresource.CreateResource(d, sync)
156+
if e := tfresource.CreateResource(d, sync); e != nil {
157+
return e
158+
}
159+
160+
if _, ok := sync.D.GetOkExists("detach_clone_trigger"); ok {
161+
err := sync.DetachClone()
162+
if err != nil {
163+
return err
164+
}
165+
}
166+
return nil
167+
142168
}
143169

144170
func readFileStorageFileSystem(d *schema.ResourceData, m interface{}) error {
@@ -154,7 +180,27 @@ func updateFileStorageFileSystem(d *schema.ResourceData, m interface{}) error {
154180
sync.D = d
155181
sync.Client = m.(*client.OracleClients).FileStorageClient()
156182

157-
return tfresource.UpdateResource(d, sync)
183+
if _, ok := sync.D.GetOkExists("detach_clone_trigger"); ok && sync.D.HasChange("detach_clone_trigger") {
184+
oldRaw, newRaw := sync.D.GetChange("detach_clone_trigger")
185+
oldValue := oldRaw.(int)
186+
newValue := newRaw.(int)
187+
if oldValue < newValue {
188+
err := sync.DetachClone()
189+
190+
if err != nil {
191+
return err
192+
}
193+
} else {
194+
sync.D.Set("detach_clone_trigger", oldRaw)
195+
return fmt.Errorf("new value of trigger should be greater than the old value")
196+
}
197+
}
198+
199+
if err := tfresource.UpdateResource(d, sync); err != nil {
200+
return err
201+
}
202+
203+
return nil
158204
}
159205

160206
func deleteFileStorageFileSystem(d *schema.ResourceData, m interface{}) error {
@@ -209,6 +255,10 @@ func (s *FileStorageFileSystemResourceCrud) Create() error {
209255
request.AvailabilityDomain = &tmp
210256
}
211257

258+
if cloneAttachStatus, ok := s.D.GetOkExists("clone_attach_status"); ok {
259+
request.CloneAttachStatus = oci_file_storage.CreateFileSystemDetailsCloneAttachStatusEnum(cloneAttachStatus.(string))
260+
}
261+
212262
if compartmentId, ok := s.D.GetOkExists("compartment_id"); ok {
213263
tmp := compartmentId.(string)
214264
request.CompartmentId = &tmp
@@ -334,6 +384,11 @@ func (s *FileStorageFileSystemResourceCrud) Update() error {
334384
func (s *FileStorageFileSystemResourceCrud) Delete() error {
335385
request := oci_file_storage.DeleteFileSystemRequest{}
336386

387+
if canDetachChildFileSystem, ok := s.D.GetOkExists("can_detach_child_file_system"); ok {
388+
tmp := canDetachChildFileSystem.(bool)
389+
request.CanDetachChildFileSystem = &tmp
390+
}
391+
337392
tmp := s.D.Id()
338393
request.FileSystemId = &tmp
339394

@@ -348,6 +403,12 @@ func (s *FileStorageFileSystemResourceCrud) SetData() error {
348403
s.D.Set("availability_domain", *s.Res.AvailabilityDomain)
349404
}
350405

406+
s.D.Set("clone_attach_status", s.Res.CloneAttachStatus)
407+
408+
if s.Res.CloneCount != nil {
409+
s.D.Set("clone_count", *s.Res.CloneCount)
410+
}
411+
351412
if s.Res.CompartmentId != nil {
352413
s.D.Set("compartment_id", *s.Res.CompartmentId)
353414
}
@@ -409,6 +470,29 @@ func (s *FileStorageFileSystemResourceCrud) SetData() error {
409470
return nil
410471
}
411472

473+
func (s *FileStorageFileSystemResourceCrud) DetachClone() error {
474+
request := oci_file_storage.DetachCloneRequest{}
475+
476+
idTmp := s.D.Id()
477+
request.FileSystemId = &idTmp
478+
479+
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "file_storage")
480+
481+
_, err := s.Client.DetachClone(context.Background(), request)
482+
if err != nil {
483+
return err
484+
}
485+
486+
if waitErr := tfresource.WaitForUpdatedState(s.D, s); waitErr != nil {
487+
return waitErr
488+
}
489+
490+
val := s.D.Get("detach_clone_trigger")
491+
s.D.Set("detach_clone_trigger", val)
492+
493+
return nil
494+
}
495+
412496
func FileSystemSourceDetailsToMap(obj *oci_file_storage.SourceDetails) map[string]interface{} {
413497
result := map[string]interface{}{}
414498

internal/service/file_storage/file_storage_file_systems_data_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ func (s *FileStorageFileSystemsDataSourceCrud) SetData() error {
157157
"compartment_id": *r.CompartmentId,
158158
}
159159

160+
fileSystem["clone_attach_status"] = r.CloneAttachStatus
161+
160162
if r.DefinedTags != nil {
161163
fileSystem["defined_tags"] = tfresource.DefinedTagsToMap(r.DefinedTags)
162164
}

internal/tfresource/crud_helpers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,13 @@ func MonetaryDiffSuppress(key string, old string, new string, d *schema.Resource
12311231
return fmt.Sprintf("%.2f", oldVal) == fmt.Sprintf("%.2f", newVal)
12321232
}
12331233

1234+
func AttachDiffSuppressFunction(key string, old string, new string, d *schema.ResourceData) bool {
1235+
if new == "DETACH" {
1236+
return true
1237+
}
1238+
return false
1239+
}
1240+
12341241
// Diff suppression function to make sure that any change in ordering of attributes in JSON objects don't result in diffs.
12351242
// For example, the config may have created this:
12361243
//

website/docs/d/file_storage_file_systems.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ The following attributes are exported:
5757
The following attributes are exported:
5858

5959
* `availability_domain` - The availability domain the file system is in. May be unset as a blank or NULL value. Example: `Uocm:PHX-AD-1`
60+
* `clone_attach_status` - Specifies whether the file system is attached to its parent file system.
61+
* `clone_count` - Specifies the total number of children of a file system.
6062
* `compartment_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the compartment that contains the file system.
6163
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
6264
* `display_name` - A user-friendly name. It does not have to be unique, and it is changeable. Avoid entering confidential information. Example: `My file system`

website/docs/d/file_storage_filesystem_snapshot_policies.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ The following attributes are exported:
5757
* `id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the file system snapshot policy.
5858
* `policy_prefix` - The prefix to apply to all snapshots created by this policy. Example: `acme`
5959
* `schedules` - The list of associated snapshot schedules. A maximum of 10 schedules can be associated with a policy.
60-
* `day_of_month` - The day of the month to create a scheduled snapshot. If the day does not exist for the month, snapshot creation will be skipped. Used for MONTHLY and YEARLY snapshot schedules.
61-
* `day_of_week` - The day of the week to create a scheduled snapshot. Used for WEEKLY snapshot schedules.
62-
* `hour_of_day` - The hour of the day to create a DAILY, WEEKLY, MONTHLY, or YEARLY snapshot. If not set, a value will be chosen at creation time.
63-
* `month` - The month to create a scheduled snapshot. Used only for YEARLY snapshot schedules.
60+
* `day_of_month` - The day of the month to create a scheduled snapshot. If the day does not exist for the month, snapshot creation will be skipped. Used for MONTHLY and YEARLY snapshot schedules. If not set, the system chooses a value at creation time.
61+
* `day_of_week` - The day of the week to create a scheduled snapshot. Used for WEEKLY snapshot schedules. If not set, the system chooses a value at creation time.
62+
* `hour_of_day` - The hour of the day to create a DAILY, WEEKLY, MONTHLY, or YEARLY snapshot. If not set, the system chooses a value at creation time.
63+
* `month` - The month to create a scheduled snapshot. Used only for YEARLY snapshot schedules. If not set, the system chooses a value at creation time.
6464
* `period` - The frequency of scheduled snapshots.
6565
* `retention_duration_in_seconds` - The number of seconds to retain snapshots created with this schedule. Snapshot expiration time will not be set if this value is empty.
6666
* `schedule_prefix` - A name prefix to be applied to snapshots created by this schedule. Example: `compliance1`

website/docs/d/file_storage_filesystem_snapshot_policy.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ The following attributes are exported:
4040
* `id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the file system snapshot policy.
4141
* `policy_prefix` - The prefix to apply to all snapshots created by this policy. Example: `acme`
4242
* `schedules` - The list of associated snapshot schedules. A maximum of 10 schedules can be associated with a policy.
43-
* `day_of_month` - The day of the month to create a scheduled snapshot. If the day does not exist for the month, snapshot creation will be skipped. Used for MONTHLY and YEARLY snapshot schedules.
44-
* `day_of_week` - The day of the week to create a scheduled snapshot. Used for WEEKLY snapshot schedules.
45-
* `hour_of_day` - The hour of the day to create a DAILY, WEEKLY, MONTHLY, or YEARLY snapshot. If not set, a value will be chosen at creation time.
46-
* `month` - The month to create a scheduled snapshot. Used only for YEARLY snapshot schedules.
43+
* `day_of_month` - The day of the month to create a scheduled snapshot. If the day does not exist for the month, snapshot creation will be skipped. Used for MONTHLY and YEARLY snapshot schedules. If not set, the system chooses a value at creation time.
44+
* `day_of_week` - The day of the week to create a scheduled snapshot. Used for WEEKLY snapshot schedules. If not set, the system chooses a value at creation time.
45+
* `hour_of_day` - The hour of the day to create a DAILY, WEEKLY, MONTHLY, or YEARLY snapshot. If not set, the system chooses a value at creation time.
46+
* `month` - The month to create a scheduled snapshot. Used only for YEARLY snapshot schedules. If not set, the system chooses a value at creation time.
4747
* `period` - The frequency of scheduled snapshots.
4848
* `retention_duration_in_seconds` - The number of seconds to retain snapshots created with this schedule. Snapshot expiration time will not be set if this value is empty.
4949
* `schedule_prefix` - A name prefix to be applied to snapshots created by this schedule. Example: `compliance1`

website/docs/r/file_storage_export.html.markdown

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ resource "oci_file_storage_export" "test_export" {
4545

4646
The following arguments are supported:
4747

48-
* `export_options` - (Optional) (Updatable) Export options for the new export. If left unspecified, defaults to:
48+
* `export_options` - (Optional) (Updatable) Export options for the new export. For exports of mount targets with IPv4 address, if client options are left unspecified, client options would default to:
49+
4950
[ { "source" : "0.0.0.0/0", "requirePrivilegedSourcePort" : false, "access": "READ_WRITE", "identitySquash": "NONE", "anonymousUid": 65534, "anonymousGid": 65534, "isAnonymousAccessAllowed": false, "allowedAuth": ["SYS"] } ]
5051

52+
For exports of mount targets with IPv6 address, if client options are left unspecified, client options would be an empty array, i.e. export would not be visible to any clients.
53+
5154
**Note:** Mount targets do not have Internet-routable IP addresses. Therefore they will not be reachable from the Internet, even if an associated `ClientOptions` item has a source of `0.0.0.0/0`.
5255

5356
**If set to the empty array then the export will not be visible to any clients.**

0 commit comments

Comments
 (0)