Repository: pulumi/pulumi-terraform-bridge
Pull request #284 (2020-10-08 11:05:33)

Supply user error about which config values were missing
Fixes: #282

A regression removed this and it meant that when a user didn't
supply the correct config values, that they got the following error:

```
  aws:s3:Bucket (my-bucket):
    error: required configuration keys were missing
```

That had no context. Fixing the regression now shows this error:

```
  aws:s3:Bucket (my-bucket):
    error: 1 error occurred:
    	* missing required configuration key "aws:region": The region where AWS operations will take place. Examples are us-east-1, us-west-2, etc.
    Set a value using the command `pulumi config set aws:region <value>`.
```

github-actions[bot]: Diff for [pulumi-random](https://github.com/pulumi-bot/pulumi-random/compare/e1af1ba..a6ee4f0) with merge commit a1cf89c52f6bedca099b714292684241f5e74df1
github-actions[bot]: Diff for [pulumi-azuread](https://github.com/pulumi-bot/pulumi-azuread/compare/9e0ce39..9f8de7b) with merge commit a1cf89c52f6bedca099b714292684241f5e74df1
github-actions[bot]: Diff for [pulumi-azure](https://github.com/pulumi-bot/pulumi-azure/compare/d15281b6..3f4be696) with merge commit a1cf89c52f6bedca099b714292684241f5e74df1
github-actions[bot]: Diff for [pulumi-aws](https://github.com/pulumi-bot/pulumi-aws/compare/4b53d7885..5551a7cc9) with merge commit a1cf89c52f6bedca099b714292684241f5e74df1
github-actions[bot]: Diff for [pulumi-gcp](https://github.com/pulumi-bot/pulumi-gcp/compare/0f58f9ea..caf2a5e5) with merge commit a1cf89c52f6bedca099b714292684241f5e74df1

Patch:
diff --git a/pkg/tfbridge/provider.go b/pkg/tfbridge/provider.go
index 70894923..93a55bf6 100644
--- a/pkg/tfbridge/provider.go
+++ b/pkg/tfbridge/provider.go
@@ -351,7 +351,7 @@ func buildTerraformConfig(p *Provider, vars resource.PropertyMap) (shim.Resource
 		}
 	}
 
-	inputs, _, err := MakeTerraformInputs(nil, tfVars, nil, nil, p.config, p.info.Config)
+	inputs, _, err := MakeTerraformInputs(nil, tfVars, nil, tfVars, p.config, p.info.Config)
 	if err != nil {
 		return nil, err
 	}
@@ -360,9 +360,9 @@ func buildTerraformConfig(p *Provider, vars resource.PropertyMap) (shim.Resource
 }
 
 func validateProviderConfig(ctx context.Context, p *Provider, config shim.ResourceConfig) (
-	[]*pulumirpc.CheckFailure, error) {
+	[]*pulumirpc.ConfigureErrorMissingKeys_MissingKey, error) {
 
-	var missingKeys []*pulumirpc.CheckFailure
+	var missingKeys []*pulumirpc.ConfigureErrorMissingKeys_MissingKey
 	p.config.Range(func(key string, meta shim.Schema) bool {
 		if meta.Required() && !config.IsSet(key) {
 			name := TerraformToPulumiName(key, meta, nil, false)
@@ -371,9 +371,9 @@ func validateProviderConfig(ctx context.Context, p *Provider, config shim.Resour
 			// TF descriptions often have newlines in inopportune positions. This makes them present
 			// a little better in our console output.
 			descriptionWithoutNewlines := strings.Replace(meta.Description(), "\n", " ", -1)
-			missingKeys = append(missingKeys, &pulumirpc.CheckFailure{
-				Property: fullyQualifiedName.String(),
-				Reason:   descriptionWithoutNewlines,
+			missingKeys = append(missingKeys, &pulumirpc.ConfigureErrorMissingKeys_MissingKey{
+				Name:        fullyQualifiedName.String(),
+				Description: descriptionWithoutNewlines,
 			})
 		}
 		return true
@@ -536,7 +536,7 @@ func (p *Provider) Configure(ctx context.Context,
 		if len(missingKeys) > 0 {
 			err = rpcerror.WithDetails(
 				rpcerror.New(codes.InvalidArgument, "required configuration keys were missing"),
-				&pulumirpc.CheckResponse{Failures: missingKeys})
+				&pulumirpc.ConfigureErrorMissingKeys{MissingKeys: missingKeys})
 			return nil, err
 		}
 		if validationErrors != nil {


Test patch:
diff --git a/pkg/tfbridge/provider_test.go b/pkg/tfbridge/provider_test.go
index 20e5374c..b65c8bb9 100644
--- a/pkg/tfbridge/provider_test.go
+++ b/pkg/tfbridge/provider_test.go
@@ -175,3 +175,22 @@ func TestDiffConfig(t *testing.T) {
 	assert.True(t, resp.HasDetailedDiff)
 	assert.Len(t, resp.DetailedDiff, 1)
 }
+
+func TestBuildConfig(t *testing.T) {
+	provider := &Provider{
+		tf:     shimv1.NewProvider(testTFProvider),
+		config: shimv1.NewSchemaMap(testTFProvider.Schema),
+	}
+
+	configIn := resource.PropertyMap{
+		"configValue": resource.NewStringProperty("foo"),
+		"version":     resource.NewStringProperty("0.0.1"),
+	}
+	configOut, err := buildTerraformConfig(provider, configIn)
+	assert.NoError(t, err)
+
+	expected := provider.tf.NewResourceConfig(map[string]interface{}{
+		"config_value": "foo",
+	})
+	assert.Equal(t, expected, configOut)
+}