Skip to content

Commit 6520f56

Browse files
authored
RCG Actions Resource (#238)
1 parent 25f83b9 commit 6520f56

14 files changed

+675
-3
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
title: "powerflex_replication_consistency_group_action resource"
2+
linkTitle: "powerflex_replication_consistency_group_action"
3+
page_title: "powerflex_replication_consistency_group_action Resource - powerflex"
4+
subcategory: ""
5+
description: |-
6+
This resource is used to execute actions on the Replication Consistency Group entity of the PowerFlex Array.
7+
---
8+
9+
# powerflex_replication_consistency_group_action (Resource)
10+
11+
This resource is used to execute actions on the Replication Consistency Group entity of the PowerFlex Array.
12+
13+
## Example Usage
14+
15+
```terraform
16+
/*
17+
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
18+
19+
Licensed under the Mozilla Public License Version 2.0 (the "License");
20+
you may not use this file except in compliance with the License.
21+
You may obtain a copy of the License at
22+
23+
http://mozilla.org/MPL/2.0/
24+
25+
26+
Unless required by applicable law or agreed to in writing, software
27+
distributed under the License is distributed on an "AS IS" BASIS,
28+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29+
See the License for the specific language governing permissions and
30+
limitations under the License.
31+
*/
32+
33+
terraform {
34+
required_providers {
35+
powerflex = {
36+
source = "registry.terraform.io/dell/powerflex"
37+
}
38+
}
39+
}
40+
41+
provider "powerflex" {
42+
username = var.username
43+
password = var.password
44+
endpoint = var.endpoint
45+
insecure = true
46+
timeout = 120
47+
}
48+
49+
// Resource to manage lifecycle
50+
resource "terraform_data" "always_run" {
51+
input = timestamp()
52+
}
53+
54+
data "powerflex_replication_consistancy_group" "rcg_filter" {
55+
filter {
56+
name = [var.replication_consistancy_group_name]
57+
}
58+
}
59+
60+
resource "powerflex_replication_consistency_group_action" "example" {
61+
# Required
62+
63+
# Id of the replication consistancy group
64+
id = data.powerflex_replication_consistancy_group.rcg_filter.replication_consistency_group_details[0].id
65+
66+
# Action to be performed on the replication consistancy group.
67+
# Options are Failover, Restore, Sync, Reverse, Switchover and Snapshot (Default is Sync)
68+
action = var.action
69+
70+
// This will allow terraform create process to trigger each time we run terraform apply.
71+
lifecycle {
72+
replace_triggered_by = [
73+
terraform_data.always_run
74+
]
75+
}
76+
}
77+
```
78+
79+
After the execution of above resource block, resource would have been created on the PowerFlex array. For more information, please check the terraform state file.
80+
81+
<!-- schema generated by tfplugindocs -->
82+
## Schema
83+
84+
### Required
85+
86+
- `id` (String) Replication Consistency Group ID
87+
88+
### Optional
89+
90+
- `action` (String) Replication Consistency Group Action
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
3+
4+
Licensed under the Mozilla Public License Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://mozilla.org/MPL/2.0/
9+
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
username = "example_user"
19+
password = "example_password"
20+
endpoint = "example_endpoint"
21+
replication_consistancy_group_name = "rcg_name"
22+
# Options are Failover, Restore, Sync, Reverse, Switchover and Snapshot (Default is Sync)
23+
action = "Sync"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
3+
4+
Licensed under the Mozilla Public License Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://mozilla.org/MPL/2.0/
9+
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
terraform {
19+
required_providers {
20+
powerflex = {
21+
source = "registry.terraform.io/dell/powerflex"
22+
}
23+
}
24+
}
25+
26+
provider "powerflex" {
27+
username = var.username
28+
password = var.password
29+
endpoint = var.endpoint
30+
insecure = true
31+
timeout = 120
32+
}
33+
34+
// Resource to manage lifecycle
35+
resource "terraform_data" "always_run" {
36+
input = timestamp()
37+
}
38+
39+
data "powerflex_replication_consistancy_group" "rcg_filter" {
40+
filter {
41+
name = [var.replication_consistancy_group_name]
42+
}
43+
}
44+
45+
resource "powerflex_replication_consistency_group_action" "example" {
46+
# Required
47+
48+
# Id of the replication consistancy group
49+
id = data.powerflex_replication_consistancy_group.rcg_filter.replication_consistency_group_details[0].id
50+
51+
# Action to be performed on the replication consistancy group.
52+
# Options are Failover, Restore, Sync, Reverse, Switchover and Snapshot (Default is Sync)
53+
action = var.action
54+
55+
// This will allow terraform create process to trigger each time we run terraform apply.
56+
lifecycle {
57+
replace_triggered_by = [
58+
terraform_data.always_run
59+
]
60+
}
61+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
3+
4+
Licensed under the Mozilla Public License Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://mozilla.org/MPL/2.0/
9+
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
variable "username" {
18+
type = string
19+
description = "Stores the username of PowerFlex host."
20+
}
21+
22+
variable "password" {
23+
type = string
24+
description = "Stores the password of PowerFlex host."
25+
}
26+
27+
variable "endpoint" {
28+
type = string
29+
description = "Stores the endpoint of PowerFlex host. eg: https://10.1.1.1:443, here 443 is port where API requests are getting accepted"
30+
}
31+
32+
variable "replication_consistancy_group_name" {
33+
type = string
34+
description = "The Replication Consistency Group name."
35+
}
36+
37+
variable "action" {
38+
type = string
39+
description = "The Replication Consistency Group action to be preformed. Options Failover, Restore, Sync, Reverse, Switchover and Snapshot"
40+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ toolchain go1.23.2
77
require (
88
github.com/bramvdbogaerde/go-scp v1.5.0
99
github.com/bytedance/mockey v1.2.13
10-
github.com/dell/goscaleio v1.17.1-0.20241106091455-02b95d6c772d
10+
github.com/dell/goscaleio v1.17.1-0.20241106124128-c895c8717b22
1111
github.com/hashicorp/terraform-plugin-framework v1.11.0
1212
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
1313
github.com/hashicorp/terraform-plugin-go v0.23.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG
3131
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3232
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3333
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
34-
github.com/dell/goscaleio v1.17.1-0.20241106091455-02b95d6c772d h1:TL0HemIn8zHnJwwx1TvKP80SmGqa8FtQ88oodhnZ0Fs=
35-
github.com/dell/goscaleio v1.17.1-0.20241106091455-02b95d6c772d/go.mod h1:dB1a2wXevGps25VAda+6WDp+NTUdgMZXvQVM0YOBpX8=
34+
github.com/dell/goscaleio v1.17.1-0.20241106124128-c895c8717b22 h1:Ox4ra5FUj1LWL3M1ibMxPCzWLue2yRzYdhSuRsLYEDc=
35+
github.com/dell/goscaleio v1.17.1-0.20241106124128-c895c8717b22/go.mod h1:dB1a2wXevGps25VAda+6WDp+NTUdgMZXvQVM0YOBpX8=
3636
github.com/dylanmei/iso8601 v0.1.0 h1:812NGQDBcqquTfH5Yeo7lwR0nzx/cKdsmf3qMjPURUI=
3737
github.com/dylanmei/iso8601 v0.1.0/go.mod h1:w9KhXSgIyROl1DefbMYIE7UVSIvELTbMrCfx+QkYnoQ=
3838
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=

powerflex/constants/constants.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,22 @@ const (
2323

2424
// DeleteIsNotSupportedErrorMsg is the Error message for delete not supported
2525
DeleteIsNotSupportedErrorMsg = "Delete is not supported for this resource"
26+
27+
// Sync is the sync constant
28+
Sync = "Sync"
29+
30+
// Restore is the restore constant
31+
Restore = "Restore"
32+
33+
// Failover is the failover constant
34+
Failover = "Failover"
35+
36+
// Reverse is the reverse constant
37+
Reverse = "Reverse"
38+
39+
// Switchover is the switchover constant
40+
Switchover = "Switchover"
41+
42+
// Snapshot is the snapshot constant
43+
Snapshot = "Snapshot"
2644
)

powerflex/helper/replication_helper.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"reflect"
2424
"strings"
2525
sshClient "terraform-provider-powerflex/client"
26+
"terraform-provider-powerflex/powerflex/constants"
2627
"terraform-provider-powerflex/powerflex/models"
2728

2829
"github.com/dell/goscaleio"
@@ -552,3 +553,28 @@ func RCGUpdates(client *goscaleio.Client, state models.ReplicationConsistancyGro
552553
}
553554
return nil
554555
}
556+
557+
// RCGDoAction do an action on the RCG
558+
func RCGDoAction(client *goscaleio.Client, actions models.ReplicationConsistancyGroupAction) error {
559+
rcgClient := goscaleio.NewReplicationConsistencyGroup(client)
560+
rcgClient.ReplicationConsistencyGroup.ID = actions.ID.ValueString()
561+
562+
switch actions.Action.ValueString() {
563+
case constants.Sync:
564+
_, err := rcgClient.ExecuteSyncOnReplicationGroup()
565+
return err
566+
case constants.Restore:
567+
return rcgClient.ExecuteRestoreOnReplicationGroup()
568+
case constants.Failover:
569+
return rcgClient.ExecuteFailoverOnReplicationGroup()
570+
case constants.Reverse:
571+
return rcgClient.ExecuteReverseOnReplicationGroup()
572+
case constants.Switchover:
573+
return rcgClient.ExecuteSwitchoverOnReplicationGroup(false)
574+
case constants.Snapshot:
575+
_, err := rcgClient.CreateReplicationConsistencyGroupSnapshot()
576+
return err
577+
default:
578+
return fmt.Errorf("Invalid Action %s", actions.Action.ValueString())
579+
}
580+
}

powerflex/models/replication.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,9 @@ type ReplicationConsistancyGroupFilter struct {
155155
RemoteActivityState []types.String `tfsdk:"remote_activity_state"`
156156
InactiveReason []types.Int64 `tfsdk:"inactive_reason"`
157157
}
158+
159+
// ReplicationConsistancyGroupAction defines the model for ReplicationConsistancyGroupAction
160+
type ReplicationConsistancyGroupAction struct {
161+
ID types.String `tfsdk:"id"`
162+
Action types.String `tfsdk:"action"`
163+
}

powerflex/provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,5 +318,6 @@ func (p *powerflexProvider) Resources(_ context.Context) []func() resource.Resou
318318
NewNvmeHostResource,
319319
ReplicationConsistencyGroupResource,
320320
PeerSystemResource,
321+
ReplicationConsistencyGroupActionResource,
321322
}
322323
}

0 commit comments

Comments
 (0)