Repository: pulumi/pulumi-terraform-bridge
Pull request #325 (2021-02-05 20:12:19)

Upgrade to Pulumi v2.20.0

github-actions[bot]: Diff for [pulumi-random](https://github.com/pulumi-bot/pulumi-random/compare/8676a74..3ae388a) with merge commit a3aabd17a3d752b4b7a9f23b1d3e4a3868f19040
github-actions[bot]: Diff for [pulumi-azuread](https://github.com/pulumi-bot/pulumi-azuread/compare/7ff5d3b..62b258d) with merge commit a3aabd17a3d752b4b7a9f23b1d3e4a3868f19040
github-actions[bot]: Diff for [pulumi-gcp](https://github.com/pulumi-bot/pulumi-gcp/compare/76c3d355..0af74880) with merge commit a3aabd17a3d752b4b7a9f23b1d3e4a3868f19040
github-actions[bot]: Diff for [pulumi-azure](https://github.com/pulumi-bot/pulumi-azure/compare/44c60338e..753e192d3) with merge commit a3aabd17a3d752b4b7a9f23b1d3e4a3868f19040
github-actions[bot]: Diff for [pulumi-aws](https://github.com/pulumi-bot/pulumi-aws/compare/9ae8604f2..fdc087e05) with merge commit a3aabd17a3d752b4b7a9f23b1d3e4a3868f19040

Patch:
diff --git a/go.mod b/go.mod
index 9cfff91a..4f6a664b 100644
--- a/go.mod
+++ b/go.mod
@@ -33,8 +33,8 @@ require (
 	github.com/mitchellh/mapstructure v1.4.0
 	github.com/mitchellh/reflectwalk v1.0.1
 	github.com/pkg/errors v0.9.1
-	github.com/pulumi/pulumi/pkg/v2 v2.18.0
-	github.com/pulumi/pulumi/sdk/v2 v2.18.0
+	github.com/pulumi/pulumi/pkg/v2 v2.20.0
+	github.com/pulumi/pulumi/sdk/v2 v2.20.0
 	github.com/pulumi/terraform-diff-reader v0.0.0-20201211191010-ad4715e9285e
 	github.com/spf13/afero v1.2.2
 	github.com/spf13/cobra v1.0.0
diff --git a/go.sum b/go.sum
index 3a513b76..3c87f6c1 100644
--- a/go.sum
+++ b/go.sum
@@ -515,11 +515,11 @@ github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
 github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
 github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
 github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
-github.com/pulumi/pulumi/pkg/v2 v2.18.0 h1:vH+VyzpxWZVW7CSJ7ThD0w6uKXQa5j+TptzyQM6eT2o=
-github.com/pulumi/pulumi/pkg/v2 v2.18.0/go.mod h1:bAbzFeU3gHu1diqcckqUqaFf5dP02BfJlP8dnHwm00k=
+github.com/pulumi/pulumi/pkg/v2 v2.20.0 h1:E9x8OFgyE/oQPuTGO9g2z5Coh3TtXCG2L9m04t4zgdU=
+github.com/pulumi/pulumi/pkg/v2 v2.20.0/go.mod h1:bAbzFeU3gHu1diqcckqUqaFf5dP02BfJlP8dnHwm00k=
 github.com/pulumi/pulumi/sdk/v2 v2.2.1/go.mod h1:QNbWpL4gvf3X0lUFT7TXA2Jo1ff/Ti2l97AyFGYwvW4=
-github.com/pulumi/pulumi/sdk/v2 v2.18.0 h1:fOno92mnb/4xoVV+TqtQG0W6KCJLe87JyfBVVhZ8voE=
-github.com/pulumi/pulumi/sdk/v2 v2.18.0/go.mod h1:fCFhRV6NmidWetmgDPA76efL+s0JqLlS54JJIwfOt+o=
+github.com/pulumi/pulumi/sdk/v2 v2.20.0 h1:Y4lUewm7YhAXz7R/m1M8w5X2o20BnxBq3ka6jmM6bAE=
+github.com/pulumi/pulumi/sdk/v2 v2.20.0/go.mod h1:fCFhRV6NmidWetmgDPA76efL+s0JqLlS54JJIwfOt+o=
 github.com/pulumi/terraform-diff-reader v0.0.0-20201211191010-ad4715e9285e h1:Dik4Qe/+xguB8JagPyXNlbOnRiXGmq/PSPQTGunYnTk=
 github.com/pulumi/terraform-diff-reader v0.0.0-20201211191010-ad4715e9285e/go.mod h1:sZ9FUzGO+yM41hsQHs/yIcj/Y993qMdBxBU5mpDmAfQ=
 github.com/pulumi/terraform-plugin-sdk/v2 v2.0.0-20201219002103-53f910a1ea61 h1:n44snmoisMPJuF1LF3/kkKf1BBiGaYyEapFRLIlAHRc=
diff --git a/pkg/tfbridge/provider.go b/pkg/tfbridge/provider.go
index e29fbecf..d6e97633 100644
--- a/pkg/tfbridge/provider.go
+++ b/pkg/tfbridge/provider.go
@@ -524,24 +524,21 @@ func (p *Provider) Configure(ctx context.Context,
 		return nil, errors.Wrap(err, "could not marshal config state")
 	}
 
-	if req.Variables == nil {
-		// We only follow this path if the CLI hasbn't already called CheckConfig
-		if p.info.PreConfigureCallback != nil {
-			if err = p.info.PreConfigureCallback(vars, config); err != nil {
-				return nil, err
-			}
-		}
-
-		missingKeys, validationErrors := validateProviderConfig(ctx, p, config)
-		if len(missingKeys) > 0 {
-			err = rpcerror.WithDetails(
-				rpcerror.New(codes.InvalidArgument, "required configuration keys were missing"),
-				&pulumirpc.ConfigureErrorMissingKeys{MissingKeys: missingKeys})
+	if p.info.PreConfigureCallback != nil {
+		if err = p.info.PreConfigureCallback(vars, config); err != nil {
 			return nil, err
 		}
-		if validationErrors != nil {
-			return nil, validationErrors
-		}
+	}
+
+	missingKeys, validationErrors := validateProviderConfig(ctx, p, config)
+	if len(missingKeys) > 0 {
+		err = rpcerror.WithDetails(
+			rpcerror.New(codes.InvalidArgument, "required configuration keys were missing"),
+			&pulumirpc.ConfigureErrorMissingKeys{MissingKeys: missingKeys})
+		return nil, err
+	}
+	if validationErrors != nil {
+		return nil, validationErrors
 	}
 
 	// Now actually attempt to do the configuring and return its resulting error (if any).


Test patch:
diff --git a/pkg/tfbridge/provider_test.go b/pkg/tfbridge/provider_test.go
index c63b37e8..457efd95 100644
--- a/pkg/tfbridge/provider_test.go
+++ b/pkg/tfbridge/provider_test.go
@@ -2,6 +2,7 @@ package tfbridge
 
 import (
 	"context"
+	"errors"
 	"sort"
 	"testing"
 
@@ -518,3 +519,35 @@ func TestProviderCheckV2(t *testing.T) {
 	assert.Equal(t, "Required attribute is not set", failures[2].Reason)
 	assert.Equal(t, "", failures[2].Property)
 }
+
+func testProviderPreConfigureCallback(t *testing.T, provider *Provider) {
+	expectedErr := errors.New("failedToPreConfigure")
+	provider.info = ProviderInfo{
+		PreConfigureCallback: func(vars resource.PropertyMap, config shim.ResourceConfig) error {
+			return expectedErr
+		},
+	}
+	_, err := provider.Configure(context.Background(), &pulumirpc.ConfigureRequest{
+		Variables: map[string]string{
+			"foo:config:bar": "invalid",
+		},
+	})
+	assert.Equal(t, expectedErr, err)
+}
+
+func TestProviderPreConfigureCallbackV1(t *testing.T) {
+	provider := &Provider{
+		tf:     shimv1.NewProvider(testTFProvider),
+		config: shimv1.NewSchemaMap(testTFProvider.Schema),
+	}
+	testProviderPreConfigureCallback(t, provider)
+
+}
+
+func TestProviderPreConfigureCallbackV2(t *testing.T) {
+	provider := &Provider{
+		tf:     shimv2.NewProvider(testTFProviderV2),
+		config: shimv2.NewSchemaMap(testTFProviderV2.Schema),
+	}
+	testProviderPreConfigureCallback(t, provider)
+}