mirror of https://github.com/pulumi/pulumi.git
e88cd05f52
### Description This PR addresses https://github.com/pulumi/pulumi/issues/17788 by implementing a `pulumi.DeferredOutput(ctx)` function which can be used for generating Go programs with mutually dependant components. The implementation is as follows: ```go // <sdk/go/internal/types.go> // DeferredOutput creates an Output whose value can be later resolved from another Output instance. func DeferredOutput[T any](ctx context.Context) (pulumix.Output[T], func(Output)) { var zero T rt := reflect.TypeOf(zero) state := internal.NewOutputState(nil, rt) out := pulumix.Output[T]{OutputState: state} resolve := func(o Output) { go func() { v, known, secret, deps, err := internal.AwaitOutput(ctx, o) if err != nil { internal.RejectOutput(state, err) return } internal.ResolveOutput(out, v, known, secret, deps) }() } return out, resolve } ``` This PR implements the usage of this function in Go program-gen but the results are far from ideal: - ~Usage of deferred output variables requires an explicit cast from `AnyOutput` to the target output type where it was used~ Now correctly casting from the generic output type to target component inputs - Generating lists of referenced components via a `ForExpression` emits `"TODO: For expression"` Example generated code in programs: ```go secondPasswordLength, resolveSecondPasswordLength := pulumi.DeferredOutput[int](ctx) first, err := NewFirst(ctx, "first", &FirstArgs{ PasswordLength: pulumix.Cast[pulumi.IntOutput](secondPasswordLength), }) ``` Fixes #17788 --------- Co-authored-by: Julien <julien@caffeine.lu> |
||
---|---|---|
.. | ||
gen_program_test | ||
doc.go | ||
doc_test.go | ||
embeddedUtilities.go | ||
gen.go | ||
gen_program.go | ||
gen_program_expression_test.go | ||
gen_program_expressions.go | ||
gen_program_inline_invoke.go | ||
gen_program_json.go | ||
gen_program_optionals.go | ||
gen_program_read_dir.go | ||
gen_program_splat.go | ||
gen_program_ternaries.go | ||
gen_program_test.go | ||
gen_program_utils.go | ||
gen_spill.go | ||
gen_test.go | ||
importer.go | ||
utilities.go | ||
utilities_test.go |