Skip to content

Commit

Permalink
🐛 cnquery modules were not being discovered (#698)
Browse files Browse the repository at this point in the history
Fixes #676
  • Loading branch information
jaym authored Jan 3, 2023
1 parent 8265160 commit 5924bd8
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion motor/providers/terraform/hcl_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestLoadHclBlocks(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, tf.parsed)
assert.Equal(t, 2, len(tf.tfVars))
assert.Equal(t, 4, len(tf.parsed.Files()))
assert.Equal(t, 5, len(tf.parsed.Files()))
}

func TestLoadTfvars(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion motor/providers/terraform/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func New(tc *providers.Config) (*Provider, error) {
if err != nil {
return errors.Wrap(err, "could not parse tfvars file")
}
} else {
} else if modulesManifest == nil {
modulesManifest, err = ParseTerraformModuleManifest(path)
if errors.Is(err, os.ErrNotExist) {
log.Debug().Str("path", path).Msg("no terraform module manifest found")
Expand Down
13 changes: 13 additions & 0 deletions motor/providers/terraform/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ func TestTerraform(t *testing.T) {
files := p.Parser().Files()
assert.Equal(t, len(files), 2)
}

func TestModuleManifestIssue676(t *testing.T) {
// See https://github.com/mondoohq/cnquery/issues/676
p, err := New(&providers.Config{
Options: map[string]string{
"path": "./testdata/issue676",
},
})
require.NoError(t, err)

require.NotNil(t, p.modulesManifest)
require.Len(t, p.modulesManifest.Records, 3)
}
41 changes: 41 additions & 0 deletions motor/providers/terraform/testdata/issue676/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Modules":[{"Key":"","Source":"","Dir":"."},{"Key":"org-policy_bucket_policy_only","Source":"registry.terraform.io/terraform-google-modules/org-policy/google//modules/bucket_policy_only","Version":"5.2.0","Dir":".terraform/modules/org-policy_bucket_policy_only/modules/bucket_policy_only"},{"Key":"org-policy_bucket_policy_only.storage-uniform-bucket-level-access","Source":"../..","Dir":".terraform/modules/org-policy_bucket_policy_only"}]}
5 changes: 5 additions & 0 deletions motor/providers/terraform/testdata/issue676/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module "org-policy_bucket_policy_only" {
source = "terraform-google-modules/org-policy/google//modules/bucket_policy_only"
version = "5.2.0"
# insert the 1 required variable here
}

0 comments on commit 5924bd8

Please sign in to comment.