Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue configuring in the normal way #1610

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pf/internal/plugin/provider_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/config"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
pl "github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"
Expand Down Expand Up @@ -200,7 +201,13 @@ func (p *providerServer) CheckConfig(ctx context.Context,
return nil, p.checkNYI("CheckConfig", err)
}

rpcInputs, err := p.configEncoding.MarshalProperties(newInputs)
rpcInputs, err := plugin.MarshalProperties(newInputs, plugin.MarshalOptions{
Label: "config",
KeepUnknowns: true,
SkipNulls: true,
KeepSecrets: true,
RejectAssets: true,
})
if err != nil {
return nil, fmt.Errorf("CheckConfig failed to marshal updated news: %w", err)
}
Expand Down
35 changes: 21 additions & 14 deletions pf/tests/provider_checkconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge"
testutils "github.com/pulumi/pulumi-terraform-bridge/testing/x"
tfbridge0 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
)

func TestCheckConfig(t *testing.T) {
Expand Down Expand Up @@ -107,7 +107,8 @@ func TestCheckConfig(t *testing.T) {
},
}

assert.Equal(t, "04da6b54-80e4-46f7-96ec-b56ff0331ba9", plugin.UnknownStringValue)
assert.Equal(t, "dd056dcd-154b-4c76-9bd3-c8f88648b5ff", plugin.UnknownObjectValue)
assert.Equal(t, "6a19a0b0-7e62-4c92-b797-7f8e31da9cc2", plugin.UnknownArrayValue)
testutils.Replay(t, makeProviderServer(t, schema), `
{
"method": "/pulumirpc.ResourceProvider/CheckConfig",
Expand All @@ -122,8 +123,8 @@ func TestCheckConfig(t *testing.T) {
},
"response": {
"inputs": {
"configValue": "04da6b54-80e4-46f7-96ec-b56ff0331ba9",
"scopes": "04da6b54-80e4-46f7-96ec-b56ff0331ba9",
"configValue": "dd056dcd-154b-4c76-9bd3-c8f88648b5ff",
"scopes": "6a19a0b0-7e62-4c92-b797-7f8e31da9cc2",
"version": "6.54.0"
}
}
Expand Down Expand Up @@ -360,8 +361,8 @@ func TestCheckConfig(t *testing.T) {
},
"response": {
"inputs": {
"batching": "{\"enableBatching\":true,\"sendAfter\":\"1s\"}",
"scopes": "[\"a\",\"b\"]",
"batching": {"enableBatching":true,"sendAfter":"1s"},
"scopes": ["a","b"],
"version": "6.54.0"
}
}
Expand Down Expand Up @@ -439,13 +440,19 @@ func TestCheckConfig(t *testing.T) {
},
"response": {
"inputs": {
"batching": {
"4dabf18193072939515e22adb298388d": "1b47061264138c4ac30d75fd1eb44270",
"value": "{\"enableBatching\":true,\"sendAfter\":\"1s\"}"
},
"scopes": "[\"a\",\"b\"]",
"version": "6.54.0"
}
"batching": {
"enableBatching": true,
"sendAfter": {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great - improved granularity of secret marking.

"4dabf18193072939515e22adb298388d": "1b47061264138c4ac30d75fd1eb44270",
"value": "1s"
}
},
"scopes": [
"a",
"b"
],
"version": "6.54.0"
}
}
}`)
})
Expand Down Expand Up @@ -667,7 +674,7 @@ func TestPreConfigureCallback(t *testing.T) {
"response": {
"inputs": {
"version": "6.54.0",
"configValue": "04da6b54-80e4-46f7-96ec-b56ff0331ba9"
"configValue": "dd056dcd-154b-4c76-9bd3-c8f88648b5ff"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now UnknownObjectValue = "dd056dcd-154b-4c76-9bd3-c8f88648b5ff" ... ever so slightly weird.

}
}
}`)
Expand Down
12 changes: 6 additions & 6 deletions pf/tests/testdata/updateprogram.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
},
"response": {
"inputs": {
"skipMetadataApiCheck": "true",
"skipMetadataApiCheck": true,
"stringDefaultinfoConfigProp": "DEFAULT"
}
},
Expand Down Expand Up @@ -357,7 +357,7 @@
},
"response": {
"inputs": {
"skipMetadataApiCheck": "true",
"skipMetadataApiCheck": true,
"stringDefaultinfoConfigProp": "DEFAULT"
}
},
Expand Down Expand Up @@ -642,7 +642,7 @@
"response": {
"inputs": {
"stringDefaultinfoConfigProp": "DEFAULT",
"skipMetadataApiCheck": "true"
"skipMetadataApiCheck": true
}
},
"metadata": {
Expand Down Expand Up @@ -928,7 +928,7 @@
"response": {
"inputs": {
"stringDefaultinfoConfigProp": "DEFAULT",
"skipMetadataApiCheck": "true"
"skipMetadataApiCheck": true
}
},
"metadata": {
Expand Down Expand Up @@ -1284,7 +1284,7 @@
"response": {
"inputs": {
"stringDefaultinfoConfigProp": "DEFAULT",
"skipMetadataApiCheck": "true"
"skipMetadataApiCheck": true
}
},
"metadata": {
Expand Down Expand Up @@ -1610,7 +1610,7 @@
},
"response": {
"inputs": {
"skipMetadataApiCheck": "true",
"skipMetadataApiCheck": true,
"stringDefaultinfoConfigProp": "DEFAULT"
}
},
Expand Down
8 changes: 7 additions & 1 deletion pkg/tfbridge/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,13 @@ func (p *Provider) CheckConfig(ctx context.Context, req *pulumirpc.CheckRequest)
secretNews := MarkSchemaSecrets(ctx, p.config, p.info.Config, resource.NewObjectProperty(news)).ObjectValue()

// In case news was modified by pre-configure callbacks, marshal it again to send out the modified value.
newsStruct, err := configEnc.MarshalProperties(secretNews)
newsStruct, err := plugin.MarshalProperties(secretNews, plugin.MarshalOptions{
Label: "config",
KeepUnknowns: true,
SkipNulls: true,
KeepSecrets: true,
RejectAssets: true,
})
if err != nil {
return nil, err
}
Expand Down
35 changes: 19 additions & 16 deletions pkg/tfbridge/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,8 @@ func TestCheckConfig(t *testing.T) {
config: shimv2.NewSchemaMap(p.Schema),
}

assert.Equal(t, "04da6b54-80e4-46f7-96ec-b56ff0331ba9", plugin.UnknownStringValue)
assert.Equal(t, "dd056dcd-154b-4c76-9bd3-c8f88648b5ff", plugin.UnknownObjectValue)
assert.Equal(t, "6a19a0b0-7e62-4c92-b797-7f8e31da9cc2", plugin.UnknownArrayValue)

testutils.Replay(t, provider, `
{
Expand All @@ -1037,8 +1038,8 @@ func TestCheckConfig(t *testing.T) {
},
"response": {
"inputs": {
"configValue": "04da6b54-80e4-46f7-96ec-b56ff0331ba9",
"scopes": "04da6b54-80e4-46f7-96ec-b56ff0331ba9",
"configValue": "dd056dcd-154b-4c76-9bd3-c8f88648b5ff",
"scopes": "6a19a0b0-7e62-4c92-b797-7f8e31da9cc2",
"version": "6.54.0"
}
}
Expand Down Expand Up @@ -1245,8 +1246,8 @@ func TestCheckConfig(t *testing.T) {
},
"response": {
"inputs": {
"batching": "{\"enableBatching\":true,\"sendAfter\":\"1s\"}",
"scopes": "[\"a\",\"b\"]",
"batching": {"enableBatching":true,"sendAfter":"1s"},
"scopes": ["a","b"],
"version": "6.54.0"
}
}
Expand Down Expand Up @@ -1292,10 +1293,6 @@ func TestCheckConfig(t *testing.T) {
})

