From 16b84b2c7b8c9773d22ef77a33344113017c6123 Mon Sep 17 00:00:00 2001 From: Alexander-Kita Date: Fri, 11 Oct 2024 10:56:37 -0500 Subject: [PATCH] Add GRS Attributes/Arguments to pi_volume resource (#5668) --- ibm/service/power/ibm_pi_constants.go | 1 + ibm/service/power/resource_ibm_pi_volume.go | 22 +++++++++++++++++++++ website/docs/r/pi_volume.html.markdown | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 54a94699a7..a31fe72a95 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -63,6 +63,7 @@ const ( Arg_Remove = "pi_remove" Arg_Replicants = "pi_replicants" Arg_ReplicationEnabled = "pi_replication_enabled" + Arg_ReplicationSites = "pi_replication_sites" Arg_ReplicationPolicy = "pi_replication_policy" Arg_ReplicationScheme = "pi_replication_scheme" Arg_ResourceGroupID = "pi_resource_group_id" diff --git a/ibm/service/power/resource_ibm_pi_volume.go b/ibm/service/power/resource_ibm_pi_volume.go index 9a60e6ca08..365de4a32c 100644 --- a/ibm/service/power/resource_ibm_pi_volume.go +++ b/ibm/service/power/resource_ibm_pi_volume.go @@ -87,6 +87,14 @@ func ResourceIBMPIVolume() *schema.Resource { Optional: true, Type: schema.TypeBool, }, + Arg_ReplicationSites: { + Description: "List of replication sites for volume replication.", + Elem: &schema.Schema{Type: schema.TypeString}, + ForceNew: true, + Optional: true, + Set: schema.HashString, + Type: schema.TypeSet, + }, Arg_UserTags: { Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, @@ -183,6 +191,12 @@ func ResourceIBMPIVolume() *schema.Resource { Description: "The replication status of the volume.", Type: schema.TypeString, }, + Attr_ReplicationSites: { + Computed: true, + Description: "List of replication sites for volume replication.", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, + }, Attr_ReplicationType: { Computed: true, Description: "The replication type of the volume 'metro' or 'global'.", @@ -252,6 +266,13 @@ func resourceIBMPIVolumeCreate(ctx context.Context, d *schema.ResourceData, meta replicationEnabled := v.(bool) body.ReplicationEnabled = &replicationEnabled } + if v, ok := d.GetOk(Arg_ReplicationSites); ok { + if d.Get(Arg_ReplicationEnabled).(bool) { + body.ReplicationSites = flex.FlattenSet(v.(*schema.Set)) + } else { + return diag.Errorf("Replication (%s) must be enabled if replication sites are specified.", Arg_ReplicationEnabled) + } + } if ap, ok := d.GetOk(Arg_AffinityPolicy); ok { policy := ap.(string) body.AffinityPolicy = &policy @@ -355,6 +376,7 @@ func resourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta i d.Set(Attr_MirroringState, vol.MirroringState) d.Set(Attr_PrimaryRole, vol.PrimaryRole) d.Set(Arg_ReplicationEnabled, vol.ReplicationEnabled) + d.Set(Attr_ReplicationSites, vol.ReplicationSites) d.Set(Attr_ReplicationStatus, vol.ReplicationStatus) d.Set(Attr_ReplicationType, vol.ReplicationType) d.Set(Attr_VolumeStatus, vol.State) diff --git a/website/docs/r/pi_volume.html.markdown b/website/docs/r/pi_volume.html.markdown index 82206410b0..6737608882 100644 --- a/website/docs/r/pi_volume.html.markdown +++ b/website/docs/r/pi_volume.html.markdown @@ -59,6 +59,10 @@ Review the argument references that you can specify for your resource. - `pi_anti_affinity_volumes`- (Optional, String) List of volumes to base volume anti-affinity policy against; required if requesting `anti-affinity` and `pi_anti_affinity_instances` is not provided. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. - `pi_replication_enabled` - (Optional, Boolean) Indicates if the volume should be replication enabled or not. + + **Note:** `replication_sites` will be populated automatically with default sites if set to true and sites are not specified. + +- `pi_replication_sites` - (Optional, List) List of replication sites for volume replication. Must set `pi_replication_enabled` to true to use. - `pi_user_tags` - (Optional, List) The user tags attached to this resource. - `pi_volume_name` - (Required, String) The name of the volume. - `pi_volume_pool` - (Optional, String) Volume pool where the volume will be created; if provided then `pi_affinity_policy` values will be ignored. @@ -82,6 +86,7 @@ In addition to all argument reference list, you can access the following attribu - `mirroring_state` - (String) Mirroring state for replication enabled volume. - `primary_role` - (String) Indicates whether `master`/`auxiliary` volume is playing the primary role. - `replication_status` - (String) The replication status of the volume. +- `replication_sites` - (List) List of replication sites for volume replication. - `replication_type` - (String) The replication type of the volume `metro` or `global`. - `volume_id` - (String) The unique identifier of the volume. - `volume_status` - (String) The status of the volume.