The soldier was caught in an undercover operation after he contacted a foreign country asking to defect.

A NZ soldier drives a vehicle as part of Exercise Wayfinder. Courtesy of New Zealand Defence Force
A New Zealand soldier has been dismissed from the army and sentenced to two years in military detention after being court-martialed for handing over sensitive information to someone he thought was an agent of a foreign government.
His contact was actually an agent of the NZ Security Intelligence Service (SIS).