Honestly one of the most impactful suggestions I can make to other DevOps types is this.
Terraform is shit. A declarative syntax is both unnecessarily restrictive and overly verbose. You can get logic in there, but it's a hack. Forget about it.
Try Pulumi.
The providers are mostly generated from Terraform, so there's feature parity. But what changes is that you use a real language with real logic. Go, TypeScript, Python. There may be more.
It's the absolute dog's bollocks.