diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index aac2683c62..3590aad6c2 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -106,6 +106,7 @@ const ( Arg_VirtualOpticalDevice = "pi_virtual_optical_device" Arg_VolumeCloneName = "pi_volume_clone_name" Arg_VolumeCloneTaskID = "pi_volume_clone_task_id" + Arg_VolumeGroupAction = "pi_volume_group_action" Arg_VolumeGroupID = "pi_volume_group_id" Arg_VolumeGroupName = "pi_volume_group_name" Arg_VolumeID = "pi_volume_id" @@ -119,10 +120,6 @@ const ( Arg_VolumeType = "pi_volume_type" Arg_VTL = "vtl" - // Duplicate Arguments, will be removed as refactoring take course. - PIVolumeGroupID = "pi_volume_group_id" - PIVolumeOnboardingID = "pi_volume_onboarding_id" - // Attributes Attr_Access = "access" Attr_AccessConfig = "access_config" @@ -341,6 +338,7 @@ const ( Attr_ReservedCore = "reserved_core" Attr_ReservedCores = "reserved_cores" Attr_ReservedMemory = "reserved_memory" + Attr_Reset = "reset" Attr_ResultsOnboardedVolumes = "results_onboarded_volumes" Attr_ResultsVolumeOnboardingFailures = "results_volume_onboarding_failures" Attr_Rules = "rules" @@ -373,6 +371,7 @@ const ( Attr_SourceChecksum = "source_checksum" Attr_SourcePort = "source_port" Attr_SourceVolumeID = "source_volume_id" + Attr_Source = "source" Attr_SourceVolumeName = "source_volume_name" Attr_Speed = "speed" Attr_SPPPlacementGroupID = "spp_placement_group_id" @@ -381,12 +380,14 @@ const ( Attr_SPPPlacementGroupPolicy = "policy" Attr_SPPPlacementGroups = "spp_placement_groups" Attr_SSHKey = "ssh_key" + Attr_Start = "start" Attr_StartTime = "start_time" Attr_State = "state" Attr_Status = "status" Attr_StatusDescriptionErrors = "status_description_errors" Attr_StatusDetail = "status_detail" Attr_StorageConnection = "storage_connection" + Attr_Stop = "stop" Attr_StoragePool = "storage_pool" Attr_StoragePoolAffinity = "storage_pool_affinity" Attr_StoragePoolsCapacity = "storage_pools_capacity" @@ -476,6 +477,7 @@ const ( Allow = "allow" AntiAffinity = "anti-affinity" Attach = "attach" + Aux = "aux" BYOL = "byol" Capped = "capped" Critical = "CRITICAL" @@ -497,8 +499,9 @@ const ( HostGroup = "hostGroup" ICMP = "icmp" IPV4_Address = "ipv4-address" - NAG = "network-address-group" + Master = "master" MaxVolumeSupport = "maxVolumeSupport" + NAG = "network-address-group" Netweaver = "Netweaver" Network_Interface = "network-interface" None = "none" @@ -568,11 +571,6 @@ const ( State_Up = "up" State_Updating = "updating" State_VerifyResize = "verify_resize" - Status_Active = "ACTIVE" - Status_Deleting = "deleting" - Status_Error = "ERROR" - Status_Pending = "PENDING" - Status_Shutoff = "SHUTOFF" // Timeout values Timeout_Active = 2 * time.Minute @@ -593,6 +591,7 @@ const ( PIVolumeGroupName = "pi_volume_group_name" PIVolumeGroupConsistencyGroupName = "pi_consistency_group_name" PIVolumeGroupAction = "pi_volume_group_action" + PIVolumeOnboardingID = "pi_volume_onboarding_id" // VPN PIVPNConnectionId = "connection_id" diff --git a/ibm/service/power/resource_ibm_pi_volume_group_action.go b/ibm/service/power/resource_ibm_pi_volume_group_action.go index 6c7e7a2b4a..6ff42faea3 100644 --- a/ibm/service/power/resource_ibm_pi_volume_group_action.go +++ b/ibm/service/power/resource_ibm_pi_volume_group_action.go @@ -8,13 +8,13 @@ import ( "fmt" "time" - st "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" + "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/power-go-client/power/models" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/softlayer/softlayer-go/sl" ) @@ -30,90 +30,99 @@ func ResourceIBMPIVolumeGroupAction() *schema.Resource { Delete: schema.DefaultTimeout(15 * time.Minute), }, Schema: map[string]*schema.Schema{ - helpers.PICloudInstanceId: { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Cloud Instance ID - This is the service_instance_id.", - }, - PIVolumeGroupID: { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Volume Group ID", + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", + ForceNew: true, + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - PIVolumeGroupAction: { - Type: schema.TypeList, - Required: true, - ForceNew: true, - MaxItems: 1, - MinItems: 1, - Description: "Performs an action (start stop reset ) on a volume group(one at a time).", + Arg_VolumeGroupAction: { + Description: "Performs an action (start stop reset) on a volume group(one at a time).", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "start": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - ForceNew: true, + Attr_Start: { + Description: "Performs start action on a volume group.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "source": { - Type: schema.TypeString, + Attr_Source: { + Description: "Indicates the source of the action `master` or `aux`.", Required: true, - ValidateFunc: validate.ValidateAllowedStringValues([]string{"master", "aux"}), + Type: schema.TypeString, + ValidateFunc: validate.ValidateAllowedStringValues([]string{Master, Aux}), }, }, }, - }, - "stop": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, ForceNew: true, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + }, + Attr_Stop: { + Description: "Performs stop action on a volume group.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "access": { - Type: schema.TypeBool, - Required: true, + Attr_Access: { + Description: "Indicates the access mode of aux volumes.", + Required: true, + Type: schema.TypeBool, }, }, }, - }, - "reset": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, ForceNew: true, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + }, + Attr_Reset: { + Description: "Performs reset action on the volume group to update its value.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "status": { - Type: schema.TypeString, + Attr_Status: { + Description: "New status to be set for a volume group.", Required: true, - ValidateFunc: validate.ValidateAllowedStringValues([]string{"available"}), + Type: schema.TypeString, + ValidateFunc: validate.ValidateAllowedStringValues([]string{State_Available}), }, }, }, + ForceNew: true, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, }, }, }, + ForceNew: true, + MaxItems: 1, + MinItems: 1, + Required: true, + Type: schema.TypeList, + }, + Arg_VolumeGroupID: { + Description: "Volume Group ID", + ForceNew: true, + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - "volume_group_name": { + // Attributes + Attr_ReplicationStatus: { + Computed: true, + Description: "Volume Group Replication Status", Type: schema.TypeString, + }, + Attr_VolumeGroupName: { Computed: true, Description: "Volume Group ID", - }, - "volume_group_status": { Type: schema.TypeString, + }, + Attr_VolumeGroupStatus: { Computed: true, Description: "Volume Group Status", - }, - "replication_status": { Type: schema.TypeString, - Computed: true, - Description: "Volume Group Replication Status", }, }, } @@ -125,16 +134,16 @@ func resourceIBMPIVolumeGroupActionCreate(ctx context.Context, d *schema.Resourc return diag.FromErr(err) } - vgID := d.Get(PIVolumeGroupID).(string) - vgAction, err := expandVolumeGroupAction(d.Get(PIVolumeGroupAction).([]interface{})) + vgID := d.Get(Arg_VolumeGroupID).(string) + vgAction, err := expandVolumeGroupAction(d.Get(Arg_VolumeGroupAction).([]interface{})) if err != nil { return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) body := vgAction - client := st.NewIBMPIVolumeGroupClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIVolumeGroupClient(ctx, sess, cloudInstanceID) _, err = client.VolumeGroupAction(vgID, body) if err != nil { return diag.FromErr(err) @@ -161,16 +170,16 @@ func resourceIBMPIVolumeGroupActionRead(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - client := st.NewIBMPIVolumeGroupClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIVolumeGroupClient(ctx, sess, cloudInstanceID) vg, err := client.GetDetails(vgID) if err != nil { return diag.FromErr(err) } - d.Set("volume_group_name", vg.Name) - d.Set("volume_group_status", vg.Status) - d.Set("replication_status", vg.ReplicationStatus) + d.Set(Attr_VolumeGroupName, vg.Name) + d.Set(Attr_VolumeGroupStatus, vg.Status) + d.Set(Attr_ReplicationStatus, vg.ReplicationStatus) return nil } @@ -190,18 +199,18 @@ func expandVolumeGroupAction(data []interface{}) (*models.VolumeGroupAction, err vgAction := models.VolumeGroupAction{} action := data[0].(map[string]interface{}) - if v, ok := action["start"]; ok && len(v.([]interface{})) != 0 { - vgAction.Start = expandVolumeGroupStartAction(action["start"].([]interface{})) + if v, ok := action[Attr_Start]; ok && len(v.([]interface{})) != 0 { + vgAction.Start = expandVolumeGroupStartAction(action[Attr_Start].([]interface{})) return &vgAction, nil } - if v, ok := action["stop"]; ok && len(v.([]interface{})) != 0 { - vgAction.Stop = expandVolumeGroupStopAction(action["stop"].([]interface{})) + if v, ok := action[Attr_Stop]; ok && len(v.([]interface{})) != 0 { + vgAction.Stop = expandVolumeGroupStopAction(action[Attr_Stop].([]interface{})) return &vgAction, nil } - if v, ok := action["reset"]; ok && len(v.([]interface{})) != 0 { - vgAction.Reset = expandVolumeGroupResetAction(action["reset"].([]interface{})) + if v, ok := action[Attr_Reset]; ok && len(v.([]interface{})) != 0 { + vgAction.Reset = expandVolumeGroupResetAction(action[Attr_Reset].([]interface{})) return &vgAction, nil } return nil, fmt.Errorf("[ERROR] no pi_volume_group_action received") @@ -215,7 +224,7 @@ func expandVolumeGroupStartAction(start []interface{}) *models.VolumeGroupAction s := start[0].(map[string]interface{}) return &models.VolumeGroupActionStart{ - Source: sl.String(s["source"].(string)), + Source: sl.String(s[Attr_Source].(string)), } } @@ -227,7 +236,7 @@ func expandVolumeGroupStopAction(stop []interface{}) *models.VolumeGroupActionSt s := stop[0].(map[string]interface{}) return &models.VolumeGroupActionStop{ - Access: sl.Bool(s["access"].(bool)), + Access: sl.Bool(s[Attr_Access].(bool)), } } @@ -239,6 +248,6 @@ func expandVolumeGroupResetAction(reset []interface{}) *models.VolumeGroupAction s := reset[0].(map[string]interface{}) return &models.VolumeGroupActionReset{ - Status: sl.String(s["status"].(string)), + Status: sl.String(s[Attr_Status].(string)), } } diff --git a/ibm/service/power/resource_ibm_pi_volume_group_action_test.go b/ibm/service/power/resource_ibm_pi_volume_group_action_test.go index 6142e87374..1e5db25155 100644 --- a/ibm/service/power/resource_ibm_pi_volume_group_action_test.go +++ b/ibm/service/power/resource_ibm_pi_volume_group_action_test.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - st "github.com/IBM-Cloud/power-go-client/clients/instance" + "github.com/IBM-Cloud/power-go-client/clients/instance" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" @@ -68,7 +68,7 @@ func testAccCheckIBMPIVolumeGroupActionExists(n string) resource.TestCheckFunc { return err } cloudInstanceID, vgID := ids[0], ids[1] - client := st.NewIBMPIVolumeGroupClient(context.Background(), sess, cloudInstanceID) + client := instance.NewIBMPIVolumeGroupClient(context.Background(), sess, cloudInstanceID) _, err = client.Get(vgID) if err != nil { diff --git a/website/docs/r/pi_volume_group_action.html.markdown b/website/docs/r/pi_volume_group_action.html.markdown index 74926d43e9..e131edcc8f 100644 --- a/website/docs/r/pi_volume_group_action.html.markdown +++ b/website/docs/r/pi_volume_group_action.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: ibm_pi_volume_group_action" @@ -8,28 +7,31 @@ description: |- --- # ibm_pi_volume_group_action + Perfoms action on a volume group. For more information, about managing volume, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). ## Example usage + The following example attaches volume to a power systems virtual server instance. ```terraform -resource "ibm_pi_volume_group_action" "testacc_volume_group_action"{ - pi_cloud_instance_id = "" - pi_volume_group_id = "" - pi_volume_group_action { - stop { - access = true - } - } -} + resource "ibm_pi_volume_group_action" "testacc_volume_group_action" { + pi_cloud_instance_id = "" + pi_volume_group_id = "" + pi_volume_group_action { + stop { + access = true + } + } + } ``` -**Note** -* Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. -* If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: - * `region` - `lon` - * `zone` - `lon04` +### Notes + +- Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. +- If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: + - `region` - `lon` + - `zone` - `lon04` Example usage: @@ -47,28 +49,30 @@ ibm_pi_volume_group_action provides the following [timeouts](https://www.terrafo - **create** - (Default 15 minutes) Used for performing action on volume group. - **delete** - (Default 15 minutes) Used for deleting volume group action resource. -## Argument reference -Review the argument references that you can specify for your resource. +## Argument reference + +Review the argument references that you can specify for your resource. - `pi_cloud_instance_id` - (Required, Forces new resource, String) The GUID of the service instance associated with an account. - `pi_volume_group_action` - (Required, Forces new resource, List) Performs an action (`start` / `stop` / `reset`) on a volume group(one at a time). - Constraints: The maximum length is `1` items. The minimum length is `1` items. - Nested scheme for **pi_volume_group_action**: + Nested scheme for `pi_volume_group_action`: - `reset` - (Optional, Forces new resource, List) Performs reset action on the volume group to update its status value. - Constraints: The maximum length is `1` items. - Nested scheme for **reset**: + Nested scheme for `reset`: - `status` - (Required, String) New status to be set for a volume group. - `start` - (Optional, Forces new resource, List) Performs start action on a volume group. - Constraints: The maximum length is `1` items. - Nested scheme for **start**: + Nested scheme for `start`: - `source` - (Required, String) Indicates the source of the action `master` or `aux`. - `stop` - (Optional, Forces new resource, List) Performs stop action on a volume group. - Constraints: The maximum length is `1` items. - Nested scheme for **reset**: + Nested scheme for `reset`: - `access` - (Required, Boolean) Indicates the access mode of aux volumes. - `pi_volume_group_id` - (Required, Forces new resource, String) The ID of volume group on which action is to performed. ## Attribute reference + In addition to all argument reference list, you can access the following attribute reference after your resource is created. - `id` - (String) The unique identifier of the volume group action. The ID is composed of `/`. @@ -80,8 +84,8 @@ In addition to all argument reference list, you can access the following attribu The `ibm_pi_volume_group_action` resource can be imported by using `pi_cloud_instance_id` and `volume_group_id`. -**Example** +### Example -``` -$ terraform import ibm_pi_volume_group_action.example d7bec597-4726-451f-8a63-e62e6f19c32c/49fba6c9-23f8-40bc-9899-aca322ee7d5b +```bash +terraform import ibm_pi_volume_group_action.example d7bec597-4726-451f-8a63-e62e6f19c32c/49fba6c9-23f8-40bc-9899-aca322ee7d5b ```