feat: update terraform test schema for v1.11#485
feat: update terraform test schema for v1.11#485MorrisWitthein wants to merge 4 commits intohashicorp:mainfrom
Conversation
anubhav-goel
left a comment
There was a problem hiding this comment.
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.
internal/schema/tests/1.11/root.go
Outdated
| func TestSchema(v *version.Version) *schema.BodySchema { | ||
| bs := v1_9_test.TestSchema(v) | ||
|
|
||
| bs.Blocks["run"].Body.Blocks["state_key"] = stateKeyBlockSchema() |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Instead of isRequired: false, it's a good practice to use isOptional: true
internal/schema/tests/1.11/root.go
Outdated
| bs := v1_9_test.TestSchema(v) | ||
|
|
||
| bs.Blocks["run"].Body.Blocks["state_key"] = stateKeyBlockSchema() | ||
| bs.Blocks["mock_provider"].Body.Blocks["override_during"] = overrideDuringBlockSchema() |
There was a problem hiding this comment.
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
5563c05 to
7f7e9d5
Compare
7f7e9d5 to
a24b5d3
Compare
AttributeSchema and add missing occurences of override_during attribute
|
Hey @anubhav-goel, I added a central definition for the |
anubhav-goel
left a comment
There was a problem hiding this comment.
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.
internal/schema/tests/1.11/root.go
Outdated
|
|
||
| func overrideDuringAttributeSchema() *schema.AttributeSchema { | ||
| return &schema.AttributeSchema{ | ||
| Description: lang.PlainText("Allows overriding the point in time where terraform generates data"), |
There was a problem hiding this comment.
lang.Markdown could be used instead
internal/schema/tests/1.11/root.go
Outdated
| return bs | ||
| } | ||
|
|
||
| func overrideDuringAttributeSchema() *schema.AttributeSchema { |
There was a problem hiding this comment.
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.
internal/schema/tests/1.11/root.go
Outdated
| bs.Blocks["mock_resource"] = patchMockResourceBlockSchema(bs.Blocks["mock_resource"]) | ||
| bs.Blocks["mock_data"] = patchMockDataBlockSchema(bs.Blocks["mock_data"]) |
There was a problem hiding this comment.
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.
…urce/mock_data patching into mock_provider_block
|
Thanks again for all your Feedback! |
Fixes: #449