I'm assuming you still have a key switch. It is easy to wire the headlight to operate only with the key ON using a relay. If you want the light to operate only if the motor is running, that is a lot more difficult.
Buy a 12 volt headlight relay at any auto parts store. It will probably have 4 terminals. If there are 5 terminals (87a insulate that terminal. If there are two terminals marked 87, insulate one of them) 2 terminals are used to operate the relay (control terminals) The other 2 terminals switch the power on and off like a regular
manual switch. I assume you have some kind of a switch now to turn the light on and off. Replace the switch with the relay. Your power wires go to the power terminals on the relay. Connect the control power terminal to switched power and the other to ground. Many relays have a wire diagram on the relay body to show how to connect.
85 to control power (orange wire). 86 to ground (black/white stripe wire). 30 to the battery. 87 to the headlight. 87a if there is one, insulate. A second 87 if there is one, insulate.
If you want to be able to turn the headlight off with the key ON, leave your existing switch in place and connect it into the control wire. (orange to manual switch, manual switch to relay 85.