Open drandell opened 2 years ago
Hi @drandell,
The version number you've found here is the version number of the schema for that particular configuration block, rather than the version of the provider. Provider schema elements have separate version numbers from the providers themselves because this allows the schema for each resource type and for the provider configuration itself to evolve independently. Therefore the schema JSON you've included here is working as designed.
The provider's own version number isn't included in its schema because a provider doesn't typically know its own version number: that's an artifact of its packaging and metadata in the registry rather than of the plugin executable itself.
Can you say a little more about what you intend to do with this information? It may be possible to get the information you need in a different way. Otherwise, we can turn this into a feature request representing whatever use-case you have. Thanks!
Hi, @apparentlymart thanks for replying so quickly :) My plan is to query the provider schema to determine the available resources, I'm working on an application for managed terraform via GUI. As a bit of added context, I thought knowing what provider version was used to determine the available resources would be helpful for point-in-time comparisons later on i.e. I've queried and found XY resources but later on found XYZ because XY was ran with provider version 40 but now it's 41.
I had thought of querying the .terraform.lock.hcl
file as that contains the version information but it doesn't feel quite right.
Hi @drandell! Thanks for the additional context.
I think the best machine-readable integration point for that at the moment would be to run terraform version -json
and refer to the provider_selections
property, which is a mapping from provider address to version number. This command will return a JSON equivalent of the human-oriented information you can see from terraform version
.
This command is actually just directly interpreting the content of .terraform.lock.hcl
and returning it, because that is Terraform's source of record about which version of each provider is selected. That means you will need to have an up-to-date lock file before running it, which you can achieve by running terraform init
. I assume you must already be doing this anyway because it would not be possible to request the schemas for the providers if you hadn't already installed them.
Terraform Version
Terraform Configuration Files
Debug Output
Expected Behavior
version should be "4.41.0"
Actual Behavior
Schema.json contains all of the resource information but critically, I can't tell what version of the provider the schema was generated from and the version field is just set to 0
Steps to Reproduce
terraform init terraform providers schema -json > schema.json
Additional Context
No response
References
No response