The shared module terraformdns/route53-recordsets/aws is implemented in essentially the way you are describing, so you may be able to address your need either using that module directly or by referring to its source code as an example and implementing a similar pattern for yourself directly.