From 2131703bb56bf54eee565a501e16123048c42a9a Mon Sep 17 00:00:00 2001 From: kavya498 Date: Mon, 10 May 2021 12:09:20 +0530 Subject: [PATCH] Fix: Panics on Import --- ibm/resource_ibm_api_gateway_endpoint.go | 7 +++++++ ...resource_ibm_api_gateway_endpoint_subscription.go | 6 ++++++ ibm/resource_ibm_container_bind_service.go | 3 +++ ibm/resource_ibm_container_vpc_worker_pool.go | 3 +++ ibm/resource_ibm_container_worker_pool.go | 3 +++ ...urce_ibm_container_worker_pool_zone_attachment.go | 8 ++++++-- ibm/resource_ibm_dl_gateway_virtual_connection.go | 4 +++- ibm/resource_ibm_iam_access_group_dynamic_rule.go | 7 +++++-- ibm/resource_ibm_iam_access_group_policy.go | 3 +++ ibm/resource_ibm_iam_service_policy.go | 3 +++ ibm/resource_ibm_iam_user_policy.go | 3 +++ ibm/resource_ibm_kms_key_alias.go | 3 +++ ibm/resource_ibm_kms_key_rings.go | 3 +++ ibm/resource_ibm_ob_logging.go | 8 ++++++-- ibm/resource_ibm_ob_monitoring.go | 8 ++++++-- ibm/resource_ibm_pi_image.go | 3 +++ ibm/resource_ibm_pi_key.go | 3 +++ ibm/resource_ibm_pi_network.go | 3 +++ ibm/resource_ibm_pi_snapshot.go | 12 +++++++----- ibm/resource_ibm_pi_volume.go | 4 +++- ibm/resource_ibm_private_dns_glb.go | 4 ++++ ibm/resource_ibm_private_dns_glb_monitor.go | 3 +++ ibm/resource_ibm_private_dns_glb_pool.go | 3 +++ ibm/resource_ibm_private_dns_permitted_network.go | 4 ++++ ibm/resource_ibm_private_dns_resource_record.go | 3 +++ ibm/resource_ibm_private_dns_zones.go | 3 +++ ibm/resource_ibm_resource_tag.go | 6 +++++- ibm/resource_ibm_satellite_host.go | 6 +++++- ibm/resource_ibm_tg_gateway_connection.go | 4 +++- 29 files changed, 115 insertions(+), 18 deletions(-) diff --git a/ibm/resource_ibm_api_gateway_endpoint.go b/ibm/resource_ibm_api_gateway_endpoint.go index eaae02d34d..019454f4d8 100644 --- a/ibm/resource_ibm_api_gateway_endpoint.go +++ b/ibm/resource_ibm_api_gateway_endpoint.go @@ -172,6 +172,9 @@ func resourceIBMApiGatewayEndPointGet(d *schema.ResourceData, meta interface{}) parts := d.Id() partslist := strings.Split(parts, "//") + if len(partslist) < 2 { + return fmt.Errorf("Incorrect ID %s: Id should be a combination of instanceCRN//artifactID", d.Id()) + } serviceInstanceCrn := partslist[0] apiID := partslist[1] @@ -406,6 +409,10 @@ func resourceIBMApiGatewayEndPointExists(d *schema.ResourceData, meta interface{ parts := d.Id() partslist := strings.Split(parts, "//") + if len(partslist) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of instanceCRN//artifactID", d.Id()) + } + serviceInstanceCrn := partslist[0] apiID := partslist[1] diff --git a/ibm/resource_ibm_api_gateway_endpoint_subscription.go b/ibm/resource_ibm_api_gateway_endpoint_subscription.go index 7dc44af937..acf0664019 100644 --- a/ibm/resource_ibm_api_gateway_endpoint_subscription.go +++ b/ibm/resource_ibm_api_gateway_endpoint_subscription.go @@ -133,6 +133,9 @@ func resourceIBMApiGatewayEndpointSubscriptionGet(d *schema.ResourceData, meta i parts := d.Id() partslist := strings.Split(parts, "//") + if len(partslist) < 2 { + return fmt.Errorf("Incorrect ID %s: Id should be a combination of artifactID//clientID", d.Id()) + } artifactID := partslist[0] clientID := partslist[1] @@ -268,6 +271,9 @@ func resourceIBMApiGatewayEndpointSubscriptionExists(d *schema.ResourceData, met } parts := d.Id() partslist := strings.Split(parts, "//") + if len(partslist) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of artifactID//clientID", d.Id()) + } artifactID := partslist[0] clientID := partslist[1] diff --git a/ibm/resource_ibm_container_bind_service.go b/ibm/resource_ibm_container_bind_service.go index abf66ac020..7b6ee7449a 100644 --- a/ibm/resource_ibm_container_bind_service.go +++ b/ibm/resource_ibm_container_bind_service.go @@ -183,6 +183,9 @@ func resourceIBMContainerBindServiceRead(d *schema.ResourceData, meta interface{ if err != nil { return err } + if len(parts) < 3 { + return fmt.Errorf("Incorrect ID %s: Id should be a combination of clusterNameID/serviceInstanceNameID/namespaceID", d.Id()) + } clusterNameID := parts[0] serviceInstanceNameID := parts[1] namespaceID := parts[2] diff --git a/ibm/resource_ibm_container_vpc_worker_pool.go b/ibm/resource_ibm_container_vpc_worker_pool.go index f27fc86d62..14879726af 100644 --- a/ibm/resource_ibm_container_vpc_worker_pool.go +++ b/ibm/resource_ibm_container_vpc_worker_pool.go @@ -413,6 +413,9 @@ func resourceIBMContainerVpcWorkerPoolExists(d *schema.ResourceData, meta interf if err != nil { return false, err } + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of clusterID/WorkerPoolID", d.Id()) + } cluster := parts[0] workerPoolID := parts[1] diff --git a/ibm/resource_ibm_container_worker_pool.go b/ibm/resource_ibm_container_worker_pool.go index 546565434b..b6f4d20c49 100644 --- a/ibm/resource_ibm_container_worker_pool.go +++ b/ibm/resource_ibm_container_worker_pool.go @@ -350,6 +350,9 @@ func resourceIBMContainerWorkerPoolExists(d *schema.ResourceData, meta interface if err != nil { return false, err } + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of clusterID/WorkerPoolID", d.Id()) + } cluster := parts[0] workerPoolID := parts[1] diff --git a/ibm/resource_ibm_container_worker_pool_zone_attachment.go b/ibm/resource_ibm_container_worker_pool_zone_attachment.go index ce815b7ac0..d550b1b15c 100644 --- a/ibm/resource_ibm_container_worker_pool_zone_attachment.go +++ b/ibm/resource_ibm_container_worker_pool_zone_attachment.go @@ -8,10 +8,11 @@ import ( "strings" "time" - v1 "github.com/IBM-Cloud/bluemix-go/api/container/containerv1" - "github.com/IBM-Cloud/bluemix-go/bmxerror" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + v1 "github.com/IBM-Cloud/bluemix-go/api/container/containerv1" + "github.com/IBM-Cloud/bluemix-go/bmxerror" ) func resourceIBMContainerWorkerPoolZoneAttachment() *schema.Resource { @@ -280,6 +281,9 @@ func resourceIBMContainerWorkerPoolZoneAttachmentExists(d *schema.ResourceData, if err != nil { return false, err } + if len(parts) < 3 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of clusterID/WorkerPoolID/ZoneID", d.Id()) + } cluster := parts[0] workerPoolID := parts[1] zoneID := parts[2] diff --git a/ibm/resource_ibm_dl_gateway_virtual_connection.go b/ibm/resource_ibm_dl_gateway_virtual_connection.go index d26350fd1d..687d3b3ee7 100644 --- a/ibm/resource_ibm_dl_gateway_virtual_connection.go +++ b/ibm/resource_ibm_dl_gateway_virtual_connection.go @@ -292,7 +292,9 @@ func resourceIBMdlGatewayVCExists(d *schema.ResourceData, meta interface{}) (boo if err != nil { return false, err } - + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of gatewayID/gatewayVCID", d.Id()) + } gatewayId := parts[0] ID := parts[1] diff --git a/ibm/resource_ibm_iam_access_group_dynamic_rule.go b/ibm/resource_ibm_iam_access_group_dynamic_rule.go index fc4c3192e7..3af566644e 100644 --- a/ibm/resource_ibm_iam_access_group_dynamic_rule.go +++ b/ibm/resource_ibm_iam_access_group_dynamic_rule.go @@ -7,10 +7,10 @@ import ( "fmt" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/IBM-Cloud/bluemix-go/api/iamuum/iamuumv2" "github.com/IBM-Cloud/bluemix-go/bmxerror" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceIBMIAMDynamicRule() *schema.Resource { @@ -238,6 +238,9 @@ func resourceIBMIAMDynamicRuleExists(d *schema.ResourceData, meta interface{}) ( if err != nil { return false, err } + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of accessGroupID/RuleID", d.Id()) + } grpID := parts[0] ruleID := parts[1] diff --git a/ibm/resource_ibm_iam_access_group_policy.go b/ibm/resource_ibm_iam_access_group_policy.go index 007e30b69f..87020f2971 100644 --- a/ibm/resource_ibm_iam_access_group_policy.go +++ b/ibm/resource_ibm_iam_access_group_policy.go @@ -313,6 +313,9 @@ func resourceIBMIAMAccessGroupPolicyExists(d *schema.ResourceData, meta interfac if err != nil { return false, err } + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of accessGroupID/PolicyID", d.Id()) + } accgrpPolicyID := parts[1] diff --git a/ibm/resource_ibm_iam_service_policy.go b/ibm/resource_ibm_iam_service_policy.go index 67bf88c792..dfa44827d8 100644 --- a/ibm/resource_ibm_iam_service_policy.go +++ b/ibm/resource_ibm_iam_service_policy.go @@ -356,6 +356,9 @@ func resourceIBMIAMServicePolicyExists(d *schema.ResourceData, meta interface{}) if err != nil { return false, err } + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of serviceID(OR)iamID/PolicyID", d.Id()) + } serviceIDUUID := parts[0] servicePolicyID := parts[1] diff --git a/ibm/resource_ibm_iam_user_policy.go b/ibm/resource_ibm_iam_user_policy.go index 8adb328ec4..2e108f1723 100644 --- a/ibm/resource_ibm_iam_user_policy.go +++ b/ibm/resource_ibm_iam_user_policy.go @@ -313,6 +313,9 @@ func resourceIBMIAMUserPolicyExists(d *schema.ResourceData, meta interface{}) (b if err != nil { return false, err } + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of userEmail/PolicyID", d.Id()) + } userEmail := parts[0] userPolicyID := parts[1] diff --git a/ibm/resource_ibm_kms_key_alias.go b/ibm/resource_ibm_kms_key_alias.go index 605c2f9b0b..a0ab427a7b 100644 --- a/ibm/resource_ibm_kms_key_alias.go +++ b/ibm/resource_ibm_kms_key_alias.go @@ -127,6 +127,9 @@ func resourceIBMKmsKeyAliasRead(d *schema.ResourceData, meta interface{}) error return err } id := strings.Split(d.Id(), ":alias:") + if len(id) < 2 { + return fmt.Errorf("Incorrect ID %s: Id should be a combination of keyAlias:alias:keyCRN", d.Id()) + } crn := id[1] crnData := strings.Split(crn, ":") endpointType := crnData[3] diff --git a/ibm/resource_ibm_kms_key_rings.go b/ibm/resource_ibm_kms_key_rings.go index fa2f21afdd..260924e835 100644 --- a/ibm/resource_ibm_kms_key_rings.go +++ b/ibm/resource_ibm_kms_key_rings.go @@ -151,6 +151,9 @@ func resourceIBMKmsKeyRingRead(d *schema.ResourceData, meta interface{}) error { return err } id := strings.Split(d.Id(), ":keyRing:") + if len(id) < 2 { + return fmt.Errorf("Incorrect ID %s: Id should be a combination of keyRingID:keyRing:InstanceCRN", d.Id()) + } crn := id[1] crnData := strings.Split(crn, ":") endpointType := crnData[3] diff --git a/ibm/resource_ibm_ob_logging.go b/ibm/resource_ibm_ob_logging.go index 1c624edab3..9e9cc4a23a 100644 --- a/ibm/resource_ibm_ob_logging.go +++ b/ibm/resource_ibm_ob_logging.go @@ -9,10 +9,11 @@ import ( "strings" "time" - v2 "github.com/IBM-Cloud/bluemix-go/api/container/containerv2" - "github.com/IBM-Cloud/bluemix-go/bmxerror" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + v2 "github.com/IBM-Cloud/bluemix-go/api/container/containerv2" + "github.com/IBM-Cloud/bluemix-go/bmxerror" ) const ( @@ -209,6 +210,9 @@ func resourceIBMLoggingRead(d *schema.ResourceData, meta interface{}) error { if err != nil { return err } + if len(parts) < 2 { + return fmt.Errorf("Incorrect ID %s: Id should be a combination of clusterNameorID/loggingID", d.Id()) + } clusterName := parts[0] loggingID := parts[1] diff --git a/ibm/resource_ibm_ob_monitoring.go b/ibm/resource_ibm_ob_monitoring.go index 828dbbdd4e..fd42a92cfd 100644 --- a/ibm/resource_ibm_ob_monitoring.go +++ b/ibm/resource_ibm_ob_monitoring.go @@ -9,10 +9,11 @@ import ( "strings" "time" - v2 "github.com/IBM-Cloud/bluemix-go/api/container/containerv2" - "github.com/IBM-Cloud/bluemix-go/bmxerror" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + v2 "github.com/IBM-Cloud/bluemix-go/api/container/containerv2" + "github.com/IBM-Cloud/bluemix-go/bmxerror" ) const ( @@ -210,6 +211,9 @@ func resourceIBMMonitoringRead(d *schema.ResourceData, meta interface{}) error { if err != nil { return err } + if len(parts) < 2 { + return fmt.Errorf("Incorrect ID %s: Id should be a combination of clusterNameorID/monitoringID", d.Id()) + } clusterName := parts[0] monitoringID := parts[1] diff --git a/ibm/resource_ibm_pi_image.go b/ibm/resource_ibm_pi_image.go index e9a19a03e9..8b57dbfaef 100644 --- a/ibm/resource_ibm_pi_image.go +++ b/ibm/resource_ibm_pi_image.go @@ -154,6 +154,9 @@ func resourceIBMPIImageExists(d *schema.ResourceData, meta interface{}) (bool, e if err != nil { return false, err } + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of powerInstanceID/ImageID", d.Id()) + } name := parts[1] powerinstanceid := parts[0] client := st.NewIBMPIImageClient(sess, powerinstanceid) diff --git a/ibm/resource_ibm_pi_key.go b/ibm/resource_ibm_pi_key.go index 49b5c879ae..dd9b705838 100644 --- a/ibm/resource_ibm_pi_key.go +++ b/ibm/resource_ibm_pi_key.go @@ -151,6 +151,9 @@ func resourceIBMPIKeyExists(d *schema.ResourceData, meta interface{}) (bool, err if err != nil { return false, err } + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of powerInstanceID/keyName", d.Id()) + } name := parts[1] powerinstanceid := parts[0] client := st.NewIBMPIKeyClient(sess, powerinstanceid) diff --git a/ibm/resource_ibm_pi_network.go b/ibm/resource_ibm_pi_network.go index f5121732de..b737513a51 100644 --- a/ibm/resource_ibm_pi_network.go +++ b/ibm/resource_ibm_pi_network.go @@ -188,6 +188,9 @@ func resourceIBMPINetworkExists(d *schema.ResourceData, meta interface{}) (bool, if err != nil { return false, err } + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of powerInstanceID/NetworkID", d.Id()) + } powerinstanceid := parts[0] client := st.NewIBMPINetworkClient(sess, powerinstanceid) diff --git a/ibm/resource_ibm_pi_snapshot.go b/ibm/resource_ibm_pi_snapshot.go index 0771536192..44c6437b04 100644 --- a/ibm/resource_ibm_pi_snapshot.go +++ b/ibm/resource_ibm_pi_snapshot.go @@ -8,14 +8,14 @@ import ( "log" "time" - "github.com/IBM-Cloud/power-go-client/power/client/p_cloud_p_vm_instances" - "github.com/IBM-Cloud/power-go-client/power/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/IBM-Cloud/bluemix-go/bmxerror" st "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/power-go-client/helpers" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/IBM-Cloud/power-go-client/power/client/p_cloud_p_vm_instances" + "github.com/IBM-Cloud/power-go-client/power/models" ) func resourceIBMPISnapshot() *schema.Resource { @@ -248,7 +248,9 @@ func resourceIBMPISnapshotExists(d *schema.ResourceData, meta interface{}) (bool if err != nil { return false, err } - + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of powerInstanceID/SnapshotID", d.Id()) + } powerinstanceid := parts[0] client := st.NewIBMPISnapshotClient(sess, powerinstanceid) diff --git a/ibm/resource_ibm_pi_volume.go b/ibm/resource_ibm_pi_volume.go index bfd0ebd144..befd6e46c1 100644 --- a/ibm/resource_ibm_pi_volume.go +++ b/ibm/resource_ibm_pi_volume.go @@ -224,7 +224,9 @@ func resourceIBMPIVolumeExists(d *schema.ResourceData, meta interface{}) (bool, if err != nil { return false, err } - + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of powerInstanceID/VolumeID", d.Id()) + } powerinstanceid := parts[0] client := st.NewIBMPIVolumeClient(sess, powerinstanceid) diff --git a/ibm/resource_ibm_private_dns_glb.go b/ibm/resource_ibm_private_dns_glb.go index fc155f1808..6ca04eae9d 100644 --- a/ibm/resource_ibm_private_dns_glb.go +++ b/ibm/resource_ibm_private_dns_glb.go @@ -289,6 +289,10 @@ func resourceIBMPrivateDNSGLBExists(d *schema.ResourceData, meta interface{}) (b return false, err } idset := strings.Split(d.Id(), "/") + if len(idset) < 3 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of InstanceID/zoneID/glbID", d.Id()) + } + getlbOptions := sess.NewGetLoadBalancerOptions(idset[0], idset[1], idset[2]) _, detail, err := sess.GetLoadBalancer(getlbOptions) if err != nil { diff --git a/ibm/resource_ibm_private_dns_glb_monitor.go b/ibm/resource_ibm_private_dns_glb_monitor.go index 82b1433bb6..6d2dbe060a 100644 --- a/ibm/resource_ibm_private_dns_glb_monitor.go +++ b/ibm/resource_ibm_private_dns_glb_monitor.go @@ -455,6 +455,9 @@ func resourceIBMPrivateDNSGLBMonitorExists(d *schema.ResourceData, meta interfac } idset := strings.Split(d.Id(), "/") + if len(idset) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of InstanceID/monitorID", d.Id()) + } getMonitorOptions := sess.NewGetMonitorOptions(idset[0], idset[1]) response, detail, err := sess.GetMonitor(getMonitorOptions) diff --git a/ibm/resource_ibm_private_dns_glb_pool.go b/ibm/resource_ibm_private_dns_glb_pool.go index 3fc808f4be..0bb7731894 100644 --- a/ibm/resource_ibm_private_dns_glb_pool.go +++ b/ibm/resource_ibm_private_dns_glb_pool.go @@ -365,6 +365,9 @@ func resourceIBMPrivateDNSGLBPoolExists(d *schema.ResourceData, meta interface{} } idset := strings.Split(d.Id(), "/") + if len(idset) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of InstanceID/poolID", d.Id()) + } getPoolOptions := sess.NewGetPoolOptions(idset[0], idset[1]) response, detail, err := sess.GetPool(getPoolOptions) diff --git a/ibm/resource_ibm_private_dns_permitted_network.go b/ibm/resource_ibm_private_dns_permitted_network.go index 4fdce195d7..69d635085b 100644 --- a/ibm/resource_ibm_private_dns_permitted_network.go +++ b/ibm/resource_ibm_private_dns_permitted_network.go @@ -182,6 +182,10 @@ func resourceIBMPrivateDNSPermittedNetworkExists(d *schema.ResourceData, meta in } idSet := strings.Split(d.Id(), "/") + if len(idSet) < 3 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of InstanceID/zoneID/permittedNetworkID", d.Id()) + } + mk := "private_dns_permitted_network_" + idSet[0] + idSet[1] ibmMutexKV.Lock(mk) defer ibmMutexKV.Unlock(mk) diff --git a/ibm/resource_ibm_private_dns_resource_record.go b/ibm/resource_ibm_private_dns_resource_record.go index bfe94974b3..114e39d73f 100644 --- a/ibm/resource_ibm_private_dns_resource_record.go +++ b/ibm/resource_ibm_private_dns_resource_record.go @@ -502,6 +502,9 @@ func resourceIBMPrivateDNSResourceRecordExists(d *schema.ResourceData, meta inte } idSet := strings.Split(d.Id(), "/") + if len(idSet) < 3 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of InstanceID/zoneID/recordID", d.Id()) + } getResourceRecordOptions := sess.NewGetResourceRecordOptions(idSet[0], idSet[1], idSet[2]) mk := "private_dns_resource_record_" + idSet[0] + idSet[1] ibmMutexKV.Lock(mk) diff --git a/ibm/resource_ibm_private_dns_zones.go b/ibm/resource_ibm_private_dns_zones.go index 8948f746b9..54d0f440fd 100644 --- a/ibm/resource_ibm_private_dns_zones.go +++ b/ibm/resource_ibm_private_dns_zones.go @@ -214,6 +214,9 @@ func resourceIBMPrivateDNSZoneExists(d *schema.ResourceData, meta interface{}) ( } idSet := strings.Split(d.Id(), "/") + if len(idSet) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of InstanceID/zoneID", d.Id()) + } getZoneOptions := sess.NewGetDnszoneOptions(idSet[0], idSet[1]) _, response, err := sess.GetDnszone(getZoneOptions) if err != nil { diff --git a/ibm/resource_ibm_resource_tag.go b/ibm/resource_ibm_resource_tag.go index db20d57d21..8d08dd1aa8 100644 --- a/ibm/resource_ibm_resource_tag.go +++ b/ibm/resource_ibm_resource_tag.go @@ -10,10 +10,11 @@ import ( "regexp" "strings" - "github.com/IBM-Cloud/bluemix-go/bmxerror" "github.com/IBM/platform-services-go-sdk/globaltaggingv1" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/bluemix-go/bmxerror" ) const ( @@ -195,6 +196,9 @@ func resourceIBMResourceTagRead(d *schema.ResourceData, meta interface{}) error if err != nil { return err } + if len(parts) < 2 { + return fmt.Errorf("Incorrect ID %s: Id should be a combination of resourceID/resourceType", d.Id()) + } rID = parts[0] rType = parts[1] } diff --git a/ibm/resource_ibm_satellite_host.go b/ibm/resource_ibm_satellite_host.go index 3b03bd54f4..0594d618bc 100644 --- a/ibm/resource_ibm_satellite_host.go +++ b/ibm/resource_ibm_satellite_host.go @@ -8,10 +8,11 @@ import ( "log" "time" - "github.com/IBM-Cloud/bluemix-go/bmxerror" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.ibm.com/ibmcloud/kubernetesservice-go-sdk/kubernetesserviceapiv1" + + "github.com/IBM-Cloud/bluemix-go/bmxerror" ) const ( @@ -163,6 +164,9 @@ func resourceIBMSatelliteHostRead(d *schema.ResourceData, meta interface{}) erro if err != nil { return err } + if len(parts) < 2 { + return fmt.Errorf("Incorrect ID %s: Id should be a combination of location/hostName", d.Id()) + } location := parts[0] hostName := parts[1] diff --git a/ibm/resource_ibm_tg_gateway_connection.go b/ibm/resource_ibm_tg_gateway_connection.go index b6e30e145b..947c928ec0 100644 --- a/ibm/resource_ibm_tg_gateway_connection.go +++ b/ibm/resource_ibm_tg_gateway_connection.go @@ -415,7 +415,9 @@ func resourceIBMTransitGatewayConnectionExists(d *schema.ResourceData, meta inte if err != nil { return false, err } - + if len(parts) < 2 { + return false, fmt.Errorf("Incorrect ID %s: Id should be a combination of gatewayID/ConnectionID", d.Id()) + } gatewayId := parts[0] ID := parts[1]