Command: providers schema
Theterraform providers schema command outputs a JSON representation of the schemas for all providers used in the current configuration.
Usage
Description
This command prints out a JSON representation of the schemas for all providers used in the current configuration. The output includes:- Provider configuration schemas
- Resource type schemas
- Data source schemas
- Provider metadata
-json flag is required for this command.
Options
-json- (Required) Produce JSON output. This is the only output format supported.
Behavior
The command:- Loads the configuration from the current working directory
- Initializes a local backend
- Creates a Terraform context with the configuration and current state
- Retrieves schemas from all providers declared in the configuration
- Marshals the schemas to JSON format
- Outputs the JSON to stdout
Requirements
- Providers must already be installed (run
terraform initfirst) - Requires a local backend (cannot be used with certain remote backends)
- This is a read-only command that does not modify state or configuration
Output Format
The output is a JSON object with the following structure:Schema Components
Provider Schema
Describes the configuration schema for the provider itself:attributes- Provider configuration argumentsblock_types- Nested configuration blocksdescription- Human-readable descriptiondescription_kind- Format of the description (“plain” or “markdown”)
Resource Schema
Describes the schema for each resource type:version- Schema version numberblock.attributes- Resource arguments and their propertiesblock.block_types- Nested configuration blocks within the resourcedescription- Resource descriptiondescription_kind- Description format
Attribute Properties
Each attribute includes:type- The attribute’s data typedescription- Description of the attributerequired- Whether the attribute is requiredoptional- Whether the attribute is optionalcomputed- Whether the value is computed by the providersensitive- Whether the attribute contains sensitive data
Examples
Basic Usage
Output provider schemas as JSON:Save to File
Save the schema output to a file for analysis:Pretty Print with jq
Format the JSON output for readability:Extract Specific Provider Schema
Extract the schema for a specific provider:List All Resource Types
List all available resource types for a provider:Get Resource Schema
Get the complete schema for a specific resource type:List Required Attributes
Find all required attributes for a resource:Use Cases
Documentation Generation
Generate custom documentation from provider schemas:Schema Validation
Validate configuration against provider schemas programmatically:IDE Integration
Provide schema information to IDEs and editors for autocomplete and validation:Testing and CI/CD
Validate that resource configurations match expected schemas:API Discovery
Discover available data sources and their attributes:Migration Planning
Compare schemas between provider versions to plan migrations:Output Example
Here’s a simplified example of the JSON output:Important Notes
- You must run
terraform initbefore running this command to ensure providers are installed - The command requires the
-jsonflag; no other output formats are supported - This command works only with local backends; some remote backend types are not supported
- The schema includes all providers declared in the configuration, even if they’re not currently in use
- Schema versions may change between provider versions, so always regenerate schemas after provider upgrades
Related Commands
terraform providers- Show provider requirementsterraform init- Install providersterraform show -json- Show state or plan in JSON formatterraform version- Show Terraform and provider versions