How to determine plan or apply phase inside custom providers?

Is there a way to determine if Terraform is running “plan” or “apply” in custom providers?

I’m trying to write a custom provider that creates a temporary directory.
My strategy is to create a temporary directory on provider configuration phase. If a directory already exists, it should be deleted.

But provider configuration phase is run at both “plan” and “apply”, so I have to keep the directory if Terraform is in “apply” phase.

Do you have any ideas?

It sounds like you are trying to do something that is not supported.

A Terraform provider is not allowed to save private information on disk and re-use it between plan and apply stages, as Terraform makes no guarantees these will run in the same environment.

Please share more information about why you think you want to do this.