pulumi-kubernetes icon indicating copy to clipboard operation
pulumi-kubernetes copied to clipboard

Can't use .metadata.name output from a CustomResource when no metadata field is provided

Open jsravn opened this issue 3 years ago • 2 comments

Hello!

  • Vote on this issue by adding a 👍 reaction
  • To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already)

Issue details

I'm creating a CustomResource without an explicit metadata.name, which pulumi fills in. But I am unable to then use .metadata.name as an input to other resources.

    const githubPRBinding = new kubernetes.apiextensions.CustomResource(
      `${name}-gh-pr-binding`,
      {
        apiVersion: "triggers.tekton.dev/v1beta1",
        kind: "TriggerBinding",
        spec: {
          params: [
            { name: "git-revision", value: "$(body.pull_request.head.sha)" },
            { name: "git-url", value: "$(body.repository.clone_url)" },
            { name: "pr-merged", value: "false" },
          ],
        },
      },
      {
        parent: this,
      }
    );

    const githubPRBindingName = githubPRBinding.metadata.name;

Produces an exception: TypeError: Cannot read properties of undefined (reading 'name').

This approach works on normally typed k8s resources.

jsravn avatar Jan 07 '22 13:01 jsravn

As a workaround, specifying metadata: {} works.

jsravn avatar Jan 07 '22 15:01 jsravn

The title of this ticket could also be written as the below to make the impact & circumstances more clear:

- Can't use .metadata.name output from a CustomResource
+ Can't use .metadata.name output from a CustomResource when there is no metadata arg

hcharley avatar May 03 '22 17:05 hcharley