diff --git a/apigee/resource_api_proxy_deployment.go b/apigee/resource_api_proxy_deployment.go index 1806e62..7625bda 100644 --- a/apigee/resource_api_proxy_deployment.go +++ b/apigee/resource_api_proxy_deployment.go @@ -59,11 +59,14 @@ func resourceApiProxyDeploymentImport(d *schema.ResourceData, meta interface{}) log.Print("[DEBUG] resourceApiProxyDeploymentImport START") client := meta.(*apigee.EdgeClient) - if len(strings.Split(d.Id(), "_")) != 3 { + splits := strings.Split(d.Id(), "_") + if len(splits) < 2 { return []*schema.ResourceData{}, fmt.Errorf("[ERR] Wrong format of resource: %s. Please follow '{name}_{env}_deployment'", d.Id()) } - name := strings.Split(d.Id(), "_")[0] - IDEnv := strings.Split(d.Id(), "_")[1] + nameOffset := len(splits[len(splits)-1]) + len(splits[len(splits)-2]) + envOffset := len(splits[len(splits)-1]) + name := d.Id()[:(len(d.Id())-nameOffset)-2] + IDEnv := d.Id()[len(name)+1 : (len(d.Id())-envOffset)-1] deployment, _, err := client.Proxies.GetDeployments(name) if err != nil { log.Printf("[DEBUG] resourceApiProxyDeploymentImport. Error getting deployment api: %v", err) diff --git a/apigee/resource_target_server.go b/apigee/resource_target_server.go index fcf1da3..f11d036 100644 --- a/apigee/resource_target_server.go +++ b/apigee/resource_target_server.go @@ -120,11 +120,15 @@ func resourceTargetServerImport(d *schema.ResourceData, meta interface{}) ([]*sc log.Print("[DEBUG] resourceTargetServerImport START") client := meta.(*apigee.EdgeClient) - if len(strings.Split(d.Id(), "_")) != 2 { + splits := strings.Split(d.Id(), "_") + if len(splits) < 1 { return []*schema.ResourceData{}, fmt.Errorf("[ERR] Wrong format of resource: %s. Please follow '{name}_{env}'", d.Id()) } - name := strings.Split(d.Id(), "_")[0] - IDEnv := strings.Split(d.Id(), "_")[1] + + nameOffset := len(splits[len(splits)-1]) + name := d.Id()[:(len(d.Id())-nameOffset)-1] + IDEnv := splits[len(splits)-1] + targetServerData, _, err := client.TargetServers.Get(name, IDEnv) if err != nil { log.Printf("[ERROR] resourceTargetServerImport error getting target servers: %s", err.Error())