No description
Find a file
dependabot[bot] dbaa11288d
build(deps): bump the github-actions-breaking group with 2 updates (#498)
Bumps the github-actions-breaking group with 2 updates: [actions/checkout](https://github.com/actions/checkout) and [actions/setup-go](https://github.com/actions/setup-go).


Updates `actions/checkout` from 4.2.2 to 6.0.2
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](11bd71901b...de0fac2e45)

Updates `actions/setup-go` from 5.4.0 to 6.2.0
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](0aaccfd150...7a3fe6cf4c)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 6.0.2
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions-breaking
- dependency-name: actions/setup-go
  dependency-version: 6.2.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions-breaking
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-06 22:11:57 +05:30
.github build(deps): bump the github-actions-breaking group with 2 updates (#498) 2026-03-06 22:11:57 +05:30
backend Add copyright_year in .copywrite.hcl (#490) 2026-02-03 15:21:44 +05:30
earlydecoder feat(stacks): Update Stacks schema to include missing GA specific blocks & attributes (#508) 2026-03-02 10:27:19 +05:30
internal Update module block source and version to allow references 2026-03-05 14:37:27 +01:00
META.d Add copyright_year in .copywrite.hcl (#490) 2026-02-03 15:21:44 +05:30
module Add copyright_year in .copywrite.hcl (#490) 2026-02-03 15:21:44 +05:30
registry Add copyright_year in .copywrite.hcl (#490) 2026-02-03 15:21:44 +05:30
schema feat(stacks): Update Stacks schema to include missing GA specific blocks & attributes (#508) 2026-03-02 10:27:19 +05:30
search Add copyright_year in .copywrite.hcl (#490) 2026-02-03 15:21:44 +05:30
stack Add copyright_year in .copywrite.hcl (#490) 2026-02-03 15:21:44 +05:30
test Add copyright_year in .copywrite.hcl (#490) 2026-02-03 15:21:44 +05:30
tools Add copyright_year in .copywrite.hcl (#490) 2026-02-03 15:21:44 +05:30
.copywrite.hcl Add copyright_year in .copywrite.hcl (#490) 2026-02-03 15:21:44 +05:30
.gitattributes ci: Enable testing in GitHub Actions (#14) 2021-02-19 08:07:54 +00:00
.gitignore Add go.work to gitignore (#156) 2022-10-28 11:29:41 -04:00
.go-version Bump: go version to 1.25 (#510) 2026-03-02 17:09:12 +05:30
go.mod build(deps): bump github.com/zclconf/go-cty from 1.17.0 to 1.18.0 (#507) 2026-03-05 17:27:05 +05:30
go.sum build(deps): bump github.com/zclconf/go-cty from 1.17.0 to 1.18.0 (#507) 2026-03-05 17:27:05 +05:30
LICENSE Add copyright_year in .copywrite.hcl (#490) 2026-02-03 15:21:44 +05:30
README.md Add pkg.go.dev badge & link 2021-01-07 08:57:32 +00:00

terraform-schema Go Reference

This library helps assembling a complete hcl-lang schema for decoding Terraform config based on static Terraform core schema and relevant provider schemas.

There is more than one schema?

Yes.

  • Terraform Core defines top-level schema
    • provider, resource or data blocks incl. meta attributes, such as alias or count
    • variable, output blocks etc.
  • each Terraform provider defines its own schema for the body of some of these blocks
    • attributes and nested blocks inside resource, data or provider blocks

Each of these can also differ between (core / provider) version.

Current Status

This project is in use by the Terraform Language Server and could in theory be used by other projects which need to decode the whole configuration.

However it has not been tested in any other scenarios.

Please note that this library depends on hcl-lang which itself is not considered stable yet.

Breaking changes may be introduced.

Alternative Solution

If you only need to perform shallow config decoding, e.g. you just need to get a list of variables, outputs, provider names/source etc. and you don't care as much about version-specific or provider-specific details then you should explore terraform-config-inspect instead, which will likely be sufficient for your needs.

How It Works

Usage

import (
	tfschema "github.com/hashicorp/terraform-schema/schema"
	"github.com/hashicorp/terraform-json"
)

// parse files e.g. via hclsyntax
parsedFiles := map[string]*hcl.File{ /* ... */ }

// obtain relevant core schema
coreSchema := tfschema.UniversalCoreModuleSchema()

// obtain relevant provider schemas e.g. via terraform-exec
// and marshal them into terraform-json type
providerSchemas := &tfjson.ProviderSchemas{ /* ... */ }

mergedSchema, err := tfschema.MergeCoreWithJsonProviderSchemas(parsedFiles, coreSchema, providerSchemas)
if err != nil {
	// ...
}

Provider Schemas

The only reliable way of obtaining provider schemas at the time of writing is via Terraform CLI by running terraform providers schema -json (0.12+).

terraform-exec can help automating the process of obtaining the schema.

terraform-json provides types that the JSON output can be marshalled into, which also used by terraform-exec and is considered as standard way of representing the output.

Known Issues

At the time of writing there is a known issue affecting the above command where it requires the following to be true in order to produce schemas:

  • configuration is valid (e.g. contains no incomplete blocks)
  • authentication is provided for any remote backend

Read more at hashicorp/terraform#24261.

Other ways of obtaining schemas are also being explored.

Why a Separate Repository (from Terraform Core)?

As demonstrated by the recent separation of Plugin SDK, Terraform Core is not intended to be consumed as a Go module and any packages which happen to be importable were not tested nor designed for use outside the context of Terraform Core.

Terraform Core's versioning reflects mainly the experience of end-users interacting with Terraform via the CLI. Functionality which is consumed as Go package and imported into other Go programs deserves its own dedicated versioning.

Terraform Core's schema internally always supports the latest version (e.g. Terraform 0.12 can parse 0.12 configuration). Consumers of this library however need to parse different versions of configuration at the same time.

Experimental Status

By using the software in this repository (the "Software"), you acknowledge that: (1) the Software is still in development, may change, and has not been released as a commercial product by HashiCorp and is not currently supported in any way by HashiCorp; (2) the Software is provided on an "as-is" basis, and may include bugs, errors, or other issues; (3) the Software is NOT INTENDED FOR PRODUCTION USE, use of the Software may result in unexpected results, loss of data, or other unexpected results, and HashiCorp disclaims any and all liability resulting from use of the Software; and (4) HashiCorp reserves all rights to make all decisions about the features, functionality and commercial release (or non-release) of the Software, at any time and without any obligation or liability whatsoever.