Skip to content

Commit

Permalink
Merge pull request #25 from zambien/bug/fix_id_extraction
Browse files Browse the repository at this point in the history
fixing name and env extraction
  • Loading branch information
zricethezav authored Mar 27, 2019
2 parents c2f15df + a6d7453 commit eaab288
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions apigee/resource_api_proxy_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions apigee/resource_target_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit eaab288

Please sign in to comment.