Skip to content

Commit

Permalink
added filesystem snapshot datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
Krishnan-Priyanshu committed Jan 7, 2025
1 parent 5a80ea5 commit b566baa
Show file tree
Hide file tree
Showing 13 changed files with 825 additions and 5 deletions.
83 changes: 83 additions & 0 deletions docs/data-sources/filesystem_snapshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
# Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Licensed under the Mozilla Public License Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://mozilla.org/MPL/2.0/
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

title: "powerstore_filesystem_snapshot data source"
linkTitle: "powerstore_filesystem_snapshot"
page_title: "powerstore_filesystem_snapshot Data Source - powerstore"
subcategory: ""
description: |-
This datasource is used to query the existing File System Snapshot from PowerStore array. The information fetched from this datasource can be used for getting the details for further processing in resource block.
---

# powerstore_filesystem_snapshot (Data Source)

This datasource is used to query the existing File System Snapshot from PowerStore array. The information fetched from this datasource can be used for getting the details for further processing in resource block.

## Example Usage

{{tffile "/root/Dev/terraform-provider-powerstore/examples/data-sources/powerstore_filesystem_snapshot/data-source.tf"}}

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `filesystem_id` (String) File System Snapshot name. Conflicts with `id` and `name`.
- `id` (String) Unique identifier of the File System Snapshot. Conflicts with `name` and `filesystem_id`.
- `name` (String) File System Snapshot name. Conflicts with `id` and `filesystem_id`.

### Read-Only

