You have to learn a few things, which you do along the way, but basically, poetry is a matter of the ear. Iambic pentameters or what constitutes a stanza comes naturally - your ears will know.
Vikram Seth
Learn, Know, You 