Skip to content

feat: update terraform test schema for v1.11#485

Open
MorrisWitthein wants to merge 4 commits intohashicorp:mainfrom
MorrisWitthein:feat/terraform-test-schema-v1.11
Open

feat: update terraform test schema for v1.11#485
MorrisWitthein wants to merge 4 commits intohashicorp:mainfrom
MorrisWitthein:feat/terraform-test-schema-v1.11

Conversation

@MorrisWitthein
Copy link
Copy Markdown

Fixes: #449

@MorrisWitthein MorrisWitthein requested a review from a team as a code owner October 31, 2025 12:02
@hashicorp-cla-app
Copy link
Copy Markdown

hashicorp-cla-app bot commented Oct 31, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@anubhav-goel anubhav-goel left a comment

Choose a reason for hiding this comment

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

Hi @MorrisWitthein,
Thank you so much for taking the time to put this together! 🎉 It's great to see a community contribution tackling #449.
I've left a few comments below, mostly around how state_key and override_during are modeled in the schema.

func TestSchema(v *version.Version) *schema.BodySchema {
bs := v1_9_test.TestSchema(v)

bs.Blocks["run"].Body.Blocks["state_key"] = stateKeyBlockSchema()
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.

state_key is actually an attribute rather than a nested block.
So it should be added to Attributes instead of Blocks. For a nice reference on how the codebase handles this pattern, take a look at #492

Attributes: map[string]*schema.AttributeSchema{
"state_key": {
Constraint: schema.AnyExpression{OfType: cty.String},
IsRequired: false,
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.

Instead of isRequired: false, it's a good practice to use isOptional: true

bs := v1_9_test.TestSchema(v)

bs.Blocks["run"].Body.Blocks["state_key"] = stateKeyBlockSchema()
bs.Blocks["mock_provider"].Body.Blocks["override_during"] = overrideDuringBlockSchema()
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.

Same comment as above, override_during is also an attribute rather than a nested block.

Also, override_during is only added to mock_provider, it should be added in other places as well. Please refer to the documentation for the same: https://developer.hashicorp.com/terraform/language/tests/mocking

@MorrisWitthein MorrisWitthein force-pushed the feat/terraform-test-schema-v1.11 branch from 5563c05 to 7f7e9d5 Compare March 10, 2026 17:36
@MorrisWitthein MorrisWitthein force-pushed the feat/terraform-test-schema-v1.11 branch from 7f7e9d5 to a24b5d3 Compare March 10, 2026 17:39
AttributeSchema and add missing occurences of override_during attribute
@MorrisWitthein
Copy link
Copy Markdown
Author

Hey @anubhav-goel,
thanks a lot for your feedback. I converted both of them to attributes and added the missing definitions for the override_during attribute.

I added a central definition for the override_during attribute in the root.go file. Let me know if that is fine, or breaking with your current patterns 🙂

Copy link
Copy Markdown
Contributor

@anubhav-goel anubhav-goel left a comment

Choose a reason for hiding this comment

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

Thanks for the update!! Most of the changes look good overall.

However, the current changes will likely crash the terraform-ls server (since mock_resource and mock_data are not root blocks, but are being modeled at the root schema level).

Hence, I’d recommend linking terraform-schema, terraform-ls, and vscode-terraform and validating end-to-end by running the full setup to confirm it achieves the desired result. If possible, sharing a short video of the behavior working in VS Code would also be helpful.


func overrideDuringAttributeSchema() *schema.AttributeSchema {
return &schema.AttributeSchema{
Description: lang.PlainText("Allows overriding the point in time where terraform generates data"),
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.

lang.Markdown could be used instead

return bs
}

func overrideDuringAttributeSchema() *schema.AttributeSchema {
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.

overrideDuringAttributeSchema() can be moved to a shared file (e.g. internal/schema/tests/1.11/override_during_attribute.go) to keep root.go/patch files focused.

Comment on lines +21 to +22
bs.Blocks["mock_resource"] = patchMockResourceBlockSchema(bs.Blocks["mock_resource"])
bs.Blocks["mock_data"] = patchMockDataBlockSchema(bs.Blocks["mock_data"])
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.

mock_resource and mock_data are not root blocks, they are nested blocks inside mock_provider. Adding them at the root schema level could cause terraform-ls to mishandle the schema and potentially crash the server.

@MorrisWitthein
Copy link
Copy Markdown
Author

@MorrisWitthein
Copy link
Copy Markdown
Author

Thanks again for all your Feedback!
I update everything accordingly and tested the new schema.

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.

[terraform-test] Missing state_key attribute in terraform test run block

2 participants