It’s essential to have a lock for your bike if you plan to leave it anywhere. The bike should be locked to something immovable, and easily-removable components removed (lights) or secured (quick-release wheels).
It is worth spending a decent amount of money on a lock, especially if your bike is in the new / attractive to thieves category – ie anything that could be sold on.
A D-lock is a good option, though some would recommend combining with a cable lock so that one single tool can’t be used to release the bike.