Skip to content

fix(terraform): support OpenTofu language block#10923

Open
momomuchu wants to merge 2 commits into
aquasecurity:mainfrom
momomuchu:fix/opentofu-language-block-10906
Open

fix(terraform): support OpenTofu language block#10923
momomuchu wants to merge 2 commits into
aquasecurity:mainfrom
momomuchu:fix/opentofu-language-block-10906

Conversation

@momomuchu

Copy link
Copy Markdown

Trivy's HCL body schema rejects OpenTofu v1.12's top-level language block with "Unsupported block type", which fails the whole scan.

pkg/iac/terraform/schema.go enumerates the allowed block types and language was missing. This adds it. The nested compatible_with block and any edition/experiments attributes decode through the existing generic block handling, so no other schema change is needed.

Added a parser test that reads a language { compatible_with { opentofu = ">= 1.12" } } file. It fails on current main with the exact "Unsupported block type" error and passes with the fix.

Closes #10906

OpenTofu v1.12 introduced a top-level `language` block used to declare
version/compatibility constraints (with a nested `compatible_with`
block). Trivy's hardcoded HCL body schema did not list this block type,
so any `.tofu`/`.tf` file containing it failed to parse with:

  Unsupported block type; Blocks of type "language" are not expected here.

Add `language` to the terraform body schema so the parser accepts it.
The nested `compatible_with` block is decoded by the generic block
machinery, so no further schema changes are required.

Adds a regression test that parses a config using the `language` block
and reads the nested `compatible_with.opentofu` constraint.

Closes aquasecurity#10906
@momomuchu
momomuchu requested a review from nikpivkin as a code owner July 4, 2026 13:05
@CLAassistant

CLAassistant commented Jul 4, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

// When the parser reads the file
// Then it must not fail with "Unsupported block type", and the nested
// `compatible_with.opentofu` constraint must be readable.
func Test_OpenTofuLanguageBlock(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Given/When/Then doc comment is out of style for this file — compare with TestConfigWithEphemeralBlock nearby. A link to #10906 is enough. The require messages, the resource block check, and the compatible_with assertions can go — the point of the test is just that the language block no longer triggers "Unsupported block type".

@a7hu-15 a7hu-15 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks! Let's get this merged once tests pass.

Drop the Given/When/Then comment and over-specified assertions per
review; the test only needs to prove the language block no longer
triggers Unsupported block type. Ref aquasecurity#10906
@momomuchu

Copy link
Copy Markdown
Author

Done. Trimmed the test to just ParseFS + Load with require.NoError, matching TestConfigWithEphemeralBlock, and dropped the GWT comment (linked #10906 instead) plus the compatible_with/resource-block assertions. Verified it still fails with the original Unsupported block type error if I revert the schema.go change, so it keeps catching the regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(terraform): parser fails on OpenTofu language block

4 participants