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

use "pulumi.json#/Resource" in yaml/v2 Resources #2918

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EronWright
Copy link
Contributor

@EronWright EronWright commented Mar 28, 2024

Proposed changes

Updates the resources property on the yaml/v2 resources to have a more specific return type, an array of pulumi.Resource instead of any.

Related issues

Blocked on pulumi/pulumi#6346

Example

Here's an example of a Go SDK program making use of the ConfigMap resource that is constructed by the ConfigGroup.

package main

import (
	corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1"
	yamlv2 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/yaml/v2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		example, err := yamlv2.NewConfigGroup(ctx, "example", &yamlv2.ConfigGroupArgs{
			Objs: pulumi.Array{
				pulumi.Map{
					"apiVersion": pulumi.String("v1"),
					"kind":       pulumi.String("ConfigMap"),
					"metadata": pulumi.Map{
						"name": pulumi.String("my-map"),
					},
				},
			},
		})
		if err != nil {
			return err
		}

		// note: applier function signature changed from `any` to `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)

		return nil
	})
}

Result:

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

Outputs:
    configMapUid: "7ea19ba9-0e34-4b35-87e4-ecc67398b13a"

@EronWright EronWright changed the title use "pulumi.json#/Resource" in ConfigGroup V2 use "pulumi.json#/Resource" in yaml/v2 Resources Mar 28, 2024
@EronWright EronWright self-assigned this Mar 28, 2024
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.

None yet

1 participant