Could be your brake controller.
Could be in the Trailer's Harness.
Could be in the Truck's Harness.
Could be in the Dash.
Could be a bad ground.
Could be in the Body Computer/Gem Module
Could be in the ignition switch.
Could even be something as silly as the chip in your Key. If you have another Ignition Key, try that one when you're having the problem again. Although that one's a long shot.
I believe in checking the easiest thing to fix first.
When it comes to electrical problems........ They can really be a problem.