Skip to content

Commit

Permalink
Fixes Import issue for IP Allocation resource
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanthKa677 committed Oct 26, 2023
1 parent 789a9de commit 1cc367f
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions infoblox/resource_infoblox_ip_allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,16 +636,17 @@ func resourceAllocationRelease(d *schema.ResourceData, m interface{}) error {

func ipAllocationImporter(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
var ttl int
internalId := newInternalResourceIdFromString(d.Id())
if internalId == nil {
return nil, fmt.Errorf("ID value provided is not in a proper format")
}

d.SetId(internalId.String())
if err := d.Set("internal_id", internalId.String()); err != nil {
return nil, err
}
obj, err := getOrFindHostRec(d, m)
if err != nil {
if _, ok := err.(*ibclient.NotFoundError); ok {
d.SetId("")
return nil, ibclient.NewNotFoundError(fmt.Sprintf(
"cannot find apropriate object on NIOS side for resource with ID '%s': %s;"+
" removing the resource from Terraform state",
d.Id(), err))
}

return nil, err
}

Expand Down Expand Up @@ -731,18 +732,5 @@ func ipAllocationImporter(d *schema.ResourceData, m interface{}) ([]*schema.Reso
return nil, err
}

internalId := newInternalResourceIdFromString(d.Id())
if internalId == nil {
return nil, fmt.Errorf("ID value provided is not in a proper format")
}

d.SetId(internalId.String())
if err := d.Set("internal_id", internalId.String()); err != nil {
return nil, err
}
if _, err := getOrFindHostRec(d, m); err != nil {
return nil, err
}

return []*schema.ResourceData{d}, nil
}

0 comments on commit 1cc367f

Please sign in to comment.