Intrinsic functions (like get_resource and repeat) are evaluated from the inside out, so in this case Heat will try to resolve {get_resource: <%port%>}, which obviously fails.
• Don't explicitly create an OS::Neutron::Port, but instead allow OS::Nova::Server to create the ports you need.
• Include all potential ports in the template and enable or disable them from the environment with conditionals, then use the if macro to choose to reference them or not in the Server network config.