Skip to content

Commit

Permalink
Prevent panics on invalid provider configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
iwahbe committed Jul 22, 2024
1 parent 32e9d39 commit e665ff6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pf/proto/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package proto

import (
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
// "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
)
Expand All @@ -36,8 +36,16 @@ func (pseudoResource) DecodeTimeouts(config shim.ResourceConfig) (*shim.Resource
func getSchemaMap[T any](m interface {
GetOk(string) (T, bool)
}, key string) T {
v, ok := m.GetOk(key)
contract.Assertf(ok, "Could not find key %q", key)
v, _ := m.GetOk(key)
// Some functions (such as terraformToPulumiName; link: [1]) do not correctly use
// GetOk, so we can't panic on Get for a missing value, even though that is the
// point of Get.
//
// [^1]: https://github.com/pulumi/pulumi-terraform-bridge/blob/08338be75eedce29c4c2349109d72edc8a38930d/pkg/tfbridge/names.go#L154-L158
//
// contract.Assertf(ok, "Could not find key %q", key)
//
//nolint:lll
return v
}

Expand Down
10 changes: 10 additions & 0 deletions pf/tfbridge/provider_checkconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ func (p *provider) validateProviderConfig(
if k == "version" || k == "pluginDownloadURL" {
continue
}
// TODO[https://github.com/pulumi/pulumi/issues/16757] While #16757 is
// outstanding, we need to filter out the keys for parameterized providers
// from the top level namespace.
//
// We will need to remove this check before we GA dynamic providers.
if p.parameterize != nil {
if k == "name" || k == "parameterization" {
continue
}
}
n := tfbridge.PulumiToTerraformName(string(k), p.schemaOnlyProvider.Schema(), p.info.GetConfig())
_, known := p.configType.AttributeTypes[n]
if !known {
Expand Down

0 comments on commit e665ff6

Please sign in to comment.