Skip to content

Commit

Permalink
Fix: Panics on Import
Browse files Browse the repository at this point in the history
  • Loading branch information
kavya498 committed May 10, 2021
1 parent dad4d61 commit 2131703
Show file tree
Hide file tree
Showing 29 changed files with 115 additions and 18 deletions.
7 changes: 7 additions & 0 deletions ibm/resource_ibm_api_gateway_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]

Expand Down
6 changes: 6 additions & 0 deletions ibm/resource_ibm_api_gateway_endpoint_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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]

Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_container_bind_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_container_vpc_worker_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_container_worker_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
8 changes: 6 additions & 2 deletions ibm/resource_ibm_container_worker_pool_zone_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion ibm/resource_ibm_dl_gateway_virtual_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
7 changes: 5 additions & 2 deletions ibm/resource_ibm_iam_access_group_dynamic_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]

Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_iam_access_group_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_iam_service_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_iam_user_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_kms_key_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_kms_key_rings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 6 additions & 2 deletions ibm/resource_ibm_ob_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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]

Expand Down
8 changes: 6 additions & 2 deletions ibm/resource_ibm_ob_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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]

Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_pi_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_pi_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_pi_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 7 additions & 5 deletions ibm/resource_ibm_pi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion ibm/resource_ibm_pi_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions ibm/resource_ibm_private_dns_glb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_private_dns_glb_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_private_dns_glb_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions ibm/resource_ibm_private_dns_permitted_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_private_dns_resource_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions ibm/resource_ibm_private_dns_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion ibm/resource_ibm_resource_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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]
}
Expand Down
Loading

0 comments on commit 2131703

Please sign in to comment.