diff --git a/changelog/pending/20221206--pkg--fixes-codegen-python-nonstring-secrets.yaml b/changelog/pending/20221206--pkg--fixes-codegen-python-nonstring-secrets.yaml new file mode 100644 index 000000000000..2faf39de7052 --- /dev/null +++ b/changelog/pending/20221206--pkg--fixes-codegen-python-nonstring-secrets.yaml @@ -0,0 +1,4 @@ +changes: +- type: fix + scope: pkg + description: Fixes codegen/python generation of non-string secrets in provider properties diff --git a/pkg/codegen/python/gen.go b/pkg/codegen/python/gen.go index 3dcbe76973ee..c5e0d860f826 100644 --- a/pkg/codegen/python/gen.go +++ b/pkg/codegen/python/gen.go @@ -1301,11 +1301,17 @@ func (mod *modContext) genResource(res *schema.Resource) (string, error) { // If this resource is a provider then, regardless of the schema of the underlying provider // type, we must project all properties as strings. For all properties that are not strings, // we'll marshal them to JSON and use the JSON string as a string input. + handledSecret := false if res.IsProvider && !isStringType(prop.Type) { - arg = fmt.Sprintf("pulumi.Output.from_input(%s).apply(pulumi.runtime.to_json) if %s is not None else None", arg, arg) + if prop.Secret { + arg = fmt.Sprintf("pulumi.Output.secret(%s).apply(pulumi.runtime.to_json) if %s is not None else None", arg, arg) + handledSecret = true + } else { + arg = fmt.Sprintf("pulumi.Output.from_input(%s).apply(pulumi.runtime.to_json) if %s is not None else None", arg, arg) + } } name := PyName(prop.Name) - if prop.Secret { + if prop.Secret && !handledSecret { fmt.Fprintf(w, " __props__.__dict__[%[1]q] = None if %[2]s is None else pulumi.Output.secret(%[2]s)\n", name, arg) } else { fmt.Fprintf(w, " __props__.__dict__[%q] = %s\n", name, arg) diff --git a/pkg/codegen/testing/test/sdk_driver.go b/pkg/codegen/testing/test/sdk_driver.go index a105126bb887..398563c5ae96 100644 --- a/pkg/codegen/testing/test/sdk_driver.go +++ b/pkg/codegen/testing/test/sdk_driver.go @@ -151,9 +151,10 @@ var PulumiPulumiSDKTests = []*SDKTest{ Description: "Simple schema encoded using YAML", }, { - Directory: "provider-config-schema", - Description: "Simple provider config schema", - SkipCompileCheck: codegen.NewStringSet(dotnet), + Directory: "provider-config-schema", + Description: "Simple provider config schema", + // For golang skip check, see https://github.com/pulumi/pulumi/issues/11567 + SkipCompileCheck: codegen.NewStringSet(dotnet, golang), }, { Directory: "replace-on-change", diff --git a/pkg/codegen/testing/test/testdata/provider-config-schema/docs/_index.md b/pkg/codegen/testing/test/testdata/provider-config-schema/docs/_index.md index c4b5d9778cee..9b2a218610f0 100644 --- a/pkg/codegen/testing/test/testdata/provider-config-schema/docs/_index.md +++ b/pkg/codegen/testing/test/testdata/provider-config-schema/docs/_index.md @@ -1,6 +1,6 @@ --- title: "configstation" -title_tag: "configstation.configstation" +title_tag: "configstation Package" meta_desc: "" layout: api no_edit_this_page: true @@ -11,6 +11,11 @@ no_edit_this_page: true +

Modules

+ +

Resources