t.Run("enforce_schema_nested_secrets", func(t *testing.T) {
// Flattened compound values may encode that some nested properties are sensitive. There is currently no
// way to preserve the secret-ness accurately in the JSON-in-proto encoding. Instead of this, bridged
// providers approximate and mark the entire property as secret when any of the components are
// sensitive.
p := testprovider.ProviderV2()

p.Schema["scopes"] = &schema.Schema{
Expand Down Expand Up @@ -1342,12 +1339,18 @@ func TestCheckConfig(t *testing.T) {
},
"response": {
"inputs": {
"batching": {
"4dabf18193072939515e22adb298388d": "1b47061264138c4ac30d75fd1eb44270",
"value": "{\"enableBatching\":true,\"sendAfter\":\"1s\"}"
},
"scopes": "[\"a\",\"b\"]",
"version": "6.54.0"
"batching": {
"enableBatching": true,
"sendAfter": {
"4dabf18193072939515e22adb298388d": "1b47061264138c4ac30d75fd1eb44270",
"value": "1s"
}
},
"scopes": [
"a",
"b"
],
"version": "6.54.0"
}
}
}`)
Expand Down Expand Up @@ -1698,7 +1701,7 @@ func TestPreConfigureCallback(t *testing.T) {
"response": {
"inputs": {
"version": "6.54.0",
"configValue": "04da6b54-80e4-46f7-96ec-b56ff0331ba9"
"configValue": "dd056dcd-154b-4c76-9bd3-c8f88648b5ff"
}
}
}`)
Expand Down
4 changes: 4 additions & 0 deletions testing/x/json_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func AssertJSONMatchesPattern(
actual json.RawMessage,
opts ...JSONMatchOption,
) {
t.Helper()

var p, a interface{}

options := jsonMatchOptions{}
Expand Down Expand Up @@ -80,6 +82,7 @@ func AssertJSONMatchesPattern(

var match func(path string, p, a interface{})
match = func(path string, p, a interface{}) {
t.Helper()
switch pp := p.(type) {
case string:
if pp != "*" {
Expand Down Expand Up @@ -161,6 +164,7 @@ func AssertJSONMatchesPattern(
}

func assertJSONEquals(t *testing.T, path string, expected, actual interface{}) {
t.Helper()
assert.Equalf(t, prettyJSON(t, expected), prettyJSON(t, actual), "at %s", path)
}

Expand Down
6 changes: 6 additions & 0 deletions testing/x/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ import (
//
// Replay does not assume that the provider is a bridged provider and can be generally useful.
func Replay(t *testing.T, server pulumirpc.ResourceProviderServer, jsonLog string) {
t.Helper()

ctx := context.Background()
var entry jsonLogEntry
err := json.Unmarshal([]byte(jsonLog), &entry)
Expand Down Expand Up @@ -159,6 +161,8 @@ func Replay(t *testing.T, server pulumirpc.ResourceProviderServer, jsonLog strin
// ReplaySequence is exactly like Replay, but expects jsonLog to encode a sequence of events `[e1, e2, e3]`, and will
// call Replay on each of those events in the given order.
func ReplaySequence(t *testing.T, server pulumirpc.ResourceProviderServer, jsonLog string) {
t.Helper()

var entries []jsonLogEntry
err := json.Unmarshal([]byte(jsonLog), &entries)
assert.NoError(t, err)
Expand All @@ -175,6 +179,8 @@ func replay[Req protoreflect.ProtoMessage, Resp protoreflect.ProtoMessage](
req Req,
serve func(context.Context, Req) (Resp, error),
) {
t.Helper()

ctx := context.Background()

err := jsonpb.Unmarshal([]byte(entry.Request), req)
Expand Down