Skip to content

Commit

Permalink
adding replication rule datasource
Browse files Browse the repository at this point in the history
Signed-off-by: shenda1 <[email protected]>
  • Loading branch information
shenda1 committed Jan 3, 2025
1 parent b5565dd commit 6c96aa7
Show file tree
Hide file tree
Showing 13 changed files with 610 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ HOSTNAME=registry.terraform.io
NAMESPACE=dell
NAME=powerstore
BINARY=terraform-provider-${NAME}
VERSION=1.1.0
VERSION=1.2.0
OS_ARCH=linux_amd64

default: install
Expand Down
87 changes: 87 additions & 0 deletions docs/data-sources/replication_rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
# 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_replication_rule data source"
linkTitle: "powerstore_replication_rule"
page_title: "powerstore_replication_rule Data Source - powerstore"
subcategory: ""
description: |-
This datasource is used to query the existing replication rule from PowerStore array. The information fetched from this datasource can be used for getting the details for further processing in resource block.
---

# powerstore_replication_rule (Data Source)

This datasource is used to query the existing replication rule 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/akash/terraform-provider-powerstore/examples/data-sources/powerstore_replication_rule/data-source.tf"}}

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

### Optional

- `id` (String) Unique identifier of the replication rule. Conflicts with `name`.
- `name` (String) Name of the replication rule. Conflicts with `id`.

### Read-Only

