-
Notifications
You must be signed in to change notification settings - Fork 10.3k
"terraform providers schema" only includes providers already being used #26306
Description
Terraform Version
I am currently working with a development build of Terraform 0.14, but this bug also seems to be present in Terraform 0.13.
Terraform Configuration Files
terraform {
required_providers {
random = {
source = "hashicorp/random"
}
}
}Debug Output
There is no output relevant to this problem in the trace log.
Expected Behavior
With the above configuration, terraform providers schema -json should produce a JSON schema representation containing the schema for the hashicorp/random provider.
Producing a schema in this situation is necessary to allow development tools such as a text editor language server to assist the user in declaring their first resource for this provider, by providing autocomplete for resource type names. Otherwise, a provider like this one which doesn't require a configuration block is only visible to the language server after the user has manually written one resource block, assuming that the language server is somehow able to infer that it needs to refresh its cached copy of the schemas.
Actual Behavior
terraform providers schema -json produces an empty schema representation, because it doesn't accept the provider requirement declaration alone as a use of this provider.
This behavior made sense for Terraform 0.12 and earlier, where explicit provider requirements were only for annotating with version constraints, but from Terraform 0.13 and later the required_providers block is the documented way to declare the intent to use a particular provider in the current module and choose a local name for it.
Steps to Reproduce
With the above configuration:
-
terraform initto install therandomprovider -
terraform providers schema -jsonto see the schema response that lacks the random provider's schema:{"format_version":"0.1"}
Additional Context
It's possible to work around this by writing a do-nothing provider configuration block, which is then considered to be a use of the provider sufficient for inclusion in the schema:
provider "random" {
}...but we generally don't expect to find explicit configuration blocks for providers that don't require any configuration, so this would be an unusual additional requirement for those using a hypothetical language server that depends on the JSON schema output.