Is a Pokemon's CP or IVs more important when choosing which Pokemon to defend a gym?

Solution 1:

IVs are included in the CP amalgamate. In general, two Pokemon with the same moveset and species will be roughly equivalent if they also have the same CP; if one of them has greater IVs, then the other will undoubtedly have a higher level.

There is some variance because the CP formula values Attack quadratically more than Defense or Stamina, even though their respective effect in battle is proportional (with Stamina contributing slightly more due to the fact that it also serves as a reservoir of Energy). Thus, Pokemon with higher Attack will be over-rated, and those with lower attack will be under-rated. IVs will, naturally, contribute to these proportions.

Solution 2:

As explained by RustyMembers the IV is by far more important than the CP of a Pokemon. But actually equally or sometimes even more important is the Moveset of a Pokemon. A Pokemon with the best moveset dps wise but with lower IV will perform better than a similar one with a different moveset but higher IV %.

However there is some discussion about this but general consensus is that Moveset is more important than IV if the difference in % is not too high.

Here is a nice discussion on Reddit about the topic.