diff --git a/examples/resources/netbox_virtualization_vm_primary_ip/import.sh b/examples/resources/netbox_virtualization_vm_primary_ip/import.sh new file mode 100644 index 000000000..da49f1b0b --- /dev/null +++ b/examples/resources/netbox_virtualization_vm_primary_ip/import.sh @@ -0,0 +1,2 @@ +# Virtual machine primary IP assignments can be imported by virtual machine id +terraform import netbox_virtualization_vm_primary_ip.name 1 diff --git a/netbox/virtualization/resource_netbox_virtualization_vm_primary_ip.go b/netbox/virtualization/resource_netbox_virtualization_vm_primary_ip.go index 6cd9a83f9..2fdd982eb 100644 --- a/netbox/virtualization/resource_netbox_virtualization_vm_primary_ip.go +++ b/netbox/virtualization/resource_netbox_virtualization_vm_primary_ip.go @@ -249,6 +249,9 @@ func resourceNetboxVirtualizationVMPrimaryIPExists(d *schema.ResourceData, resourceID := int64(d.Get("virtualmachine_id").(int)) resourceIDString := strconv.FormatInt(resourceID, 10) + if resourceIDString == "0" { + resourceIDString = d.Id() + } params := virtualization.NewVirtualizationVirtualMachinesListParams().WithID( &resourceIDString) resources, err := client.Virtualization.VirtualizationVirtualMachinesList( @@ -258,7 +261,7 @@ func resourceNetboxVirtualizationVMPrimaryIPExists(d *schema.ResourceData, } for _, resource := range resources.Payload.Results { - if resource.ID == resourceID { + if strconv.FormatInt(resource.ID, 10) == resourceIDString { resourceExist = true } }