Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/fixtures/hclvalidate/valid/validation-block/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "example_var" {
type = string
description = "A variable that requires validation."
default = "test"

validation {
condition = length(var.example_var) > 0
error_message = "The example_var must not be empty."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// intentionally blank
13 changes: 11 additions & 2 deletions tf/tf.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,25 @@ func ModuleVariables(modulePath string) ([]string, []string, error) {
},
}

varsAttributesSchema := &hcl.BodySchema{
Attributes: []hcl.AttributeSchema{
{
Name: "default",
Required: false,
},
},
}

varsContent, _, contentDiags := body.PartialContent(varsSchema)
allDiags = append(allDiags, contentDiags...)
optional, required := []string{}, []string{}

for _, b := range varsContent.Blocks {
name := b.Labels[0]
attributes, attrDiags := b.Body.JustAttributes()
varBodyContent, _, attrDiags := b.Body.PartialContent(varsAttributesSchema)

allDiags = append(allDiags, attrDiags...)
if _, ok := attributes["default"]; ok {
if _, ok := varBodyContent.Attributes["default"]; ok {
optional = append(optional, name)
} else {
required = append(required, name)
Expand Down
Loading