From a56f5f7d807cf39829d2e48f43989007209c516f Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Tue, 7 May 2024 10:19:07 +0200 Subject: [PATCH] Add new helper schema for variable collection --- schema/variable_schema.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/schema/variable_schema.go b/schema/variable_schema.go index 48828133..293b6b0d 100644 --- a/schema/variable_schema.go +++ b/schema/variable_schema.go @@ -11,6 +11,31 @@ import ( "github.com/zclconf/go-cty/cty" ) +// SchemaForVariableCollection returns a schema for collecting all +// variables in a variable file. It doesn't check if a variable has +// been defined in the module or not. +func AnySchemaForVariableCollection(modPath string) *schema.BodySchema { + return &schema.BodySchema{ + AnyAttribute: &schema.AttributeSchema{ + OriginForTarget: &schema.PathTarget{ + Address: schema.Address{ + schema.StaticStep{Name: "var"}, + schema.AttrNameStep{}, + }, + Path: lang.Path{ + Path: modPath, + LanguageID: ModuleLanguageID, + }, + Constraints: schema.Constraints{ + ScopeId: refscope.VariableScope, + Type: cty.DynamicPseudoType, + }, + }, + Constraint: schema.AnyExpression{OfType: cty.DynamicPseudoType}, + }, + } +} + func SchemaForVariables(vars map[string]module.Variable, modPath string) (*schema.BodySchema, error) { attributes := make(map[string]*schema.AttributeSchema)