I want to create a provider / resource which has access to the complete state.
I want to access the complete terraform state file, more or less.
One idee would be to configure the provider with the state file location and let the provider read the statefile, but this is locked at least locally and it seams this would not be a clean solution.
There is no clean solution to what you want to do, because the entire design of Terraform is that Terraform core controls the central details of managing state, and providers are called just to perform actions on individual resources.
So, with your intent, you are actively fighting against Terraform design principles.
What is the ultimate goal, that makes you want to do this?
one use case would be to use for example to the amount of resources in the state as a parameter for an backend system which the resource is is controlling over the backend api.
So that the own resources know how many resources overall exist in this particular configuration.(as an example).
I see… at that point, I think you should wrap Terraform in a script which counts the resources by running terraform state list and counting the lines, and writes the result to a .tfvars file before starting the Terraform run.
The provider interface just doesn’t give them access to what you want in any clean way - you’d be stuck having to try to break out of the provider abstraction and effectively “reverse-engineer” the currently running Terraform operation. It’s likely to prove too fragile to be worth attempting.