Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Snapshot DS (PowerScale 1.1) #60

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions docs/data-sources/snapshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
# Copyright (c) 2023 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: "powerscale_snapshot data source"
linkTitle: "powerscale_snapshot"
page_title: "powerscale_snapshot Data Source - terraform-provider-powerscale"
subcategory: ""
description: |-
This datasource is used to query the existing Snapshots from PowerScale array. The information fetched from this datasource can be used for getting the details / for further processing in resource block. PowerScale Snapshots is a logical pointer to data that is stored on a cluster at a specific point in time.
---

# powerscale_snapshot (Data Source)

This datasource is used to query the existing Snapshots from PowerScale array. The information fetched from this datasource can be used for getting the details / for further processing in resource block. PowerScale Snapshots is a logical pointer to data that is stored on a cluster at a specific point in time.

## Example Usage

```terraform
/*
Copyright (c) 2023 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.
*/

# Returns all of the PowerScale snapshots and their details
# PowerScale Snapshots is a logical pointer to data that is stored on a cluster at a specific point in time.
data "powerscale_snapshot" "all" {
}

output "powerscale_snapshot_data_all" {
value = data.powerscale_snapshot.all
}

# Returns a subset of the PowerScale snapshots based on the path provided in the `paths` filter block and their details
data "powerscale_snapshot" "test" {
# Optional path of the filesystem, this will return all the snapshots related to that particular path
filter {
path = "/ifs/tfacc_file_system_test"
}
}

output "powerscale_snapshot" {
value = data.powerscale_snapshot.test
}

# After the successful execution of above said block, We can see the output value by executing 'terraform output' command.
# Also, we can use the fetched information by the variable data.powerscale_snapshot.all
```

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

### Optional

