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

feat: Package Schema resource-typed properties #15795

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

AaronFriel
Copy link
Member

A new built-in type, pulumi.json#/Resource is added to the schema to refer to any resource. This unblocks schematizing resources like kubernetes.yaml/v2.ConfigFile, which ideally would declare an output like so:

            "properties": {
                "resources": {
                    "type": "array",
                    "items": {
                        "$ref": "pulumi.json#/Resource"
                    },
                    "description": "Resources created by the ConfigFile."
                }
            },

This is a small ergonomic improvement over pulumi.json#/Any, and fixes #6346.

@AaronFriel AaronFriel requested a review from a team as a code owner March 27, 2024 01:56
@AaronFriel AaronFriel added the impact/no-changelog-required This issue doesn't require a CHANGELOG update label Mar 27, 2024
@pulumi-bot
Copy link
Contributor

pulumi-bot commented Mar 27, 2024

Changelog

[uncommitted] (2024-04-30)

Features

  • [sdkgen] Support resource-typed input and output properties
    #15795

@AaronFriel AaronFriel removed the impact/no-changelog-required This issue doesn't require a CHANGELOG update label Mar 27, 2024
@EronWright
Copy link
Contributor

EronWright commented Mar 28, 2024

I tested this feature branch (which also contains the unmarshaling fix) with the pulumi-kubernetes provider and it seems to work really well. Here's the patch that I applied:
https://github.com/pulumi/pulumi-kubernetes/compare/eronwright/any-resource?expand=1

Then I updated my example (note the func signature in ApplyT now uses pulumi.Resource):

uid := example.Resources.Index(pulumi.Int(0)).ApplyT(func(r pulumi.Resource) pulumi.StringPtrOutput {
    ctx.Log.Info("I'm a good ConfigMap", &pulumi.LogArgs{Resource: r})
    configMap := r.(*corev1.ConfigMap)
    return configMap.Metadata.Uid()
})
ctx.Export("configMapUid", uid)

And the results were as-expected:

Diagnostics:
  kubernetes:core/v1:ConfigMap (example:default/my-map):
    I'm a good ConfigMap

Outputs:
    configMapUid: "57586778-16d5-4840-931b-d9a2b6a1f4a7"

pkg/codegen/schema/schema.go Outdated Show resolved Hide resolved
sdk/go/pulumi/rpc.go Outdated Show resolved Hide resolved
tests/integration/any_resource_types/go/echo_resource.go Outdated Show resolved Hide resolved
tests/integration/any_resource_types/go_test.go Outdated Show resolved Hide resolved
Comment on lines 74 to +75
case anyResourceType:
fallthrough
return "pulumi:pulumi:Resource"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need this block to be above the jsonType, or jsonType should stop leaning on fallthrough.

AaronFriel and others added 5 commits April 30, 2024 09:38
A new built-in type, `pulumi.json#/Resource` is added to the schema to refer to
any resource. This unblocks schematizing resources like
`kubernetes.yaml/v2.ConfigFile`, which ideally would declare an output like so:

```json
            "properties": {
                "resources": {
                    "type": "array",
                    "items": {
                        "$ref": "pulumi.json#/Resource"
                    },
                    "description": "Resources created by the ConfigFile."
                }
            },
```

This is a small ergonomic improvement over `pulumi.json#/Any`, and fixes #6346.
This moves more of the Resource type's implementation to the generated
`types_builins.go`.
This PR unblocks the integration test below, which modified the Echo provider
to pass-through its inputs to outputs - including resources.

There remains a bug in re-marshaling a resource inside a provider that we avoid
by simplifying `Create()` to pass-through. This is or is related to #15788.
Co-authored-by: Eron Wright <eron@pulumi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support generic Pulumi resource types in schema
6 participants