- `filesystem_snapshots` (Attributes List) List of File System Snapshots. (see [below for nested schema](#nestedatt--filesystem_snapshots))

<a id="nestedatt--filesystem_snapshots"></a>
### Nested Schema for `filesystem_snapshots`

Read-Only:

- `access_policy` (String) Access Policy
- `access_type` (String) Access Type
- `config_type` (String) Config Type
- `description` (String) Description
- `expiration_timestamp` (String) Expiration Timestamp
- `filesystem_type` (String) Filesystem Type
- `flr_attributes` (Attributes) Flr Attributes (see [below for nested schema](#nestedatt--filesystem_snapshots--flr_attributes))
- `folder_rename_policy` (String) Folder Rename Policy
- `id` (String) ID
- `is_async_m_time_enabled` (Boolean) Is Async MTime Enabled
- `is_smb_no_notify_enabled` (Boolean) Is Smb No Notify Enabled
- `is_smb_notify_on_access_enabled` (Boolean) Is Smb Notify On Access Enabled
- `is_smb_notify_on_write_enabled` (Boolean) Is Smb Notify On Write Enabled
- `is_smb_op_locks_enabled` (Boolean) Is Smb Op Locks Enabled
- `is_smb_sync_writes_enabled` (Boolean) Is Smb Sync Writes Enabled
- `locking_policy` (String) Locking Policy
- `name` (String) Name
- `nas_server_id` (String) Nas Server ID
- `parent_id` (String) Parent ID
- `protection_policy_id` (String) Protection Policy ID
- `size_total` (Number) Size Total
- `size_used` (Number) Size Used
- `smb_notify_on_change_dir_depth` (Number) Smb Notify On Change Dir Depth

<a id="nestedatt--filesystem_snapshots--flr_attributes"></a>
### Nested Schema for `filesystem_snapshots.flr_attributes`

Read-Only:

- `default_retention` (String) Default Retention
- `maximum_retention` (String) Maximum Retention
- `minimum_retention` (String) Minimum Retention
- `mode` (String) Mode
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

# commands to run this tf file : terraform init && terraform apply --auto-approve
# This datasource reads hosts either by id or name where user can provide a value to any one of them
# If it is a empty datsource block , then it will read all the filesystem
# If id or name is provided then it reads a particular file system snapshot with that id or name
# If filesystem_id is provided then it will read all the filesystem snapshots within filesystem
# Only one of the attribute can be provided among id or name or filesystem_id


// create filesystem
resource "powerstore_filesystem" "test" {
name = "test_fs"
description = "testing file system"
size = 3
nas_server_id = "<nas_server_id>"
flr_attributes = {
mode = "Enterprise"
minimum_retention = "1D"
default_retention = "1D"
maximum_retention = "infinite"
}
config_type = "General"
access_policy = "UNIX"
locking_policy = "Advisory"
folder_rename_policy = "All_Allowed"
is_smb_sync_writes_enabled = true
is_smb_no_notify_enabled = true
is_smb_op_locks_enabled = false
is_smb_notify_on_access_enabled = true
is_smb_notify_on_write_enabled = false
smb_notify_on_change_dir_depth = 12
is_async_mtime_enabled = true
file_events_publishing_mode = "All"
}

// create snapshot from filesystem
resource "powerstore_filesystem_snapshot" "test" {
name = "tf_fs_snap"
description = "Test File System Snapshot Resource"
filesystem_id = resource.powerstore_filesystem.test.id
expiration_timestamp = "2035-05-06T09:01:47Z"
access_type = "Snapshot"
}

data "powerstore_filesystem_snapshot" "test1" {
name = resource.powerstore_filesystem_snapshot.test.name
# id = resource.powerstore_filesystem_snapshot.test.id
# filesystem_id= resource.powerstore_filesystem.test.id
}


output "fileSystemSnapshotResult" {
value = data.powerstore_filesystem_snapshot.test1.filesystem_snapshots
}
33 changes: 33 additions & 0 deletions examples/data-sources/powerstore_filesystem_snapshot/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

terraform {
required_providers {
powerstore = {
version = "1.2.0"
source = "registry.terraform.io/dell/powerstore"
}
}
}

provider "powerstore" {
username = var.username
password = var.password
endpoint = var.endpoint
insecure = true
timeout = var.timeout
}
36 changes: 36 additions & 0 deletions examples/data-sources/powerstore_filesystem_snapshot/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

variable "username" {
type = string
description = "Stores the username of PowerStore host."
}

variable "password" {
type = string
description = "Stores the password of PowerStore host."
}

variable "timeout" {
type = string
description = "Stores the timeout of PowerStore host."
}

variable "endpoint" {
type = string
description = "Stores the endpoint of PowerStore host. eg: https://10.1.1.1/api/rest"
}
10 changes: 5 additions & 5 deletions examples/resources/powerstore_filesystem_snapshot/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ limitations under the License.
# To check which attributes of the file system snapshot resource can be updated, please refer Product Guide in the documentation

resource "powerstore_filesystem_snapshot" "test1" {
name = "tf_fs_snap"
description = "Test File System Snapshot Resource"
filesystem_id="67608dc7-b69c-b762-0522-42848bc63a0b"
expiration_timestamp="2035-05-06T09:01:47Z"
access_type = "Snapshot"
name = "tf_fs_snap"
description = "Test File System Snapshot Resource"
filesystem_id = "67608dc7-b69c-b762-0522-42848bc63a0b"
expiration_timestamp = "2035-05-06T09:01:47Z"
access_type = "Snapshot"
}
55 changes: 55 additions & 0 deletions models/filesystem_datasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package models

import "github.com/hashicorp/terraform-plugin-framework/types"

// FileSystemDatasource represents filesystem
type FileSystemDatasource struct {
AccessPolicy types.String `tfsdk:"access_policy"`
AccessType types.String `tfsdk:"access_type"`
ConfigType types.String `tfsdk:"config_type"`
Description types.String `tfsdk:"description"`
ExpirationTimestamp types.String `tfsdk:"expiration_timestamp"`
FilesystemType types.String `tfsdk:"filesystem_type"`
FlrAttributes FLRAttributesDatasource `tfsdk:"flr_attributes"`
FolderRenamePolicy types.String `tfsdk:"folder_rename_policy"`
ID types.String `tfsdk:"id"`
IsAsyncMTimeEnabled types.Bool `tfsdk:"is_async_m_time_enabled"`
IsSmbNoNotifyEnabled types.Bool `tfsdk:"is_smb_no_notify_enabled"`
IsSmbNotifyOnAccessEnabled types.Bool `tfsdk:"is_smb_notify_on_access_enabled"`
IsSmbNotifyOnWriteEnabled types.Bool `tfsdk:"is_smb_notify_on_write_enabled"`
IsSmbOpLocksEnabled types.Bool `tfsdk:"is_smb_op_locks_enabled"`
IsSmbSyncWritesEnabled types.Bool `tfsdk:"is_smb_sync_writes_enabled"`
LockingPolicy types.String `tfsdk:"locking_policy"`
Name types.String `tfsdk:"name"`
NasServerID types.String `tfsdk:"nas_server_id"`
ParentID types.String `tfsdk:"parent_id"`
ProtectionPolicyID types.String `tfsdk:"protection_policy_id"`
SizeTotal types.Int64 `tfsdk:"size_total"`
SizeUsed types.Int64 `tfsdk:"size_used"`
SmbNotifyOnChangeDirDepth types.Int64 `tfsdk:"smb_notify_on_change_dir_depth"`
}

// FLRAttributesDatasource represents flr attributes
type FLRAttributesDatasource struct {
DefaultRetention types.String `tfsdk:"default_retention"`
MaximumRetention types.String `tfsdk:"maximum_retention"`
MinimumRetention types.String `tfsdk:"minimum_retention"`
Mode types.String `tfsdk:"mode"`
}
28 changes: 28 additions & 0 deletions models/filesystem_snapshot_datasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package models

import "github.com/hashicorp/terraform-plugin-framework/types"

// FileSysteSnapshotDataSource is the schema for the FileSysteSnapshotDataSource datasource
type FileSysteSnapshotDataSource struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
FileSystemID types.String `tfsdk:"filesystem_id"`
FileSystemSnapshots []FileSystemDatasource `tfsdk:"filesystem_snapshots"`
}
67 changes: 67 additions & 0 deletions powerstore/datasource_filesystem_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package powerstore

import (
"terraform-provider-powerstore/models"

"github.com/dell/gopowerstore"
"github.com/hashicorp/terraform-plugin-framework/types"
)

// updateFileSystemState returns the list of filesystems
func updateFileSystemState(filesystems []gopowerstore.FileSystem) (response []models.FileSystemDatasource) {
for _, filesystem := range filesystems {
response = append(response, newFileSystem(filesystem))
}
return response
}

// newFileSystem returns a new filesystem
func newFileSystem(input gopowerstore.FileSystem) models.FileSystemDatasource {
return models.FileSystemDatasource{
AccessPolicy: types.StringValue(input.AccessPolicy),
AccessType: types.StringValue(input.AccessType),
ConfigType: types.StringValue(input.ConfigType),
Description: types.StringValue(input.Description),
ExpirationTimestamp: types.StringValue(input.ExpirationTimestamp),
FilesystemType: types.StringValue(string(input.FilesystemType)),
FolderRenamePolicy: types.StringValue(input.FolderRenamePolicy),
ID: types.StringValue(input.ID),
IsAsyncMTimeEnabled: types.BoolValue(input.IsAsyncMTimeEnabled),
IsSmbNoNotifyEnabled: types.BoolValue(input.IsSmbNoNotifyEnabled),
IsSmbNotifyOnAccessEnabled: types.BoolValue(input.IsSmbNotifyOnAccessEnabled),
IsSmbNotifyOnWriteEnabled: types.BoolValue(input.IsSmbNotifyOnWriteEnabled),
IsSmbOpLocksEnabled: types.BoolValue(input.IsSmbOpLocksEnabled),
IsSmbSyncWritesEnabled: types.BoolValue(input.IsSmbSyncWritesEnabled),
LockingPolicy: types.StringValue(input.LockingPolicy),
Name: types.StringValue(input.Name),
NasServerID: types.StringValue(input.NasServerID),
ParentID: types.StringValue(input.ParentID),
ProtectionPolicyID: types.StringValue(input.ProtectionPolicyID),
SizeTotal: types.Int64Value(int64(input.SizeTotal)),
SizeUsed: types.Int64Value(int64(input.SizeUsed)),
SmbNotifyOnChangeDirDepth: types.Int64Value(int64(input.SmbNotifyOnChangeDirDepth)),
FlrAttributes: models.FLRAttributesDatasource{
DefaultRetention: types.StringValue(input.FlrCreate.DefaultRetention),
MaximumRetention: types.StringValue(input.FlrCreate.MaximumRetention),
MinimumRetention: types.StringValue(input.FlrCreate.MinimumRetention),
Mode: types.StringValue(input.FlrCreate.Mode),
},
}
}
Loading

0 comments on commit b566baa

Please sign in to comment.