Skip to content

Commit

Permalink
Sync bitbucket and GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
carchi8py committed Aug 15, 2023
1 parent 3499916 commit e07c297
Show file tree
Hide file tree
Showing 13 changed files with 872 additions and 3 deletions.
85 changes: 85 additions & 0 deletions docs/data-sources/storage_snapshot_policies_data_source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
page_title: "netapp-ontap_storage_snapshot_policies_data_source Data Source - terraform-provider-netapp-ontap"
subcategory: "storage"
description: |-
Retrieves Snapshot Policies information
---

# NetApp Ontap snapshot policies data source

Snapshot Policies data source

## Example Usage
```terraform
data "netapp-ontap_storage_snapshot_policies_data_source" "storage_snapshot_policies" {
# required to know which system to interface with
cx_profile_name = "cluster4"
filter = {
name = "ansible*"
}
}
```


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

### Required

- `cx_profile_name` (String) Connection profile name

### Optional

- `filter` (Attributes) (see [below for nested schema](#nestedatt--filter))

### Read-Only

- `storage_snapshot_policies` (Attributes List) (see [below for nested schema](#nestedatt--storage_snapshot_policies))

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

Optional:

- `name` (String) SnapshotPolicy name
- `svm_name` (String) SnapshotPolicy vserver name


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

Required:

- `cx_profile_name` (String) Connection profile name
- `name` (String) SnapshotPolicy name

Read-Only:

- `comment` (String) A comment associated with the Snapshot copy policy
- `copies` (Attributes List) Snapshot copy (see [below for nested schema](#nestedatt--storage_snapshot_policies--copies))
- `enabled` (Boolean) Is the Snapshot copy policy enabled?
- `svm_name` (String) IPInterface vserver name
- `uuid` (String) SnapshotPolicy UUID

<a id="nestedatt--storage_snapshot_policies--copies"></a>
### Nested Schema for `storage_snapshot_policies.copies`

Required:

- `schedule` (Attributes) Schedule at which Snapshot copies are captured on the volume (see [below for nested schema](#nestedatt--storage_snapshot_policies--copies--schedule))

Read-Only:

- `count` (Number) The number of Snapshot copies to maintain for this schedule
- `prefix` (String) The prefix to use while creating Snapshot copies at regular intervals
- `retention_period` (String) The retention period of Snapshot copies for this schedule
- `snapmirror_label` (String) Label for SnapMirror operations

<a id="nestedatt--storage_snapshot_policies--copies--schedule"></a>
### Nested Schema for `storage_snapshot_policies.copies.schedule`

Read-Only:

- `name` (String) Some common schedules already defined in the system are hourly, daily, weekly, at 15 minute intervals, and at 5 minute intervals. Snapshot copy policies with custom schedules can be referenced


59 changes: 59 additions & 0 deletions docs/data-sources/storage_snapshot_policy_data_source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
page_title: "netapp-ontap_snapshot_policy_data_source Data Source - terraform-provider-netapp-ontap"
subcategory: "storage"
description: |-
Retrieves Snapshot Policy information
---

# NetApp Ontap snapshot policy data source

Snapshot Policy data source

## Example Usage
```terraform
data "netapp-ontap_storage_snapshot_policy_data_source" "storage_snapshot_policy" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "ansible2"
}
```


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

### Required

- `cx_profile_name` (String) Connection profile name
- `name` (String) SnapshotPolicy name

### Read-Only

- `comment` (String) A comment associated with the Snapshot copy policy
- `copies` (Attributes List) Snapshot copy (see [below for nested schema](#nestedatt--copies))
- `enabled` (Boolean) Is the Snapshot copy policy enabled?
- `svm_name` (String) IPInterface vserver name
- `uuid` (String) SnapshotPolicy UUID

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

Required:

- `schedule` (Attributes) Schedule at which Snapshot copies are captured on the volume (see [below for nested schema](#nestedatt--copies--schedule))

Read-Only:

- `count` (Number) The number of Snapshot copies to maintain for this schedule
- `prefix` (String) The prefix to use while creating Snapshot copies at regular intervals
- `retention_period` (String) The retention period of Snapshot copies for this schedule
- `snapmirror_label` (String) Label for SnapMirror operations

<a id="nestedatt--copies--schedule"></a>
### Nested Schema for `copies.schedule`

Read-Only:

- `name` (String) Some common schedules already defined in the system are hourly, daily, weekly, at 15 minute intervals, and at 5 minute intervals. Snapshot copy policies with custom schedules can be referenced


Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "netapp-ontap_storage_snapshot_policies_data_source" "storage_snapshot_policies" {
# required to know which system to interface with
cx_profile_name = "cluster4"
filter = {
name = "ansible*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
terraform {
required_providers {
netapp-ontap = {
source = "NetApp/netapp-ontap"
version = "0.0.1"
}
}
}


provider "netapp-ontap" {
# A connection profile defines how to interface with an ONTAP cluster or svm.
# At least one is required.
connection_profiles = [
{
name = "cluster1"
hostname = "********219"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster2"
hostname = "********222"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster3"
hostname = "10.193.176.159"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster4"
hostname = "10.193.180.108"
username = var.username
password = var.password
validate_certs = var.validate_certs
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Terraform will prompt for values, unless a tfvars file is present.
variable "username" {
type = string
}
variable "password" {
type = string
sensitive = true
}
variable "validate_certs" {
type = bool
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "netapp-ontap_storage_snapshot_policy_data_source" "storage_snapshot_policy" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "ansible2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
terraform {
required_providers {
netapp-ontap = {
source = "NetApp/netapp-ontap"
version = "0.0.1"
}
}
}


provider "netapp-ontap" {
# A connection profile defines how to interface with an ONTAP cluster or svm.
# At least one is required.
connection_profiles = [
{
name = "cluster1"
hostname = "********219"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster2"
hostname = "********222"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster3"
hostname = "10.193.176.159"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster4"
hostname = "10.193.180.108"
username = var.username
password = var.password
validate_certs = var.validate_certs
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Terraform will prompt for values, unless a tfvars file is present.
variable "username" {
type = string
}
variable "password" {
type = string
sensitive = true
}
variable "validate_certs" {
type = bool
}
33 changes: 31 additions & 2 deletions internal/interfaces/storage_snapshot_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ type Schedule struct {
Name string `mapstructure:"name"`
}

// SnapshotPolicyGetDataFilterModel describes filter model
type SnapshotPolicyGetDataFilterModel struct {
Name string `mapstructure:"name"`
SVMName string `mapstructure:"svm.name"`
}

// GetSnapshotPolicy to get storage_snapshot_policy info
func GetSnapshotPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, id string) (*SnapshotPolicyGetDataModelONTAP, error) {
api := "storage/snapshot-policies"
Expand All @@ -71,11 +77,34 @@ func GetSnapshotPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient
return &dataONTAP, nil
}

// GetSnapshotPolicyByName to get storage_snapshot_policy info
func GetSnapshotPolicyByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string) (*SnapshotPolicyGetDataModelONTAP, error) {
api := "storage/snapshot-policies"
query := r.NewQuery()
query.Set("name", name)
query.Fields([]string{"name", "svm.name", "copies", "scope", "enabled", "comment"})
statusCode, response, err := r.GetNilOrOneRecord(api, query, nil)
if err == nil && response == nil {
err = fmt.Errorf("no response for GET %s", api)
}
if err != nil {
return nil, errorHandler.MakeAndReportError("error reading storage_snapshot_policy info", fmt.Sprintf("error on GET %s: %s, statusCode %d", api, err, statusCode))
}

var dataONTAP SnapshotPolicyGetDataModelONTAP
if err := mapstructure.Decode(response, &dataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError(fmt.Sprintf("failed to decode response from GET %s", api),
fmt.Sprintf("error: %s, statusCode %d, response %#v", err, statusCode, response))
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read storage_snapshot_policy data source: %#v", dataONTAP))
return &dataONTAP, nil
}

// GetSnapshotPolicies to get storage_snapshot_policy info for all resources matching a filter
func GetSnapshotPolicies(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *SnapshotPolicyGetDataModelONTAP) ([]SnapshotPolicyGetDataModelONTAP, error) {
func GetSnapshotPolicies(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *SnapshotPolicyGetDataFilterModel) ([]SnapshotPolicyGetDataModelONTAP, error) {
api := "storage/snapshot-policies"
query := r.NewQuery()
query.Fields([]string{"name", "svm.name", "scope", "enabled"})
query.Fields([]string{"name", "svm.name", "copies", "scope", "enabled", "comment"})
if filter != nil {
var filterMap map[string]interface{}
if err := mapstructure.Decode(filter, &filterMap); err != nil {
Expand Down
Loading

0 comments on commit e07c297

Please sign in to comment.