I feel the same problem! I've been writing web apps in various technologies (from backbone to react, php to Node) and always felt I had to reimplement the same common features (while using a lot of code + tests, ...).
Thinking similarly as you (terraform for code), together with my brother I started working on https://wasp-lang.dev/ - it is a DSL for building full-stack web apps. We are still very early but have some initial functionality.
Would love to hear if that resonates with what you had in mind.
We also did a quite extensive research of other solutions so happy to share what we discovered here as well.
E.g. From the purely code-generators:
https://divjoy.com/ - generates react code
https://bullettrain.co/ - Ruby on Rails starter