Evaluate module variable in another module when variable is in list of objects

It appears most of your problems come from your gateway_ip_configuration in your .tfvars being a list yet most/all of the expressions you’ve written accessing it, not treating it as a list.

I can’t figure out what your intent is here, as at one point you say

but you then pair that with code which appears deliberately structured to only handle zero or one:

You also say:

which is puzzling, as the issue doesn’t appear to relate to the usage of modules, and would still be an issue if they were all flattened away.

Showing your rewritten code not using modules here, may help communicate what you’re trying to achieve more clearly.

Also, please take a look at Welcome to the forum - please reformat your message regarding the formatting of your code.