Skip to content

Commit

Permalink
fixing resource name too
Browse files Browse the repository at this point in the history
  • Loading branch information
zricethezav committed Mar 27, 2019
1 parent 48c95e7 commit a6d7453
Showing 1 changed file with 7 additions and 3 deletions.
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 a6d7453

Please sign in to comment.