Typically a particular Terraform configuration should either directly manage an object or read that object from elsewhere. It sounds like you've mixed both together in the same configuration, which has therefore left Terraform unclear as to what you are asking it to do.
If your configuration is already creating a particular object then you can typically refer to the attributes from that object in order to get equivalent information to what you'd get from a data resource retrieving that same object, and by passing data around through expressions you'll implicitly give Terraform the information it needs about the appropriate ordering of the operations.
Unfortunately your question is very general and doesn't include any specific examples of what you're working on, so I can't say anything more concrete than this, but if you are running into this situation as a result of decomposing your infrastructure into multiple modules then you might find it useful to review the Module Composition section to see some different module design patterns that rely in various ways on data flow between modules.