Skip to content

Commit

Permalink
feat: add import via address for ip resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ikadix committed Dec 23, 2024
1 parent aa5b288 commit a806fa6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion internal/v6provider/resource_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,26 @@ func (r *IPResource) ImportState(
req resource.ImportStateRequest,
resp *resource.ImportStateResponse,
) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
if strings.HasPrefix(req.ID, "ip_") {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
return
}

res, err := r.M.Core.GetIpAddressWithResponse(ctx, &core.GetIpAddressParams{
IpAddressAddress: &req.ID,
})
if err != nil {
resp.Diagnostics.AddError("IP Address Import Error", err.Error())
return
}

resp.Diagnostics.Append(
resp.State.SetAttribute(
ctx,
path.Root("id"),
*res.JSON200.IpAddress.Id,
)...,
)
}

func unflattenIPVersion(ver int64) core.IPAddressVersionEnum {
Expand Down

0 comments on commit a806fa6

Please sign in to comment.