Skip to content

Commit

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

0 comments on commit 48c95e7

Please sign in to comment.