diff --git a/steampipeconfig/modconfig/block_type.go b/steampipeconfig/modconfig/block_type.go index c45cb5cce0..271a1ec133 100644 --- a/steampipeconfig/modconfig/block_type.go +++ b/steampipeconfig/modconfig/block_type.go @@ -1,23 +1,25 @@ package modconfig const ( - BlockTypeMod = "mod" - BlockTypeQuery = "query" - BlockTypeControl = "control" - BlockTypeBenchmark = "benchmark" - BlockTypeDashboard = "dashboard" - BlockTypeContainer = "container" - BlockTypeChart = "chart" - BlockTypeCard = "card" - BlockTypeFlow = "flow" - BlockTypeHierarchy = "hierarchy" - BlockTypeImage = "image" - BlockTypeInput = "input" - BlockTypeTable = "table" - BlockTypeText = "text" - BlockTypeLocals = "locals" - BlockTypeVariable = "variable" - BlockTypeParam = "param" + BlockTypeMod = "mod" + BlockTypeQuery = "query" + BlockTypeControl = "control" + BlockTypeBenchmark = "benchmark" + BlockTypeDashboard = "dashboard" + BlockTypeContainer = "container" + BlockTypeChart = "chart" + BlockTypeCard = "card" + BlockTypeFlow = "flow" + BlockTypeHierarchy = "hierarchy" + BlockTypeImage = "image" + BlockTypeInput = "input" + BlockTypeTable = "table" + BlockTypeText = "text" + BlockTypeLocals = "locals" + BlockTypeVariable = "variable" + BlockTypeParam = "param" + BlockTypeRequire = "require" + BlockTypeLegacyRequires = "requires" ) // QueryProviderBlocks is a list of block types which implement QueryProvider diff --git a/steampipeconfig/modconfig/mod.go b/steampipeconfig/modconfig/mod.go index 7c34cf8119..c650d6d7e1 100644 --- a/steampipeconfig/modconfig/mod.go +++ b/steampipeconfig/modconfig/mod.go @@ -9,6 +9,7 @@ import ( "github.com/Masterminds/semver" "github.com/hashicorp/hcl/v2" + "github.com/hashicorp/hcl/v2/hclsyntax" "github.com/hashicorp/hcl/v2/hclwrite" "github.com/turbot/go-kit/helpers" typehelpers "github.com/turbot/go-kit/types" @@ -249,12 +250,15 @@ func (m *Mod) OnDecoded(block *hcl.Block, resourceMapProvider ModResourcesProvid // handle legacy requires block if m.LegacyRequire != nil && !m.LegacyRequire.Empty() { - if m.Require != nil && !m.Require.Empty() { - return hcl.Diagnostics{&hcl.Diagnostic{ - Severity: hcl.DiagError, - Summary: "Both 'require' and legacy 'requires' blocks are defined", - Subject: &block.DefRange, - }} + // ensure that both 'require' and 'requires' were not set + for _, b := range block.Body.(*hclsyntax.Body).Blocks { + if b.Type == BlockTypeRequire { + return hcl.Diagnostics{&hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Both 'require' and legacy 'requires' blocks are defined", + Subject: &block.DefRange, + }} + } } m.Require = m.LegacyRequire } diff --git a/steampipeconfig/parse/parser.go b/steampipeconfig/parse/parser.go index 5c5791406d..64b3e53b8c 100644 --- a/steampipeconfig/parse/parser.go +++ b/steampipeconfig/parse/parser.go @@ -96,8 +96,6 @@ func ModfileExists(modPath string) bool { // ParseModDefinition parses the modfile only // it is expected the calling code will have verified the existence of the modfile by calling ModfileExists func ParseModDefinition(modPath string) (*modconfig.Mod, error) { - // TODO think about variables - // if there is no mod at this location, return error modFilePath := filepaths.ModFilePath(modPath) if _, err := os.Stat(modFilePath); os.IsNotExist(err) {