Skip to content

Commit

Permalink
🐛 fix platform detection override for lr docs (#2226)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock authored Oct 15, 2023
1 parent 04819fd commit 85173cf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
10 changes: 7 additions & 3 deletions providers-sdk/v1/lr/cli/cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ var docsYamlCmd = &cobra.Command{
},
}

// required to be before more detail platform to ensure the right mapping
var platformMappingKeys = []string{
"aws", "gcp", "k8s", "azure", "azurerm", "arista", "equinix", "ms365", "msgraph", "vsphere", "esxi", "terraform", "terraform.state", "terraform.plan",
}

var platformMapping = map[string][]string{
"aws": {"aws"},
"gcp": {"gcp"},
Expand All @@ -158,13 +163,13 @@ var platformMapping = map[string][]string{
"msgraph": {"microsoft365"},
"vsphere": {"vmware-esxi", "vmware-vsphere"},
"esxi": {"vmware-esxi", "vmware-vsphere"},
"terraform": {"terraform-hcl"},
"terraform.state": {"terraform-state"},
"terraform.plan": {"terraform-plan"},
"terraform": {"terraform-hcl"},
}

func ensureDefaults(id string, entry *docs.LrDocsEntry, version string) *docs.LrDocsEntry {
for k := range platformMapping {
for _, k := range platformMappingKeys {
if entry == nil {
entry = &docs.LrDocsEntry{}
}
Expand All @@ -178,7 +183,6 @@ func ensureDefaults(id string, entry *docs.LrDocsEntry, version string) *docs.Lr
entry.Platform = &docs.LrDocsPlatform{
Name: platformMapping[k],
}
continue // required to ensure that terraform.state is not overwritten by terraform
}
}
return entry
Expand Down
29 changes: 29 additions & 0 deletions providers-sdk/v1/lr/cli/cmd/docs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package cmd

import (
"github.com/stretchr/testify/assert"
"go.mondoo.com/cnquery/v9/providers-sdk/v1/lr/docs"
"testing"
)

var defaultLrDocsEntry = &docs.LrDocsEntry{
Fields: map[string]*docs.LrDocsField{},
MinMondooVersion: "9.1.0",
}

func TestPlatformMapping(t *testing.T) {
res := ensureDefaults("terraform.plan.configuration", defaultLrDocsEntry, "9.1.0")
assert.Equal(t, "terraform-plan", res.Platform.Name[0])

res = ensureDefaults("terraform.plan.proposedChange", defaultLrDocsEntry, "9.1.0")
assert.Equal(t, "terraform-plan", res.Platform.Name[0])

res = ensureDefaults("terraform.state.module", defaultLrDocsEntry, "9.1.0")
assert.Equal(t, "terraform-state", res.Platform.Name[0])

res = ensureDefaults("terraform.block", defaultLrDocsEntry, "9.1.0")
assert.Equal(t, "terraform-hcl", res.Platform.Name[0])
}
4 changes: 2 additions & 2 deletions providers/terraform/resources/terraform.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ resources:
min_mondoo_version: 6.11.0
platform:
name:
- terraform-hcl
- terraform-state
terraform.state.module:
fields:
address: {}
Expand All @@ -163,7 +163,7 @@ resources:
min_mondoo_version: 6.11.0
platform:
name:
- terraform-hcl
- terraform-state
terraform.state.output:
fields:
identifier: {}
Expand Down

0 comments on commit 85173cf

Please sign in to comment.