How do I vary the configuration/schema of a provider based on the resource using it?

I have close to 30 resources and data sources belonging to a Terraform provider I’m working on. All of these rely on the Provider Configuration and its schema in order to create a client and perform CRUD operations.

However, a couple of these resources do not require a set of attributes in the configuration of the provider (the provider’s expected schema of attributes taken from the environment). I would like to know if there can be any mechanism using which the said attributes can be ignored by terraform plan, when the calling resource belongs to the aforementioned set of resources that do not require these attributes.

I have seen answers to this in terms of specifying multiple providers within a provider (meta), but that is not what I can implement; I would instead like to know if within the same provider, I can have some resources using all attributes from the schema of the provider, and a few of them not using all of those attributes (being able to ignore some of them) when terraform plan is run.

Hi @pranav-init,

The plugin framework does not have any special feature to achieve the result you described, but because provider codebases typically describe their schemas using Go code you can potentially use features of the Go programming language to factor out common parts.

For example, you could write a function that takes a schema definition and then returns a new schema definition that has all of the same attributes as the input but also adds one or more additional attributes that are common to many different resource types. When you implement the schema building for your resource types you can then use that function to add the extra shared attributes before returning.