Listing Resources and Data Sources From a Terraform Provider
terraform providers schema -json
and jq
to extract a complete list of all available resources and data sources for any Terraform provider.For scripting, automation, or simply to explore what’s available, it’s incredibly useful to have a complete list of all the resources and data sources that a Terraform provider offers. I learned that you can generate this list directly from the Terraform CLI with a little help from the command-line JSON processor, jq
.
Setup
First, you need an initialized Terraform directory with the provider you want to inspect. This allows Terraform to load the provider’s schema, which contains all the information we need.
Create a
main.tf
file with the provider definition. You don’t need any other configuration.hcl code snippet start
terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 5.100.0" } } }
hcl code snippet end
Initialize Terraform in that directory.
shell code snippet start
terraform init
shell code snippet end
Listing Resources and Data Sources
With the provider initialized, you can now dump its schema as JSON and use jq
to parse it.
Resources
shell code snippet start
terraform providers schema -json | jq -r '.provider_schemas."registry.terraform.io/hashicorp/aws".resource_schemas | keys[]'
shell code snippet end
Data Sources
The command is almost identical, you just need to change resource_schemas
to data_source_schemas
.
shell code snippet start
terraform providers schema -json | jq -r '.provider_schemas."registry.terraform.io/hashicorp/aws".data_source_schemas | keys[]'
shell code snippet end
You can easily adapt this for any provider by changing the path "registry.terraform.io/hashicorp/aws"
to match the provider you are inspecting.