From 9a33f74bcfe02037183bf11d6e66acaf37800fce Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Wed, 21 Feb 2024 21:33:32 +0530 Subject: [PATCH 01/10] Refactor codee --- ibm/service/power/ibm_pi_constants.go | 17 ++ .../power/resource_ibm_pi_cloud_connection.go | 146 +++++++++--------- .../docs/r/pi_cloud_connection.html.markdown | 4 +- 3 files changed, 91 insertions(+), 76 deletions(-) diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index e8c354ef909..bd024e64dd5 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -4,7 +4,17 @@ import "time" const ( // Arguments + Arg_CloudConnectionClassicEnabled = "pi_cloud_connection_clasic_enabled" + Arg_CloudConnectionClassicGreCidr = "pi_cloud_connection_gre_cidr" + Arg_CloudConnectionClassicGreDest = "pi_cloud_connection_gre_destination_address" + Arg_CloudConnectionGlobalRouting = "pi_cloud_connection_global_routing" + Arg_CloudConnectionMetered = "pi_cloud_connection_metered" Arg_CloudConnectionName = "pi_cloud_connection_name" + Arg_CloudConnectionNetworks = "pi_cloud_connection_networks" + Arg_CloudConnectionSpeed = "pi_cloud_connection_speed" + Arg_CloudConnectionVPCEnabled = "pi_cloud_connection_enabled" + Arg_CloudConnectionVPCCRNs = "pi_cloud_connection_vpc_crns" + Arg_CloudConnectionTransitEnabled = "pi_cloud_connection_transit_enabled" Arg_CloudInstanceID = "pi_cloud_instance_id" Arg_ImageName = "pi_image_name" Arg_InstanceName = "pi_instance_name" @@ -45,6 +55,13 @@ const ( Attr_BootVolumeID = "boot_volume_id" Attr_Bootable = "bootable" Attr_CIDR = "cidr" + Attr_CloudConnectionId = "cloud_connection_id" + Attr_CloudConnectionIBMIPAddress = "ibm_ip_address" + Attr_CloudConnectionClassicGreSource = "gre_source_address" + Attr_CloudConnectionMode = "conncection_mode" + Attr_CloudConnectionUserIPAddress = "user_ip_address" + Attr_CloudConnectionPort = "port" + Attr_CloudConnectionStatus = "status" Attr_CPUs = "cpus" Attr_CRN = "crn" Attr_Capabilities = "capabilities" diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection.go b/ibm/service/power/resource_ibm_pi_cloud_connection.go index a8a17718915..9a985014fd1 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection.go @@ -10,17 +10,15 @@ import ( "regexp" "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/clients/instance" "github.com/IBM-Cloud/power-go-client/errors" - "github.com/IBM-Cloud/power-go-client/helpers" "github.com/IBM-Cloud/power-go-client/power/client/p_cloud_cloud_connections" "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/flex" "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" ) var ( @@ -48,17 +46,17 @@ func ResourceIBMPICloudConnection() *schema.Resource { Schema: map[string]*schema.Schema{ // Required Attributes - helpers.PICloudInstanceId: { + Arg_CloudInstanceID: { Type: schema.TypeString, Required: true, Description: "PI cloud instance ID", }, - helpers.PICloudConnectionName: { + Arg_CloudConnectionName: { Type: schema.TypeString, Required: true, Description: "Name of the cloud connection", }, - helpers.PICloudConnectionSpeed: { + Arg_CloudConnectionSpeed: { Type: schema.TypeInt, Required: true, ValidateFunc: validate.ValidateAllowedIntValues([]int{50, 100, 200, 500, 1000, 2000, 5000, 10000}), @@ -66,58 +64,58 @@ func ResourceIBMPICloudConnection() *schema.Resource { }, // Optional Attributes - helpers.PICloudConnectionGlobalRouting: { + Arg_CloudConnectionGlobalRouting: { Type: schema.TypeBool, Optional: true, Default: false, Description: "Enable global routing for this cloud connection", }, - helpers.PICloudConnectionMetered: { + Arg_CloudConnectionMetered: { Type: schema.TypeBool, Optional: true, Default: false, Description: "Enable metered for this cloud connection", }, - helpers.PICloudConnectionNetworks: { + Arg_CloudConnectionNetworks: { Type: schema.TypeSet, Optional: true, Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, Description: "Set of Networks to attach to this cloud connection", }, - helpers.PICloudConnectionClassicEnabled: { + Arg_CloudConnectionClassicEnabled: { Type: schema.TypeBool, Optional: true, Default: false, Description: "Enable classic endpoint destination", }, - helpers.PICloudConnectionClassicGreCidr: { + Arg_CloudConnectionClassicGreCidr: { Type: schema.TypeString, Optional: true, - RequiredWith: []string{helpers.PICloudConnectionClassicEnabled, helpers.PICloudConnectionClassicGreDest}, + RequiredWith: []string{Arg_CloudConnectionClassicEnabled, Arg_CloudConnectionClassicGreDest}, Description: "GRE network in CIDR notation", }, - helpers.PICloudConnectionClassicGreDest: { + Arg_CloudConnectionClassicGreDest: { Type: schema.TypeString, Optional: true, - RequiredWith: []string{helpers.PICloudConnectionClassicEnabled, helpers.PICloudConnectionClassicGreCidr}, + RequiredWith: []string{Arg_CloudConnectionClassicEnabled, Arg_CloudConnectionClassicGreCidr}, Description: "GRE destination IP address", }, - helpers.PICloudConnectionVPCEnabled: { + Arg_CloudConnectionVPCEnabled: { Type: schema.TypeBool, Optional: true, Default: false, - RequiredWith: []string{helpers.PICloudConnectionVPCCRNs}, + RequiredWith: []string{Arg_CloudConnectionVPCCRNs}, Description: "Enable VPC for this cloud connection", }, - helpers.PICloudConnectionVPCCRNs: { + Arg_CloudConnectionVPCCRNs: { Type: schema.TypeSet, Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, - RequiredWith: []string{helpers.PICloudConnectionVPCEnabled}, + RequiredWith: []string{Arg_CloudConnectionVPCEnabled}, Description: "Set of VPCs to attach to this cloud connection", }, - PICloudConnectionTransitEnabled: { + Arg_CloudConnectionTransitEnabled: { Type: schema.TypeBool, Optional: true, Default: false, @@ -125,37 +123,37 @@ func ResourceIBMPICloudConnection() *schema.Resource { }, //Computed Attributes - PICloudConnectionId: { + Attr_CloudConnectionId: { Type: schema.TypeString, Computed: true, Description: "Cloud connection ID", }, - PICloudConnectionStatus: { + Attr_CloudConnectionStatus: { Type: schema.TypeString, Computed: true, Description: "Link status", }, - PICloudConnectionIBMIPAddress: { + Attr_CloudConnectionIBMIPAddress: { Type: schema.TypeString, Computed: true, Description: "IBM IP address", }, - PICloudConnectionUserIPAddress: { + Attr_CloudConnectionUserIPAddress: { Type: schema.TypeString, Computed: true, Description: "User IP address", }, - PICloudConnectionPort: { + Attr_CloudConnectionPort: { Type: schema.TypeString, Computed: true, Description: "Port", }, - PICloudConnectionClassicGreSource: { + Attr_CloudConnectionClassicGreSource: { Type: schema.TypeString, Computed: true, Description: "GRE auto-assigned source IP address", }, - PICloudConnectionConnectionMode: { + Attr_CloudConnectionMode: { Type: schema.TypeString, Computed: true, Description: "Type of service the gateway is attached to", @@ -170,37 +168,37 @@ func resourceIBMPICloudConnectionCreate(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - name := d.Get(helpers.PICloudConnectionName).(string) - speed := int64(d.Get(helpers.PICloudConnectionSpeed).(int)) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + name := d.Get(Arg_CloudConnectionName).(string) + speed := int64(d.Get(Arg_CloudConnectionSpeed).(int)) body := &models.CloudConnectionCreate{ Name: &name, Speed: &speed, } - if v, ok := d.GetOk(helpers.PICloudConnectionGlobalRouting); ok { + if v, ok := d.GetOk(Arg_CloudConnectionGlobalRouting); ok { body.GlobalRouting = v.(bool) } - if v, ok := d.GetOk(helpers.PICloudConnectionMetered); ok { + if v, ok := d.GetOk(Arg_CloudConnectionMetered); ok { body.Metered = v.(bool) } // networks - if v, ok := d.GetOk(helpers.PICloudConnectionNetworks); ok && v.(*schema.Set).Len() > 0 { + if v, ok := d.GetOk(Arg_CloudConnectionNetworks); ok && v.(*schema.Set).Len() > 0 { body.Subnets = flex.ExpandStringList(v.(*schema.Set).List()) } // classic - if v, ok := d.GetOk(helpers.PICloudConnectionClassicEnabled); ok { + if v, ok := d.GetOk(Arg_CloudConnectionClassicEnabled); ok { classicEnabled := v.(bool) classic := &models.CloudConnectionEndpointClassicUpdate{ Enabled: classicEnabled, } gre := &models.CloudConnectionGRETunnelCreate{} - if v, ok := d.GetOk(helpers.PICloudConnectionClassicGreCidr); ok { + if v, ok := d.GetOk(Arg_CloudConnectionClassicGreCidr); ok { greCIDR := v.(string) gre.Cidr = &greCIDR classic.Gre = gre } - if v, ok := d.GetOk(helpers.PICloudConnectionClassicGreDest); ok { + if v, ok := d.GetOk(Arg_CloudConnectionClassicGreDest); ok { greDest := v.(string) gre.DestIPAddress = &greDest classic.Gre = gre @@ -209,12 +207,12 @@ func resourceIBMPICloudConnectionCreate(ctx context.Context, d *schema.ResourceD } // VPC - if v, ok := d.GetOk(helpers.PICloudConnectionVPCEnabled); ok { + if v, ok := d.GetOk(Arg_CloudConnectionVPCEnabled); ok { vpcEnabled := v.(bool) vpc := &models.CloudConnectionEndpointVPC{ Enabled: vpcEnabled, } - if v, ok := d.GetOk(helpers.PICloudConnectionVPCCRNs); ok && v.(*schema.Set).Len() > 0 { + if v, ok := d.GetOk(Arg_CloudConnectionVPCCRNs); ok && v.(*schema.Set).Len() > 0 { vpcIds := flex.ExpandStringList(v.(*schema.Set).List()) vpcs := make([]*models.CloudConnectionVPC, len(vpcIds)) for i, vpcId := range vpcIds { @@ -233,7 +231,7 @@ func resourceIBMPICloudConnectionCreate(ctx context.Context, d *schema.ResourceD body.TransitEnabled = v.(bool) } - client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) cloudConnection, cloudConnectionJob, err := client.Create(body) if err != nil { if vpcUnavailable.Match([]byte(err.Error())) { @@ -255,7 +253,7 @@ func resourceIBMPICloudConnectionCreate(ctx context.Context, d *schema.ResourceD jobID := *cloudConnectionJob.JobRef.ID - client := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID) _, err = waitForIBMPIJobCompleted(ctx, client, jobID, d.Timeout(schema.TimeoutCreate)) if err != nil { return diag.FromErr(err) @@ -279,39 +277,39 @@ func resourceIBMPICloudConnectionUpdate(ctx context.Context, d *schema.ResourceD cloudInstanceID := parts[0] cloudConnectionID := parts[1] - ccName := d.Get(helpers.PICloudConnectionName).(string) - ccSpeed := int64(d.Get(helpers.PICloudConnectionSpeed).(int)) + ccName := d.Get(Arg_CloudConnectionName).(string) + ccSpeed := int64(d.Get(Arg_CloudConnectionSpeed).(int)) - client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) - jobClient := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) + jobClient := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID) - if d.HasChangesExcept(helpers.PICloudConnectionNetworks) { + if d.HasChangesExcept(Arg_CloudConnectionNetworks) { body := &models.CloudConnectionUpdate{ Name: &ccName, Speed: &ccSpeed, } - if v, ok := d.GetOk(helpers.PICloudConnectionGlobalRouting); ok { + if v, ok := d.GetOk(Arg_CloudConnectionGlobalRouting); ok { globalRouting := v.(bool) body.GlobalRouting = &globalRouting } - if v, ok := d.GetOk(helpers.PICloudConnectionMetered); ok { + if v, ok := d.GetOk(Arg_CloudConnectionMetered); ok { metered := v.(bool) body.Metered = &metered } // classic - if v, ok := d.GetOk(helpers.PICloudConnectionClassicEnabled); ok { + if v, ok := d.GetOk(Arg_CloudConnectionClassicEnabled); ok { classicEnabled := v.(bool) classic := &models.CloudConnectionEndpointClassicUpdate{ Enabled: classicEnabled, } gre := &models.CloudConnectionGRETunnelCreate{} - if v, ok := d.GetOk(helpers.PICloudConnectionClassicGreCidr); ok { + if v, ok := d.GetOk(Arg_CloudConnectionClassicGreCidr); ok { greCIDR := v.(string) gre.Cidr = &greCIDR classic.Gre = gre } - if v, ok := d.GetOk(helpers.PICloudConnectionClassicGreDest); ok { + if v, ok := d.GetOk(Arg_CloudConnectionClassicGreDest); ok { greDest := v.(string) gre.DestIPAddress = &greDest classic.Gre = gre @@ -325,12 +323,12 @@ func resourceIBMPICloudConnectionUpdate(ctx context.Context, d *schema.ResourceD body.Classic = classic } // vpc - if v, ok := d.GetOk(helpers.PICloudConnectionVPCEnabled); ok { + if v, ok := d.GetOk(Arg_CloudConnectionVPCEnabled); ok { vpcEnabled := v.(bool) vpc := &models.CloudConnectionEndpointVPC{ Enabled: vpcEnabled, } - if v, ok := d.GetOk(helpers.PICloudConnectionVPCCRNs); ok && v.(*schema.Set).Len() > 0 { + if v, ok := d.GetOk(Arg_CloudConnectionVPCCRNs); ok && v.(*schema.Set).Len() > 0 { vpcIds := flex.ExpandStringList(v.(*schema.Set).List()) vpcs := make([]*models.CloudConnectionVPC, len(vpcIds)) for i, vpcId := range vpcIds { @@ -369,8 +367,8 @@ func resourceIBMPICloudConnectionUpdate(ctx context.Context, d *schema.ResourceD } } } - if d.HasChange(helpers.PICloudConnectionNetworks) { - oldRaw, newRaw := d.GetChange(helpers.PICloudConnectionNetworks) + if d.HasChange(Arg_CloudConnectionNetworks) { + oldRaw, newRaw := d.GetChange(Arg_CloudConnectionNetworks) old := oldRaw.(*schema.Set) new := newRaw.(*schema.Set) @@ -423,7 +421,7 @@ func resourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceDat cloudInstanceID := parts[0] cloudConnectionID := parts[1] - client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) cloudConnection, err := client.Get(cloudConnectionID) if err != nil { uErr := errors.Unwrap(err) @@ -437,17 +435,17 @@ func resourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceDat return diag.FromErr(err) } - d.Set(PICloudConnectionId, cloudConnection.CloudConnectionID) - d.Set(helpers.PICloudConnectionName, cloudConnection.Name) - d.Set(helpers.PICloudConnectionGlobalRouting, cloudConnection.GlobalRouting) - d.Set(helpers.PICloudConnectionMetered, cloudConnection.Metered) - d.Set(PICloudConnectionIBMIPAddress, cloudConnection.IbmIPAddress) - d.Set(PICloudConnectionUserIPAddress, cloudConnection.UserIPAddress) - d.Set(PICloudConnectionStatus, cloudConnection.LinkStatus) - d.Set(PICloudConnectionPort, cloudConnection.Port) - d.Set(helpers.PICloudConnectionSpeed, cloudConnection.Speed) - d.Set(helpers.PICloudInstanceId, cloudInstanceID) - d.Set(PICloudConnectionConnectionMode, cloudConnection.ConnectionMode) + d.Set(Attr_CloudConnectionId, cloudConnection.CloudConnectionID) + d.Set(Arg_CloudConnectionName, cloudConnection.Name) + d.Set(Arg_CloudConnectionGlobalRouting, cloudConnection.GlobalRouting) + d.Set(Arg_CloudConnectionMetered, cloudConnection.Metered) + d.Set(Attr_CloudConnectionIBMIPAddress, cloudConnection.IbmIPAddress) + d.Set(Attr_CloudConnectionUserIPAddress, cloudConnection.UserIPAddress) + d.Set(Attr_CloudConnectionStatus, cloudConnection.LinkStatus) + d.Set(Attr_CloudConnectionPort, cloudConnection.Port) + d.Set(Arg_CloudConnectionSpeed, cloudConnection.Speed) + d.Set(Arg_CloudInstanceID, cloudInstanceID) + d.Set(Attr_CloudConnectionMode, cloudConnection.ConnectionMode) if cloudConnection.Networks != nil { networks := make([]string, 0) for _, ccNetwork := range cloudConnection.Networks { @@ -455,23 +453,23 @@ func resourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceDat networks = append(networks, *ccNetwork.NetworkID) } } - d.Set(helpers.PICloudConnectionNetworks, networks) + d.Set(Arg_CloudConnectionNetworks, networks) } if cloudConnection.Classic != nil { - d.Set(helpers.PICloudConnectionClassicEnabled, cloudConnection.Classic.Enabled) + d.Set(Arg_CloudConnectionClassicEnabled, cloudConnection.Classic.Enabled) if cloudConnection.Classic.Gre != nil { - d.Set(helpers.PICloudConnectionClassicGreDest, cloudConnection.Classic.Gre.DestIPAddress) + d.Set(Arg_CloudConnectionClassicGreDest, cloudConnection.Classic.Gre.DestIPAddress) d.Set(PICloudConnectionClassicGreSource, cloudConnection.Classic.Gre.SourceIPAddress) } } if cloudConnection.Vpc != nil { - d.Set(helpers.PICloudConnectionVPCEnabled, cloudConnection.Vpc.Enabled) + d.Set(Arg_CloudConnectionVPCEnabled, cloudConnection.Vpc.Enabled) if cloudConnection.Vpc.Vpcs != nil && len(cloudConnection.Vpc.Vpcs) > 0 { vpcCRNs := make([]string, len(cloudConnection.Vpc.Vpcs)) for i, vpc := range cloudConnection.Vpc.Vpcs { vpcCRNs[i] = *vpc.VpcID } - d.Set(helpers.PICloudConnectionVPCCRNs, vpcCRNs) + d.Set(Arg_CloudConnectionVPCCRNs, vpcCRNs) } } @@ -491,7 +489,7 @@ func resourceIBMPICloudConnectionDelete(ctx context.Context, d *schema.ResourceD cloudInstanceID := parts[0] cloudConnectionID := parts[1] - client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) _, err = client.Get(cloudConnectionID) if err != nil { uErr := errors.Unwrap(err) @@ -514,7 +512,7 @@ func resourceIBMPICloudConnectionDelete(ctx context.Context, d *schema.ResourceD if deleteJob != nil { jobID := *deleteJob.ID - client := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID) _, err = waitForIBMPIJobCompleted(ctx, client, jobID, d.Timeout(schema.TimeoutDelete)) if err != nil { return diag.FromErr(err) diff --git a/website/docs/r/pi_cloud_connection.html.markdown b/website/docs/r/pi_cloud_connection.html.markdown index 2bd92842395..fa27c8d97ba 100644 --- a/website/docs/r/pi_cloud_connection.html.markdown +++ b/website/docs/r/pi_cloud_connection.html.markdown @@ -10,7 +10,7 @@ description: |- Create, update, or delete for a Power Systems Virtual Server cloud connection. 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). -**Note** +**Notes** `Cloud connection are not supported in new workspaces in DAL10 data center.` ## Example usage @@ -25,7 +25,7 @@ resource "ibm_pi_cloud_connection" "cloud_connection" { } ``` -**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: From 55081a6df022158b29b7978bddf940b14b73bb0e Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Fri, 8 Mar 2024 08:27:39 +0530 Subject: [PATCH 02/10] Sort stanza --- .../power/resource_ibm_pi_cloud_connection.go | 84 +++++++++---------- .../resource_ibm_pi_cloud_connection_test.go | 17 ++-- 2 files changed, 49 insertions(+), 52 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection.go b/ibm/service/power/resource_ibm_pi_cloud_connection.go index 9a985014fd1..086a050c7bc 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection.go @@ -45,118 +45,116 @@ func ResourceIBMPICloudConnection() *schema.Resource { }, Schema: map[string]*schema.Schema{ - // Required Attributes - Arg_CloudInstanceID: { - Type: schema.TypeString, - Required: true, - Description: "PI cloud instance ID", - }, + // Arguments Arg_CloudConnectionName: { - Type: schema.TypeString, - Required: true, Description: "Name of the cloud connection", + Required: true, + Type: schema.TypeString, }, Arg_CloudConnectionSpeed: { - Type: schema.TypeInt, + Description: "Speed of the cloud connection (speed in megabits per second)", Required: true, + Type: schema.TypeInt, ValidateFunc: validate.ValidateAllowedIntValues([]int{50, 100, 200, 500, 1000, 2000, 5000, 10000}), - Description: "Speed of the cloud connection (speed in megabits per second)", }, - - // Optional Attributes Arg_CloudConnectionGlobalRouting: { - Type: schema.TypeBool, - Optional: true, Default: false, Description: "Enable global routing for this cloud connection", - }, - Arg_CloudConnectionMetered: { + Optional: true, Type: schema.TypeBool, + }, + Arg_CloudInstanceID: { + Description: "PI cloud instance ID", + Required: true, + Type: schema.TypeString, + }, + Arg_CloudConnectionClassicEnabled: { + Default: false, + Description: "Enable classic endpoint destination", Optional: true, + Type: schema.TypeBool, + }, + Arg_CloudConnectionMetered: { Default: false, Description: "Enable metered for this cloud connection", + Optional: true, + Type: schema.TypeBool, }, Arg_CloudConnectionNetworks: { - Type: schema.TypeSet, - Optional: true, Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, Description: "Set of Networks to attach to this cloud connection", - }, - Arg_CloudConnectionClassicEnabled: { - Type: schema.TypeBool, + Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, - Default: false, - Description: "Enable classic endpoint destination", + Type: schema.TypeSet, }, Arg_CloudConnectionClassicGreCidr: { - Type: schema.TypeString, + Description: "GRE network in CIDR notation", Optional: true, RequiredWith: []string{Arg_CloudConnectionClassicEnabled, Arg_CloudConnectionClassicGreDest}, - Description: "GRE network in CIDR notation", + Type: schema.TypeString, }, Arg_CloudConnectionClassicGreDest: { - Type: schema.TypeString, + Description: "GRE destination IP address", Optional: true, RequiredWith: []string{Arg_CloudConnectionClassicEnabled, Arg_CloudConnectionClassicGreCidr}, - Description: "GRE destination IP address", + Type: schema.TypeString, }, Arg_CloudConnectionVPCEnabled: { - Type: schema.TypeBool, - Optional: true, Default: false, - RequiredWith: []string{Arg_CloudConnectionVPCCRNs}, Description: "Enable VPC for this cloud connection", + Optional: true, + RequiredWith: []string{Arg_CloudConnectionVPCCRNs}, + Type: schema.TypeBool, }, Arg_CloudConnectionVPCCRNs: { - Type: schema.TypeSet, - Optional: true, + Description: "Set of VPCs to attach to this cloud connection", Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, RequiredWith: []string{Arg_CloudConnectionVPCEnabled}, - Description: "Set of VPCs to attach to this cloud connection", + Type: schema.TypeSet, }, Arg_CloudConnectionTransitEnabled: { - Type: schema.TypeBool, - Optional: true, Default: false, Description: "Enable transit gateway for this cloud connection", + Type: schema.TypeBool, + Optional: true, }, //Computed Attributes Attr_CloudConnectionId: { - Type: schema.TypeString, Computed: true, Description: "Cloud connection ID", + Type: schema.TypeString, }, Attr_CloudConnectionStatus: { - Type: schema.TypeString, Computed: true, Description: "Link status", + Type: schema.TypeString, }, Attr_CloudConnectionIBMIPAddress: { - Type: schema.TypeString, Computed: true, Description: "IBM IP address", + Type: schema.TypeString, }, Attr_CloudConnectionUserIPAddress: { - Type: schema.TypeString, Computed: true, Description: "User IP address", + Type: schema.TypeString, }, Attr_CloudConnectionPort: { - Type: schema.TypeString, Computed: true, Description: "Port", + Type: schema.TypeString, }, Attr_CloudConnectionClassicGreSource: { - Type: schema.TypeString, Computed: true, Description: "GRE auto-assigned source IP address", + Type: schema.TypeString, }, Attr_CloudConnectionMode: { - Type: schema.TypeString, Computed: true, Description: "Type of service the gateway is attached to", + Type: schema.TypeString, }, }, } diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go index a70f85763f4..040fc89148e 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go @@ -13,15 +13,14 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "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" ) func TestAccIBMPICloudConnectionbasic(t *testing.T) { - name := fmt.Sprintf("tf-cloudconnection-%d", acctest.RandIntRange(10, 100)) + name := fmt.Sprintf("tf-cloudconnection-%d", accteinstanceRandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -55,7 +54,7 @@ func testAccCheckIBMPICloudConnectionDestroy(s *terraform.State) error { if err != nil { return err } - client := st.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) + client := instanceNewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) _, err = client.Get(cloudConnectionID) if err == nil { return fmt.Errorf("Cloud Connection still exists: %s", rs.Primary.ID) @@ -90,7 +89,7 @@ func testAccCheckIBMPICloudConnectionExists(n string) resource.TestCheckFunc { if err != nil { return err } - client := st.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) + client := instanceNewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) _, err = client.Get(cloudConnectionID) if err != nil { @@ -118,7 +117,7 @@ func testAccCheckIBMPICloudConnectionConfig(name string) string { } func TestAccIBMPICloudConnectionNetworks(t *testing.T) { - name := fmt.Sprintf("tf-cloudconnection-%d", acctest.RandIntRange(10, 100)) + name := fmt.Sprintf("tf-cloudconnection-%d", accteinstanceRandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -195,7 +194,7 @@ func testAccCheckIBMPICloudConnectionNetworkUpdateConfig(name string) string { } func TestAccIBMPICloudConnectionClassic(t *testing.T) { - name := fmt.Sprintf("tf-cloudconnection-%d", acctest.RandIntRange(10, 100)) + name := fmt.Sprintf("tf-cloudconnection-%d", accteinstanceRandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -230,7 +229,7 @@ func testAccCheckIBMPICloudConnectionClassicConfig(name string) string { } func TestAccIBMPICloudConnectionVPC(t *testing.T) { - name := fmt.Sprintf("tf-cloudconnection-%d", acctest.RandIntRange(10, 100)) + name := fmt.Sprintf("tf-cloudconnection-%d", accteinstanceRandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -269,7 +268,7 @@ func testAccCheckIBMPICloudConnectionVPCConfig(name string) string { } func TestAccIBMPICloudConnectionTransitGateway(t *testing.T) { - name := fmt.Sprintf("tf-cloudconnection-%d", acctest.RandIntRange(10, 100)) + name := fmt.Sprintf("tf-cloudconnection-%d", accteinstanceRandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, From 345527f290df70ba059e5ff68b6aa015c4ce7382 Mon Sep 17 00:00:00 2001 From: Diptipowervs <152427968+Diptipowervs@users.noreply.github.com> Date: Mon, 11 Mar 2024 10:17:25 +0530 Subject: [PATCH 03/10] Update ibm/service/power/ibm_pi_constants.go Co-authored-by: michaelkad <45772690+michaelkad@users.noreply.github.com> --- ibm/service/power/ibm_pi_constants.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index bd024e64dd5..a7f7054aca0 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -55,13 +55,13 @@ const ( Attr_BootVolumeID = "boot_volume_id" Attr_Bootable = "bootable" Attr_CIDR = "cidr" - Attr_CloudConnectionId = "cloud_connection_id" - Attr_CloudConnectionIBMIPAddress = "ibm_ip_address" - Attr_CloudConnectionClassicGreSource = "gre_source_address" - Attr_CloudConnectionMode = "conncection_mode" - Attr_CloudConnectionUserIPAddress = "user_ip_address" - Attr_CloudConnectionPort = "port" - Attr_CloudConnectionStatus = "status" +Attr_CloudConnectionClassicGreSource = "gre_source_address" +Attr_CloudConnectionIBMIPAddress = "ibm_ip_address" +Attr_CloudConnectionId = "cloud_connection_id" +Attr_CloudConnectionMode = "conncection_mode" +Attr_CloudConnectionPort = "port" +Attr_CloudConnectionStatus = "status" +Attr_CloudConnectionUserIPAddress = "user_ip_address" Attr_CPUs = "cpus" Attr_CRN = "crn" Attr_Capabilities = "capabilities" From 752b120433364c3ebdc76b62ecb8ca2ac6fae47c Mon Sep 17 00:00:00 2001 From: Diptipowervs <152427968+Diptipowervs@users.noreply.github.com> Date: Mon, 11 Mar 2024 10:18:16 +0530 Subject: [PATCH 04/10] Update ibm/service/power/resource_ibm_pi_cloud_connection_test.go Co-authored-by: michaelkad <45772690+michaelkad@users.noreply.github.com> --- ibm/service/power/resource_ibm_pi_cloud_connection_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go index 040fc89148e..b90b2584a86 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go @@ -20,7 +20,7 @@ import ( ) func TestAccIBMPICloudConnectionbasic(t *testing.T) { - name := fmt.Sprintf("tf-cloudconnection-%d", accteinstanceRandIntRange(10, 100)) + name := fmt.Sprintf("tf-cloudconnection-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, From 6dc088856d13359ed80e04240bd082add29b9c40 Mon Sep 17 00:00:00 2001 From: Diptipowervs <152427968+Diptipowervs@users.noreply.github.com> Date: Mon, 11 Mar 2024 10:18:49 +0530 Subject: [PATCH 05/10] Update ibm/service/power/resource_ibm_pi_cloud_connection_test.go Co-authored-by: michaelkad <45772690+michaelkad@users.noreply.github.com> --- ibm/service/power/resource_ibm_pi_cloud_connection_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go index b90b2584a86..f71a8ed9a18 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go @@ -54,7 +54,7 @@ func testAccCheckIBMPICloudConnectionDestroy(s *terraform.State) error { if err != nil { return err } - client := instanceNewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) _, err = client.Get(cloudConnectionID) if err == nil { return fmt.Errorf("Cloud Connection still exists: %s", rs.Primary.ID) From be73ed7954c1e50e818e1f009790845fee332b42 Mon Sep 17 00:00:00 2001 From: Diptipowervs <152427968+Diptipowervs@users.noreply.github.com> Date: Mon, 11 Mar 2024 10:19:05 +0530 Subject: [PATCH 06/10] Update ibm/service/power/resource_ibm_pi_cloud_connection_test.go Co-authored-by: michaelkad <45772690+michaelkad@users.noreply.github.com> --- ibm/service/power/resource_ibm_pi_cloud_connection_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go index f71a8ed9a18..9d82d8414c4 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go @@ -89,7 +89,7 @@ func testAccCheckIBMPICloudConnectionExists(n string) resource.TestCheckFunc { if err != nil { return err } - client := instanceNewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) _, err = client.Get(cloudConnectionID) if err != nil { From 83b63180ddf80e5badfe022a04113ed968152ac4 Mon Sep 17 00:00:00 2001 From: Diptipowervs <152427968+Diptipowervs@users.noreply.github.com> Date: Mon, 11 Mar 2024 10:19:49 +0530 Subject: [PATCH 07/10] Update ibm/service/power/resource_ibm_pi_cloud_connection_test.go Co-authored-by: michaelkad <45772690+michaelkad@users.noreply.github.com> --- ibm/service/power/resource_ibm_pi_cloud_connection_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go index 9d82d8414c4..ed58b32433f 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go @@ -117,7 +117,7 @@ func testAccCheckIBMPICloudConnectionConfig(name string) string { } func TestAccIBMPICloudConnectionNetworks(t *testing.T) { - name := fmt.Sprintf("tf-cloudconnection-%d", accteinstanceRandIntRange(10, 100)) + name := fmt.Sprintf("tf-cloudconnection-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, From 9d32b812baa4e9e2a37d833b6ae4edc157bc860d Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Mon, 11 Mar 2024 12:03:28 +0530 Subject: [PATCH 08/10] Revert test file changes --- .../power/resource_ibm_pi_cloud_connection.go | 84 ++++++++++--------- .../resource_ibm_pi_cloud_connection_test.go | 13 +-- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection.go b/ibm/service/power/resource_ibm_pi_cloud_connection.go index 086a050c7bc..9a985014fd1 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection.go @@ -45,116 +45,118 @@ func ResourceIBMPICloudConnection() *schema.Resource { }, Schema: map[string]*schema.Schema{ - // Arguments - Arg_CloudConnectionName: { - Description: "Name of the cloud connection", + // Required Attributes + Arg_CloudInstanceID: { + Type: schema.TypeString, Required: true, + Description: "PI cloud instance ID", + }, + Arg_CloudConnectionName: { Type: schema.TypeString, + Required: true, + Description: "Name of the cloud connection", }, Arg_CloudConnectionSpeed: { - Description: "Speed of the cloud connection (speed in megabits per second)", - Required: true, Type: schema.TypeInt, + Required: true, ValidateFunc: validate.ValidateAllowedIntValues([]int{50, 100, 200, 500, 1000, 2000, 5000, 10000}), + Description: "Speed of the cloud connection (speed in megabits per second)", }, + + // Optional Attributes Arg_CloudConnectionGlobalRouting: { - Default: false, - Description: "Enable global routing for this cloud connection", - Optional: true, Type: schema.TypeBool, - }, - Arg_CloudInstanceID: { - Description: "PI cloud instance ID", - Required: true, - Type: schema.TypeString, - }, - Arg_CloudConnectionClassicEnabled: { - Default: false, - Description: "Enable classic endpoint destination", Optional: true, - Type: schema.TypeBool, + Default: false, + Description: "Enable global routing for this cloud connection", }, Arg_CloudConnectionMetered: { + Type: schema.TypeBool, + Optional: true, Default: false, Description: "Enable metered for this cloud connection", - Optional: true, - Type: schema.TypeBool, }, Arg_CloudConnectionNetworks: { + Type: schema.TypeSet, + Optional: true, Computed: true, - Description: "Set of Networks to attach to this cloud connection", Elem: &schema.Schema{Type: schema.TypeString}, + Description: "Set of Networks to attach to this cloud connection", + }, + Arg_CloudConnectionClassicEnabled: { + Type: schema.TypeBool, Optional: true, - Type: schema.TypeSet, + Default: false, + Description: "Enable classic endpoint destination", }, Arg_CloudConnectionClassicGreCidr: { - Description: "GRE network in CIDR notation", + Type: schema.TypeString, Optional: true, RequiredWith: []string{Arg_CloudConnectionClassicEnabled, Arg_CloudConnectionClassicGreDest}, - Type: schema.TypeString, + Description: "GRE network in CIDR notation", }, Arg_CloudConnectionClassicGreDest: { - Description: "GRE destination IP address", + Type: schema.TypeString, Optional: true, RequiredWith: []string{Arg_CloudConnectionClassicEnabled, Arg_CloudConnectionClassicGreCidr}, - Type: schema.TypeString, + Description: "GRE destination IP address", }, Arg_CloudConnectionVPCEnabled: { - Default: false, - Description: "Enable VPC for this cloud connection", + Type: schema.TypeBool, Optional: true, + Default: false, RequiredWith: []string{Arg_CloudConnectionVPCCRNs}, - Type: schema.TypeBool, + Description: "Enable VPC for this cloud connection", }, Arg_CloudConnectionVPCCRNs: { - Description: "Set of VPCs to attach to this cloud connection", - Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeSet, Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, RequiredWith: []string{Arg_CloudConnectionVPCEnabled}, - Type: schema.TypeSet, + Description: "Set of VPCs to attach to this cloud connection", }, Arg_CloudConnectionTransitEnabled: { - Default: false, - Description: "Enable transit gateway for this cloud connection", Type: schema.TypeBool, Optional: true, + Default: false, + Description: "Enable transit gateway for this cloud connection", }, //Computed Attributes Attr_CloudConnectionId: { + Type: schema.TypeString, Computed: true, Description: "Cloud connection ID", - Type: schema.TypeString, }, Attr_CloudConnectionStatus: { + Type: schema.TypeString, Computed: true, Description: "Link status", - Type: schema.TypeString, }, Attr_CloudConnectionIBMIPAddress: { + Type: schema.TypeString, Computed: true, Description: "IBM IP address", - Type: schema.TypeString, }, Attr_CloudConnectionUserIPAddress: { + Type: schema.TypeString, Computed: true, Description: "User IP address", - Type: schema.TypeString, }, Attr_CloudConnectionPort: { + Type: schema.TypeString, Computed: true, Description: "Port", - Type: schema.TypeString, }, Attr_CloudConnectionClassicGreSource: { + Type: schema.TypeString, Computed: true, Description: "GRE auto-assigned source IP address", - Type: schema.TypeString, }, Attr_CloudConnectionMode: { + Type: schema.TypeString, Computed: true, Description: "Type of service the gateway is attached to", - Type: schema.TypeString, }, }, } diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go index ed58b32433f..a70f85763f4 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go @@ -13,10 +13,11 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" - "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "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" ) func TestAccIBMPICloudConnectionbasic(t *testing.T) { @@ -54,7 +55,7 @@ func testAccCheckIBMPICloudConnectionDestroy(s *terraform.State) error { if err != nil { return err } - client := instance.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) + client := st.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) _, err = client.Get(cloudConnectionID) if err == nil { return fmt.Errorf("Cloud Connection still exists: %s", rs.Primary.ID) @@ -89,7 +90,7 @@ func testAccCheckIBMPICloudConnectionExists(n string) resource.TestCheckFunc { if err != nil { return err } - client := instance.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) + client := st.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) _, err = client.Get(cloudConnectionID) if err != nil { @@ -194,7 +195,7 @@ func testAccCheckIBMPICloudConnectionNetworkUpdateConfig(name string) string { } func TestAccIBMPICloudConnectionClassic(t *testing.T) { - name := fmt.Sprintf("tf-cloudconnection-%d", accteinstanceRandIntRange(10, 100)) + name := fmt.Sprintf("tf-cloudconnection-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -229,7 +230,7 @@ func testAccCheckIBMPICloudConnectionClassicConfig(name string) string { } func TestAccIBMPICloudConnectionVPC(t *testing.T) { - name := fmt.Sprintf("tf-cloudconnection-%d", accteinstanceRandIntRange(10, 100)) + name := fmt.Sprintf("tf-cloudconnection-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -268,7 +269,7 @@ func testAccCheckIBMPICloudConnectionVPCConfig(name string) string { } func TestAccIBMPICloudConnectionTransitGateway(t *testing.T) { - name := fmt.Sprintf("tf-cloudconnection-%d", accteinstanceRandIntRange(10, 100)) + name := fmt.Sprintf("tf-cloudconnection-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, From fb4132d00c41202726b395230a2abe478fab12ba Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Mon, 11 Mar 2024 12:20:14 +0530 Subject: [PATCH 09/10] Sorted file --- .../power/resource_ibm_pi_cloud_connection.go | 84 +++++++++---------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection.go b/ibm/service/power/resource_ibm_pi_cloud_connection.go index 9a985014fd1..086a050c7bc 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection.go @@ -45,118 +45,116 @@ func ResourceIBMPICloudConnection() *schema.Resource { }, Schema: map[string]*schema.Schema{ - // Required Attributes - Arg_CloudInstanceID: { - Type: schema.TypeString, - Required: true, - Description: "PI cloud instance ID", - }, + // Arguments Arg_CloudConnectionName: { - Type: schema.TypeString, - Required: true, Description: "Name of the cloud connection", + Required: true, + Type: schema.TypeString, }, Arg_CloudConnectionSpeed: { - Type: schema.TypeInt, + Description: "Speed of the cloud connection (speed in megabits per second)", Required: true, + Type: schema.TypeInt, ValidateFunc: validate.ValidateAllowedIntValues([]int{50, 100, 200, 500, 1000, 2000, 5000, 10000}), - Description: "Speed of the cloud connection (speed in megabits per second)", }, - - // Optional Attributes Arg_CloudConnectionGlobalRouting: { - Type: schema.TypeBool, - Optional: true, Default: false, Description: "Enable global routing for this cloud connection", - }, - Arg_CloudConnectionMetered: { + Optional: true, Type: schema.TypeBool, + }, + Arg_CloudInstanceID: { + Description: "PI cloud instance ID", + Required: true, + Type: schema.TypeString, + }, + Arg_CloudConnectionClassicEnabled: { + Default: false, + Description: "Enable classic endpoint destination", Optional: true, + Type: schema.TypeBool, + }, + Arg_CloudConnectionMetered: { Default: false, Description: "Enable metered for this cloud connection", + Optional: true, + Type: schema.TypeBool, }, Arg_CloudConnectionNetworks: { - Type: schema.TypeSet, - Optional: true, Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, Description: "Set of Networks to attach to this cloud connection", - }, - Arg_CloudConnectionClassicEnabled: { - Type: schema.TypeBool, + Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, - Default: false, - Description: "Enable classic endpoint destination", + Type: schema.TypeSet, }, Arg_CloudConnectionClassicGreCidr: { - Type: schema.TypeString, + Description: "GRE network in CIDR notation", Optional: true, RequiredWith: []string{Arg_CloudConnectionClassicEnabled, Arg_CloudConnectionClassicGreDest}, - Description: "GRE network in CIDR notation", + Type: schema.TypeString, }, Arg_CloudConnectionClassicGreDest: { - Type: schema.TypeString, + Description: "GRE destination IP address", Optional: true, RequiredWith: []string{Arg_CloudConnectionClassicEnabled, Arg_CloudConnectionClassicGreCidr}, - Description: "GRE destination IP address", + Type: schema.TypeString, }, Arg_CloudConnectionVPCEnabled: { - Type: schema.TypeBool, - Optional: true, Default: false, - RequiredWith: []string{Arg_CloudConnectionVPCCRNs}, Description: "Enable VPC for this cloud connection", + Optional: true, + RequiredWith: []string{Arg_CloudConnectionVPCCRNs}, + Type: schema.TypeBool, }, Arg_CloudConnectionVPCCRNs: { - Type: schema.TypeSet, - Optional: true, + Description: "Set of VPCs to attach to this cloud connection", Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, RequiredWith: []string{Arg_CloudConnectionVPCEnabled}, - Description: "Set of VPCs to attach to this cloud connection", + Type: schema.TypeSet, }, Arg_CloudConnectionTransitEnabled: { - Type: schema.TypeBool, - Optional: true, Default: false, Description: "Enable transit gateway for this cloud connection", + Type: schema.TypeBool, + Optional: true, }, //Computed Attributes Attr_CloudConnectionId: { - Type: schema.TypeString, Computed: true, Description: "Cloud connection ID", + Type: schema.TypeString, }, Attr_CloudConnectionStatus: { - Type: schema.TypeString, Computed: true, Description: "Link status", + Type: schema.TypeString, }, Attr_CloudConnectionIBMIPAddress: { - Type: schema.TypeString, Computed: true, Description: "IBM IP address", + Type: schema.TypeString, }, Attr_CloudConnectionUserIPAddress: { - Type: schema.TypeString, Computed: true, Description: "User IP address", + Type: schema.TypeString, }, Attr_CloudConnectionPort: { - Type: schema.TypeString, Computed: true, Description: "Port", + Type: schema.TypeString, }, Attr_CloudConnectionClassicGreSource: { - Type: schema.TypeString, Computed: true, Description: "GRE auto-assigned source IP address", + Type: schema.TypeString, }, Attr_CloudConnectionMode: { - Type: schema.TypeString, Computed: true, Description: "Type of service the gateway is attached to", + Type: schema.TypeString, }, }, } From 9a8aa43d58cd820af313a0cb8d0f57ebf04327eb Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Mon, 11 Mar 2024 12:26:12 +0530 Subject: [PATCH 10/10] Add test file --- .../resource_ibm_pi_cloud_connection_test.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go index a70f85763f4..1f7a9a61b97 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go @@ -113,8 +113,7 @@ func testAccCheckIBMPICloudConnectionConfig(name string) string { pi_network_name = "%[2]s" pi_network_type = "vlan" pi_cidr = "192.112.111.0/24" - } - `, acc.Pi_cloud_instance_id, name) + }`, acc.Pi_cloud_instance_id, name) } func TestAccIBMPICloudConnectionNetworks(t *testing.T) { @@ -167,8 +166,7 @@ func testAccCheckIBMPICloudConnectionNetworkConfig(name string) string { pi_network_name = "%[2]s_net2" pi_network_type = "vlan" pi_cidr = "192.112.113.0/24" - } - `, acc.Pi_cloud_instance_id, name) + }`, acc.Pi_cloud_instance_id, name) } func testAccCheckIBMPICloudConnectionNetworkUpdateConfig(name string) string { @@ -190,8 +188,7 @@ func testAccCheckIBMPICloudConnectionNetworkUpdateConfig(name string) string { pi_network_name = "%[2]s_net2" pi_network_type = "vlan" pi_cidr = "192.112.113.0/24" - } - `, acc.Pi_cloud_instance_id, name) + }`, acc.Pi_cloud_instance_id, name) } func TestAccIBMPICloudConnectionClassic(t *testing.T) { @@ -225,8 +222,7 @@ func testAccCheckIBMPICloudConnectionClassicConfig(name string) string { pi_cloud_connection_name = "%[2]s" pi_cloud_connection_speed = 50 pi_cloud_connection_classic_enabled = true - } - `, acc.Pi_cloud_instance_id, name) + }`, acc.Pi_cloud_instance_id, name) } func TestAccIBMPICloudConnectionVPC(t *testing.T) { @@ -264,8 +260,7 @@ func testAccCheckIBMPICloudConnectionVPCConfig(name string) string { pi_cloud_connection_speed = 50 pi_cloud_connection_vpc_enabled = true pi_cloud_connection_vpc_crns = ["crn:v1:bluemix:public:is:us-south:a/d9cec80d0adc400ead8e2076afe26698::vpc:r006-6486cf73-451d-4d44-b90d-83dff504cbed"] - } - `, acc.Pi_cloud_instance_id, name) + }`, acc.Pi_cloud_instance_id, name) } func TestAccIBMPICloudConnectionTransitGateway(t *testing.T) { @@ -307,6 +302,5 @@ func testAccCheckIBMPICloudConnectionConfigTransitGateway(name string) string { pi_network_name = "%[2]s" pi_network_type = "vlan" pi_cidr = "192.112.111.0/24" - } - `, acc.Pi_cloud_instance_id, name) + }`, acc.Pi_cloud_instance_id, name) }