- `filter` (Block, Optional) (see [below for nested schema](#nestedblock--filter))

### Read-Only

- `id` (String) Identifier
- `snapshots_details` (Attributes List) List of Snapshots (see [below for nested schema](#nestedatt--snapshots_details))

<a id="nestedblock--filter"></a>
### Nested Schema for `filter`

Optional:

- `path` (String)


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

Read-Only:

- `alias` (String) The name of the alias, none for real snapshots.
- `created` (Number) The Unix Epoch time the snapshot was created.
- `expires` (Number) The Unix Epoch time the snapshot will expire and be eligible for automatic deletion.
- `has_locks` (Boolean) True if the snapshot has one or more locks present see, see the locks subresource of a snapshot for a list of lock.
- `id` (Number) The system ID given to the snapshot. This is useful for tracking the status of delete pending snapshots.
- `name` (String) The user or system supplied snapshot name. This will be null for snapshots pending delete.
- `path` (String) The /ifs path snapshotted.
- `pct_filesystem` (Number) Percentage of /ifs used for storing this snapshot.
- `pct_reserve` (Number) Percentage of configured snapshot reserved used for storing this snapshot.
- `schedule` (String) The name of the schedule used to create this snapshot, if applicable.
- `shadow_bytes` (Number) The amount of shadow bytes referred to by this snapshot.
- `size` (Number) The amount of storage in bytes used to store this snapshot.
- `state` (String) Snapshot state.
- `target_id` (Number) The ID of the snapshot pointed to if this is an alias. 18446744073709551615 (max uint64) is returned for an alias to the live filesystem.
- `target_name` (String) The name of the snapshot pointed to if this is an alias.
40 changes: 40 additions & 0 deletions examples/data-sources/powerscale_snapshot/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright (c) 2023 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.
*/

# Returns all of the PowerScale snapshots and their details
# PowerScale Snapshots is a logical pointer to data that is stored on a cluster at a specific point in time.
data "powerscale_snapshot" "all" {
}

output "powerscale_snapshot_data_all" {
value = data.powerscale_snapshot.all
}

# Returns a subset of the PowerScale snapshots based on the path provided in the `paths` filter block and their details
data "powerscale_snapshot" "test" {
# Optional path of the filesystem, this will return all the snapshots related to that particular path
filter {
path = "/ifs/tfacc_file_system_test"
}
}

output "powerscale_snapshot" {
value = data.powerscale_snapshot.test
}

# After the successful execution of above said block, We can see the output value by executing 'terraform output' command.
# Also, we can use the fetched information by the variable data.powerscale_snapshot.all
30 changes: 30 additions & 0 deletions examples/data-sources/powerscale_snapshot/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright (c) 2023 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 {
powerscale = {
source = "registry.terraform.io/dell/powerscale"
}
}
}

provider "powerscale" {
username = var.username
password = var.password
endpoint = var.endpoint
insecure = var.insecure
}
4 changes: 4 additions & 0 deletions powerscale/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ limitations under the License.
package constants

const (

// ReadSnapshotErrorMessage specifies error details occurred while reading Snapshots.
ReadSnapshotErrorMessage = "Could not read snapshots"

// ReadAccessZoneErrorMsg specifies error details occurred while reading Access Zones.
ReadAccessZoneErrorMsg = "Could not read access zones "

Expand Down
45 changes: 45 additions & 0 deletions powerscale/helper/snapshot_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright (c) 2023 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 helper

import (
"context"
powerscale "dell/powerscale-go-client"
"terraform-provider-powerscale/client"
"terraform-provider-powerscale/powerscale/models"

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

// GetAllSnapshots returns the full list of snapshots.
func GetAllSnapshots(ctx context.Context, client *client.Client) ([]powerscale.V1SnapshotSnapshotExtended, error) {
result, _, err := client.PscaleOpenAPIClient.SnapshotApi.ListSnapshotv1SnapshotSnapshots(ctx).Execute()
return result.GetSnapshots(), err
}

// SnapshotDetailMapper Does the mapping from response to model.
func SnapshotDetailMapper(ctx context.Context, snap powerscale.V1SnapshotSnapshotExtended) (models.SnapshotDetailModel, error) {
model := models.SnapshotDetailModel{}
err := CopyFields(ctx, &snap, &model)
if err != nil {
return model, err
}
model.ID = types.Int64Value(int64(snap.Id))
model.TargetID = types.Int64Value(int64(snap.TargetId))
return model, nil
}
67 changes: 67 additions & 0 deletions powerscale/models/snapshot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright (c) 2023 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"

// SnapshotDataSourceModel describes the data source data model.
type SnapshotDataSourceModel struct {
ID types.String `tfsdk:"id"`
Snapshots []SnapshotDetailModel `tfsdk:"snapshots_details"`
// filter
SnapshotFilter *SnapshotFilterType `tfsdk:"filter"`
}

// SnapshotFilterType describes the filter data model.
type SnapshotFilterType struct {
Path types.String `tfsdk:"path"`
nikitajoshi1 marked this conversation as resolved.
Show resolved Hide resolved
}

// SnapshotDetailModel details of the individual snapshot.
type SnapshotDetailModel struct {
// The name of the alias, none for real snapshots.
Alias types.String `tfsdk:"alias"`
// The Unix Epoch time the snapshot was created.
Created types.Int64 `tfsdk:"created"`
// The Unix Epoch time the snapshot will expire and be eligible for automatic deletion.
Expires types.Int64 `tfsdk:"expires"`
// True if the snapshot has one or more locks present see, see the locks subresource of a snapshot for a list of locks.
HasLocks types.Bool `tfsdk:"has_locks"`
// The system ID given to the snapshot. This is useful for tracking the status of delete pending snapshots.
ID types.Int64 `tfsdk:"id"`
// The user or system supplied snapshot name. This will be null for snapshots pending delete.
Name types.String `tfsdk:"name"`
// The /ifs path snapshotted.
Path types.String `tfsdk:"path"`
// Percentage of /ifs used for storing this snapshot.
PctFilesystem types.Number `tfsdk:"pct_filesystem"`
// Percentage of configured snapshot reserved used for storing this snapshot.
PctReserve types.Number `tfsdk:"pct_reserve"`
// The name of the schedule used to create this snapshot, if applicable.
Schedule types.String `tfsdk:"schedule"`
// The amount of shadow bytes referred to by this snapshot.
ShadowBytes types.Int64 `tfsdk:"shadow_bytes"`
// The amount of storage in bytes used to store this snapshot.
Size types.Int64 `tfsdk:"size"`
// Snapshot state.
State types.String `tfsdk:"state"`
// The ID of the snapshot pointed to if this is an alias. 18446744073709551615 (max uint64) is returned for an alias to the live filesystem.
TargetID types.Int64 `tfsdk:"target_id"`
// The name of the snapshot pointed to if this is an alias.
TargetName types.String `tfsdk:"target_name"`
}
4 changes: 3 additions & 1 deletion powerscale/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package provider

import (
"context"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"terraform-provider-powerscale/client"

"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"

"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
Expand Down Expand Up @@ -177,6 +178,7 @@ func (p *PscaleProvider) DataSources(ctx context.Context) []func() datasource.Da
NewAdsProviderDataSource,
NewUserGroupDataSource,
NewNfsExportDataSource,
NewSnapshotDataSource,
}
}

Expand Down
Loading