Consuming Corruption deals X damage to target creature or planeswalker and you gain X life, where X is the number of Swamps you control.
If the target creature or planeswalker is an illegal target as Consuming Corruption tries to resolve, it won't resolve and none of its effects will happen. You won't gain life.
The value of X is calculated only once, as Consuming Corruption resolves.