Bottom Line Up Front (BLUF): You need to know what you write and write what you know.
How does that work in practice? I've never fought against alien life forms whilst simultaneously dealing with a dangerous rebel threat from within, but I'm certainly writing about it. Have I violated my one rule? Have I got full Dark Knight?
"Write What You Know" is a common piece of useless advice thrown at writers at the start of their careers. It's usually offered by one of your non-writing friends. You gripe about not being able to divine any billion-dollar ideas from the bottom of your soy-mocha-frappe, and they chime in with this morsel of feccus.
"Just write what you know."
Sure. If I'd followed that advice, you would have been reading Volume 53 in my lifelong epic series about working in a big-box retail store. It's called Selling Out, and you would have loved it. I would have been the next Scott Adams, making money hand over fist.
But that's not how it works.
For me, the old "write what you know" idiom means something a little different. Instead of focusing all your efforts on ripping events from your own life and polishing them into a product, be more resourceful. Be--dare I say it--creative.
Take pieces of your life and create a collage of true emotions and actions, then hot glue that sweaty mess onto paper until you've come up with a story.
As an example, take my character of Cameron Davis, a space pilot in The Gray Wars Saga. I've never been a pilot, nor have I ever fought against aliens in an intergalactic shoving match. But I have served in the military, I have faced off against bullies, and I have made silly mistakes that cost me a lot in life. By taking the real emotions and actions of my own personal journey, I am able to create a more compelling character for my story. Instead of relying solely on my ability to invent magic out of nothing, I give myself a leg-up using the real tragedies of my own existence.
Oh, I made myself sad there.
The point I want to make is that writing, like most aspects of life, is made better with experience. You don't need to have lived through the moment to talk about it, but you do need to know what the emotional journey will be. You need to make those decisions and feel the weight of the consequences, because your characters certainly will.
You need to know what you write before you write what you know.