diff --git a/pkg/steampipeconfig/modconfig/dashboard.go b/pkg/steampipeconfig/modconfig/dashboard.go index 774e96490f..0e6c36eb66 100644 --- a/pkg/steampipeconfig/modconfig/dashboard.go +++ b/pkg/steampipeconfig/modconfig/dashboard.go @@ -12,7 +12,7 @@ import ( ) const rootRuntimeDependencyNode = "rootRuntimeDependencyNode" -const runtimeDependencyDashboardScope = "self" +const RuntimeDependencyDashboardScope = "self" // Dashboard is a struct representing the Dashboard resource type Dashboard struct { diff --git a/pkg/steampipeconfig/modconfig/parsed_property_path.go b/pkg/steampipeconfig/modconfig/parsed_property_path.go index 5539fd62c1..b91d353f4a 100644 --- a/pkg/steampipeconfig/modconfig/parsed_property_path.go +++ b/pkg/steampipeconfig/modconfig/parsed_property_path.go @@ -10,7 +10,7 @@ type ParsedPropertyPath struct { ItemType string Name string PropertyPath []string - // optional scope of this property path ("root or parent") + // optional scope of this property path ("self") Scope string Original string } @@ -49,7 +49,7 @@ func ParseResourcePropertyPath(propertyPath string) (*ParsedPropertyPath, error) } // special case handling for runtime dependencies which may have use the "self" qualifier - if parts[0] == runtimeDependencyDashboardScope { + if parts[0] == RuntimeDependencyDashboardScope { res.Scope = parts[0] parts = parts[1:] } diff --git a/pkg/steampipeconfig/parse/decode_args.go b/pkg/steampipeconfig/parse/decode_args.go index b5e965098e..12dfbe265f 100644 --- a/pkg/steampipeconfig/parse/decode_args.go +++ b/pkg/steampipeconfig/parse/decode_args.go @@ -183,6 +183,12 @@ func getRuntimeDepFromExpression(expr hcl.Expression, targetProperty, parentProp return nil, err } + if propertyPath.ItemType == modconfig.BlockTypeInput { + // tactical: validate input dependency + if err := validateInputRuntimeDependency(propertyPath); err != nil { + return nil, err + } + } ret := &modconfig.RuntimeDependency{ PropertyPath: propertyPath, ParentPropertyName: parentProperty, @@ -248,6 +254,12 @@ func identifyRuntimeDependenciesFromArray(attr *hcl.Attribute, idx int, parentPr if err != nil { return nil, err } + // tactical: validate input dependency + if propertyPath.ItemType == modconfig.BlockTypeInput { + if err := validateInputRuntimeDependency(propertyPath); err != nil { + return nil, err + } + } ret := &modconfig.RuntimeDependency{ PropertyPath: propertyPath, ParentPropertyName: parentProperty, @@ -261,6 +273,18 @@ func identifyRuntimeDependenciesFromArray(attr *hcl.Attribute, idx int, parentPr return nil, fmt.Errorf("could not extract runtime dependency for arg %d - not found in attribute list", idx) } +// tactical - if runtime dependency is an input, validate it is of correct format +// TODO - include this with the main runtime dependency validaiton, when it is rewritten https://github.com/turbot/steampipe/issues/2925 +func validateInputRuntimeDependency(propertyPath *modconfig.ParsedPropertyPath) error { + // input references must be of form self.input..value + if propertyPath.Scope != modconfig.RuntimeDependencyDashboardScope || + len(propertyPath.PropertyPath) != 1 || + propertyPath.PropertyPath[0] != "value" { + return fmt.Errorf("could not resolve runtime dependency resource %s", propertyPath.Original) + } + return nil +} + func decodeParam(block *hcl.Block, parseCtx *ModParseContext) (*modconfig.ParamDef, []*modconfig.RuntimeDependency, hcl.Diagnostics) { def := modconfig.NewParamDef(block) var runtimeDependencies []*modconfig.RuntimeDependency diff --git a/tests/manual_testing/node_reuse/inputs/dashboard.sp b/tests/manual_testing/node_reuse/inputs/dashboard.sp index cf15682e1d..964d2ff67c 100644 --- a/tests/manual_testing/node_reuse/inputs/dashboard.sp +++ b/tests/manual_testing/node_reuse/inputs/dashboard.sp @@ -13,12 +13,10 @@ dashboard "inputs" { } table { - param "foo" {} sql = "select $1" - args = { - arn = self.input.i1.value - } + args =[self.input.i1.value] } + table { query = query.q1 args = { @@ -31,5 +29,5 @@ dashboard "inputs" { query "q1"{ sql = "select arn from aws_account where arn = $1" param "arn" { } - search_path="test" + }