No description
Find a file
Ilia Gogotchuri 94ffeb9668
Update ephemeral link to the latest (#59)
Signed-off-by: Ilia Gogotchuri <ilia.gogotchuri0@gmail.com>
2025-12-15 14:04:26 +04:00
.github update CODEOWNERS to match the new governance (#35) 2025-06-25 12:47:06 -03:00
backend Update copyright headers to include year 2024 (#19) 2025-05-13 13:09:02 +04:00
earlydecoder Adding support for builtin provider (#54) 2025-11-25 11:58:43 -03:00
internal Update ephemeral link to the latest (#59) 2025-12-15 14:04:26 +04:00
module Added support for deprecated variables and outputs (#52) 2025-11-24 11:09:18 -03:00
registry Update copyright headers to include year 2024 (#19) 2025-05-13 13:09:02 +04:00
schema Resource lifecycle.destroy support for OpenTofu 1.12 (#58) 2025-12-15 13:59:50 +04:00
tools Update copyright headers to include year 2024 (#19) 2025-05-13 13:09:02 +04:00
.copywrite.hcl Update copyright headers to include year 2024 (#19) 2025-05-13 13:09:02 +04:00
.gitattributes ci: Enable testing in GitHub Actions (#14) 2021-02-19 08:07:54 +00:00
.gitignore Update copyright headers to include year 2024 (#19) 2025-05-13 13:09:02 +04:00
.go-version Bump internal Go version to 1.22 2024-06-25 16:11:29 +02:00
go.mod Ephemeral initial scope (#44) 2025-10-30 14:51:09 +04:00
go.sum Ephemeral initial scope (#44) 2025-10-30 14:51:09 +04:00
LICENSE Update copyright headers (#1) 2024-12-25 08:58:29 -05:00
README.md Update README.md 2025-01-01 08:49:35 -05:00

opentofu-schema [WIP]

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

There is more than one schema?

Yes.

  • OpenTofu Core defines top-level schema
    • provider, resource or data blocks incl. meta attributes, such as alias or count
    • variable, output blocks etc.
  • each OpenTofu 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 OpenTofu 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.

How It Works

Usage

import (
	tfschema "github.com/opentofu/opentofu-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 tofu-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 OpenTofu CLI by running tofu providers schema -json.

tofu-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 tofu-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.