The last step is definitely something you can script. It's actually pretty common to do so when you have a multi-tenant-like use case, where you have a set of templates (workbooks and/or data sources) and based on the customer/user, you would create a set of resources (workbooks and/or data sources) specific to them. The process & one tool-set that can be used is well explained in the following blog post: https://tableauandbehold.com/2018/03/14/publishing-extracts-from-a-template-data-source-using-tableau_tools/
In that same blog, there's another post that explains how data sources are defined in Tableau which could be helpful if you want to get into the nitty gritty: https://tableauandbehold.com/2016/06/29/defining-a-tableau-data-source-programmatically/
Hope this helps!