From Terraform's perspective, environment variables are just another kind of data from outside of Terraform and so if you want to read from them then you'd do so using a data source designed for that purpose.
Using data sources for external data means that there's a well-defined model for when Terraform will access the data and a guarantee that Terraform will access it only once per plan and apply, either during the plan phase if possible or during the apply phase if the data source configuration depends on information not available until the apply step.
There is not an official provider for accessing environment variables because in most cases a Terraform configuration should not directly depend on anything about the specific system where it's running -- a typical Terraform configuration is for managing remote objects via network APIs -- but there are some third party providers in the registry whose documentation suggests that they might give you what you need:
I have not directly used either so I cannot specifically recommend either of these. I suggest reviewing the documentation and the source code to see if they can do what you need.