Skip to content

Commit

Permalink
Only check mapped resources
Browse files Browse the repository at this point in the history
We should only validate resources we will use. Discovered as part of
pulumi/pulumi-databricks#595.
  • Loading branch information
iwahbe committed Sep 18, 2024
1 parent 4d6cd87 commit 0041b4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pf/internal/check/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

pfbridge "github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
sdkv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2"
)
Expand Down Expand Up @@ -118,6 +119,16 @@ func TestMissingIDWithOverride(t *testing.T) {
assert.NoError(t, err)
}

func TestMissingIDUnmapped(t *testing.T) {
stderr, err := test(t, tfbridge.ProviderInfo{
P: pfbridge.ShimProvider(testProvider{missingID: true}),
IgnoreMappings: []string{"test_res"},
})

assert.Empty(t, stderr)
assert.NoError(t, err)
}

func TestSensitiveID(t *testing.T) {
stderr, err := test(t, tfbridge.ProviderInfo{
P: pfbridge.ShimProvider(testProvider{sensitiveID: true}),
Expand Down Expand Up @@ -270,6 +281,9 @@ func test(t *testing.T, info tfbridge.ProviderInfo) (string, error) {
Color: colors.Never,
})

info.MustComputeTokens(tokens.SingleModule(info.GetResourcePrefix(),
"index", tokens.MakeStandard(info.GetResourcePrefix())))

err := Provider(sink, info)

// We should not write diags to stdout
Expand Down
5 changes: 5 additions & 0 deletions pf/internal/check/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func checkIDProperties(sink diag.Sink, info tfbridge.ProviderInfo, isPFResource
errors := 0

info.P.ResourcesMap().Range(func(rname string, resource shim.Resource) bool {
// Unmapped resources are not available, so they don't need to be correct.
if v, ok := info.Resources[rname]; !ok || v.Tok == "" {
return true
}

// If a resource is sdk based, it always has an ID, regardless of the
// schema it describes.
if !isPFResource(rname) {
Expand Down

0 comments on commit 0041b4e

Please sign in to comment.