Story line: Sci Fi writer can't think of a story. Then thinks of aliens living on moon and observing us. Whenever we get close to realizing they are there they have us forget. Then he forgets the story line.
"Dry Spell", a short story by Bill Pronzini; first published in Amazing Science Fiction, September 1970, available at the Internet Archive. Here is a summary from NESFA's Recursive Science Fiction site:
SF writer John Kensington has a terrible writer's block. Then an idea comes—aliens are building a mind-control machine to [conquer] Earth. At its present development it seeks out the minds of those who have stumbled upon their plans and erase[s] all memory of them. He also comes up with a perfect method of defeating the aliens. Seconds later he no longer remembers the idea for his new story.
Here are some quotations from the story to show how it matches your question.
Story line: Sci Fi writer can't think of a story.
The bane of all writers, John Kensington thought glumly, whether they be poor and struggling or whether they be rich and famous, is the protracted dry spell.
He sat staring at the blank sheet of yellow foolscap in his typewriter. His mind was as blank as that paper. Not a single idea, not a single line of writing that even remotely reached coherency in almost three weeks.
Then thinks of aliens living on moon and observing us.
The idea of an alien moonbase is not mentioned. Instead:
It would be a science fiction/fantasy story, he thought, probably a novella if he worked it properly. He moistened his lips. Now, let's see . . .
Suppose there's this race of aliens plotting to take over Earth, because it is a strategic planet in some kind of inter-galactic war they're involved in. Okay, okay, so it's hackneyed. There are ways to get around that, ways to play that aspect down.
These aliens have infiltrated Earth and set up some kind of base of operations, maybe up in the mountains somewhere. They're assembling a kind of penultimate cybernetic machine which, when fully completed, will have the power to erase all rational thought from the minds of humans, turning them into obsequious zombies.
Whenever we get close to realizing they are there they have us forget.
Wait now. Suppose these aliens have a portion of this machine already completed. This portion would be capable of reading, simultaneously, the thoughts of every human on Earth, and of categorizing those thoughts for the aliens to study. That way, if any human somehow happened to blunder on the scheme in one way or another—mental blundering as well as physical would have to be considered, what with clairvoyance and the emanation into space of thought waves, and the like—then the extraterrestrials would immediately know about it. And what they would do would be to train the full strength of this completed portion of the machine on that particular human, and with it eradicate all those thoughts endangering their project, thus insuring its safety.
The writer thinks of a way to defeat the aliens:
All at once the answer popped into his mind. By God! Kensington thought. It's perfect! There's not a flaw in it! He grinned hugely. Those damned aliens wouldn't stand a snowball's chance in you-know-where if I set it up this way.
Then he forgets the story line.
He sat at the typewriter, excitement coursing through him because he knew, he could feel, that the dry spell was at an end. His fingers poised over the keys.
Quite suddenly, quite inexplicably, his mind went blank.