From cbeacd5aa72005a1ffdf0a98092373d207fbcc5c Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Thu, 7 Nov 2024 11:32:48 -0600 Subject: [PATCH] Refactor Cloud Connection Network Attach --- ..._ibm_pi_cloud_connection_network_attach.go | 70 +++++++++---------- ...ud_connection_network_attach.html.markdown | 34 +++++---- 2 files changed, 50 insertions(+), 54 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection_network_attach.go b/ibm/service/power/resource_ibm_pi_cloud_connection_network_attach.go index 24b472ed2c..0934dc4b12 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection_network_attach.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection_network_attach.go @@ -9,17 +9,12 @@ import ( "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - 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/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" -) - -const ( - PICloudConnectionNetworkId = "pi_network_id" + "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" ) func ResourceIBMPICloudConnectionNetworkAttach() *schema.Resource { @@ -35,24 +30,27 @@ func ResourceIBMPICloudConnectionNetworkAttach() *schema.Resource { }, Schema: map[string]*schema.Schema{ - // Required Attributes - helpers.PICloudInstanceId: { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "PI cloud instance ID", + // Arguments + Arg_CloudConnectionID: { + Description: "Cloud Connection ID", + ForceNew: true, + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - helpers.PICloudConnectionId: { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Cloud Connection ID", + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", + ForceNew: true, + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - PICloudConnectionNetworkId: { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Network ID to attach to this cloud connection", + Arg_NetworkID: { + Description: "Network ID to attach to this cloud connection", + ForceNew: true, + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, }, } @@ -64,12 +62,12 @@ func resourceIBMPICloudConnectionNetworkAttachCreate(ctx context.Context, d *sch return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - cloudConnectionID := d.Get(helpers.PICloudConnectionId).(string) - networkID := d.Get(PICloudConnectionNetworkId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + cloudConnectionID := d.Get(Arg_CloudConnectionID).(string) + networkID := d.Get(Arg_NetworkID).(string) - client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) - jobClient := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) + jobClient := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID) _, jobReference, err := client.AddNetwork(cloudConnectionID, networkID) if err != nil { @@ -97,9 +95,9 @@ func resourceIBMPICloudConnectionNetworkAttachRead(ctx context.Context, d *schem cloudConnectionID := parts[1] networkID := parts[2] - d.Set(helpers.PICloudInstanceId, cloudInstanceID) - d.Set(helpers.PICloudConnectionId, cloudConnectionID) - d.Set(PICloudConnectionNetworkId, networkID) + d.Set(Arg_CloudInstanceID, cloudInstanceID) + d.Set(Arg_CloudConnectionID, cloudConnectionID) + d.Set(Arg_NetworkID, networkID) return nil } @@ -119,8 +117,8 @@ func resourceIBMPICloudConnectionNetworkAttachDelete(ctx context.Context, d *sch cloudConnectionID := parts[1] networkID := parts[2] - client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) - jobClient := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) + jobClient := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID) _, jobReference, err := client.DeleteNetwork(cloudConnectionID, networkID) if err != nil { @@ -128,7 +126,7 @@ func resourceIBMPICloudConnectionNetworkAttachDelete(ctx context.Context, d *sch return diag.FromErr(err) } if jobReference != nil { - _, err = waitForIBMPIJobCompleted(ctx, jobClient, *jobReference.ID, d.Timeout(schema.TimeoutUpdate)) + _, err = waitForIBMPIJobCompleted(ctx, jobClient, *jobReference.ID, d.Timeout(schema.TimeoutDelete)) if err != nil { return diag.FromErr(err) } diff --git a/website/docs/r/pi_cloud_connection_network_attach.html.markdown b/website/docs/r/pi_cloud_connection_network_attach.html.markdown index d562c7770d..129c95be9c 100644 --- a/website/docs/r/pi_cloud_connection_network_attach.html.markdown +++ b/website/docs/r/pi_cloud_connection_network_attach.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_cloud_connection_network_attach" @@ -9,7 +8,7 @@ description: |- # ibm_pi_cloud_connection_network_attach -Attach, detach Network to a Cloud Connection for a Power Systems Virtual Server. For more information, about IBM power virtual server cloud, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). +Attach, and detach a network to a cloud connection for a Power Systems Virtual Server. For more information, about IBM power virtual server cloud, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). ## Example usage @@ -17,20 +16,20 @@ The following example enables you attach a network to a cloud connection: ```terraform resource "ibm_pi_cloud_connection_network_attach" "example" { - pi_cloud_instance_id = "" pi_cloud_connection_id = "" - pi_network_id = "" + pi_cloud_instance_id = "" + pi_network_id = "" } ``` -**Note** +### 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` +- 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: +Example usage: ```terraform provider "ibm" { @@ -43,30 +42,29 @@ resource "ibm_pi_cloud_connection_network_attach" "example" { The `ibm_pi_cloud_connection_network_attach` provides the following [timeouts](https://www.terraform.io/docs/language/resources/syntax.html) configuration options: -- **Create** The attach of network to the cloud connection is considered failed if no response is received for 30 minutes. -- **Delete** The detach of network from the cloud connection is considered failed if no response is received for 30 minutes. +- **create** - (Default 30 minutes) Used for attaching a network from a cloud connection. +- **delete** - (Default 30 minutes) Used for detaching a network from a cloud connection. ## Argument reference -Review the argument references that you can specify for your resource. +Review the argument references that you can specify for your resource. -- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. - `pi_cloud_connection_id` - (Required, String) The Cloud Connection ID. +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. - `pi_network_id` - (Required, String) The Network ID to attach to this cloud connection. - ## 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 cloud connection network attachment. +- `id` - (String) The unique identifier of cloud connection network attachment. The ID is composed of `//`. ## Import The `ibm_pi_cloud_connection_network_attach` can be imported by using `pi_cloud_instance_id`, `pi_cloud_connection_id` and `pi_network_id`. -**Example** +### Example ```sh -$ terraform import ibm_pi_cloud_connection_network_attach.example d7bec597-4726-451f-8a63-e62e6f19c32c/cea6651a-bc0a-4438-9f8a-a0770bbf3ebb/4726d7be-c597-4438-9f8a-cea6651abc0a +terraform import ibm_pi_cloud_connection_network_attach.example d7bec597-4726-451f-8a63-e62e6f19c32c/cea6651a-bc0a-4438-9f8a-a0770bbf3ebb/4726d7be-c597-4438-9f8a-cea6651abc0a ```