- `replication_rules` (Attributes List) List of replication rules. (see [below for nested schema](#nestedatt--replication_rules))

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

Read-Only:

- `alert_threshold` (Number) The alert threshold for the replication rule.
- `id` (String) Unique identifier of the replication rule. Conflicts with `name`.
- `is_read_only` (Boolean) Indicates whether the replication rule is read-only.
- `is_replica` (Boolean) Indicates whether the replication rule is a replica.
- `managed_by` (String) The entity that manages the replication rule.
- `managed_by_id` (String) The ID of the managing entity.
- `name` (String) Name of the replication rule. Conflicts with `id`.
- `policies` (Attributes List) The protection policies associated with the replication rule. (see [below for nested schema](#nestedatt--replication_rules--policies))
- `remote_system` (Attributes) The remote system associated with the replication rule. (see [below for nested schema](#nestedatt--replication_rules--remote_system))
- `remote_system_id` (String) The ID of the remote system associated with the replication rule.
- `replication_session` (Attributes List) The replication session associated with the replication rule. (see [below for nested schema](#nestedatt--replication_rules--replication_session))
- `rpo` (String) The RPO (Recovery Point Objective) of the replication rule.

<a id="nestedatt--replication_rules--policies"></a>
### Nested Schema for `replication_rules.policies`

Read-Only:

- `id` (String) The ID of the protection policy.
- `name` (String) The name of the protection policy.


<a id="nestedatt--replication_rules--remote_system"></a>
### Nested Schema for `replication_rules.remote_system`

Read-Only:

- `id` (String) The ID of the remote system.
- `name` (String) The name of the remote system.


<a id="nestedatt--replication_rules--replication_session"></a>
### Nested Schema for `replication_rules.replication_session`

Read-Only:

- `id` (String) The ID of the replication session.
- `state` (String) The state of the replication session.
2 changes: 1 addition & 1 deletion docs/resources/replication_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ resource "powerstore_replication_rule" "test" {
}
//Below example is for import operation
/*resource "powerstore_snapshotrule" "terraform-provider-test-import" {
/*resource "powerstore_replication_rule" "terraform-provider-test-import" {
}*/
```

Expand Down
53 changes: 53 additions & 0 deletions examples/data-sources/powerstore_replication_rule/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
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 replication rules 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 replication rules
# If id or name is provided then it reads a particular replication rule with that id or name
# Only one of the attribute can be provided among id and name

# Get replication rule details using name
resource "powerstore_replication_rule" "test" {
name = "terraform_replication_rule"
rpo = "One_Hour"
remote_system_id = "db11abb3-789e-47f9-96b5-84b5374cbcd2"
alert_threshold = 1000
is_read_only = false
}

data "powerstore_replication_rule" "test" {
depends_on = [powerstore_replication_rule.test]
name = "terraform_replication_rule"
}

# Get replication rule details using ID
resource "powerstore_replication_rule" "test" {
name = "terraform_replication_rule"
rpo = "One_Hour"
remote_system_id = "db11abb3-789e-47f9-96b5-84b5374cbcd2"
alert_threshold = 1000
is_read_only = false
}

data "powerstore_replication_rule" "test" {
id = powerstore_replication_rule.test.id
}

output "replicationRule" {
value = data.powerstore_replication_rule.test.replication_rules
}
33 changes: 33 additions & 0 deletions examples/data-sources/powerstore_replication_rule/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_replication_rule/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"
}
2 changes: 1 addition & 1 deletion examples/resources/powerstore_replication_rule/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ resource "powerstore_replication_rule" "test" {
}

//Below example is for import operation
/*resource "powerstore_snapshotrule" "terraform-provider-test-import" {
/*resource "powerstore_replication_rule" "terraform-provider-test-import" {
}*/
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23
toolchain go1.23.2

require (
github.com/dell/gopowerstore v1.16.1-0.20241227083619-36c4ea66275f
github.com/dell/gopowerstore v1.16.1-0.20250103044727-b55f5083bb46
github.com/hashicorp/terraform-plugin-docs v0.20.1
github.com/hashicorp/terraform-plugin-framework v1.13.0
github.com/hashicorp/terraform-plugin-framework-validators v0.15.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ github.com/dell/gopowerstore v1.16.1-0.20241227064011-3c3808a39067 h1:FcRAYtZkdr
github.com/dell/gopowerstore v1.16.1-0.20241227064011-3c3808a39067/go.mod h1:RYodZ8GgJG5p85AviydL43Mt8ldcTqr5a+Cv+vqWacE=
github.com/dell/gopowerstore v1.16.1-0.20241227083619-36c4ea66275f h1:wr07YuRpeBb5sEgBahBGPWMZKomPC2TfbpBjMWMqwVE=
github.com/dell/gopowerstore v1.16.1-0.20241227083619-36c4ea66275f/go.mod h1:RYodZ8GgJG5p85AviydL43Mt8ldcTqr5a+Cv+vqWacE=
github.com/dell/gopowerstore v1.16.1-0.20250103044727-b55f5083bb46 h1:EdQbU3wBHUE1Jh/ucKbVkldi+l//jBg9qB0razB0G1A=
github.com/dell/gopowerstore v1.16.1-0.20250103044727-b55f5083bb46/go.mod h1:S3Gxw34FJbKNorL/OPe/DF+0pUSkBm6E6b4ka7m6cuo=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
Expand Down
41 changes: 41 additions & 0 deletions models/replication_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,44 @@ type ReplicationRule struct {
AlertThreshold types.Int64 `tfsdk:"alert_threshold"`
IsReadOnly types.Bool `tfsdk:"is_read_only"`
}

// ReplicationRuleDataSourceModel defines the model for replication rule data source
type ReplicationRuleDataSourceModel struct {
ReplicationRules []ReplicationRuleDataSource `tfsdk:"replication_rules"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
}

// ReplicationRuleDataSource defines the model for replication rule details
type ReplicationRuleDataSource struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
RPO types.String `tfsdk:"rpo"`
RemoteSystemID types.String `tfsdk:"remote_system_id"`
AlertThreshold types.Int64 `tfsdk:"alert_threshold"`
IsReadOnly types.Bool `tfsdk:"is_read_only"`
IsReplica types.Bool `tfsdk:"is_replica"`
ManagedBy types.String `tfsdk:"managed_by"`
ManagedByID types.String `tfsdk:"managed_by_id"`
Policies []Policy `tfsdk:"policies"`
RemoteSystem RemoteSystem `tfsdk:"remote_system"`
ReplicationSession []ReplicationSession `tfsdk:"replication_session"`
}

// Policy defines the model for policy
type Policy struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
}

// RemoteSystem defines the model for remote system
type RemoteSystem struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
}

// ReplicationSession defines the model for replication session
type ReplicationSession struct {
ID types.String `tfsdk:"id"`
State types.String `tfsdk:"state"`
}
Loading

0 comments on commit 6c96aa7

Please sign in to comment.