pulumi/tests/testdata
Zaid Ajaj e88cd05f52
[sdk/program-gen] Implementing DeferredOutput for Go SDK and program-gen (#17885)
### 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>
2025-01-04 18:47:30 +00:00
..
aws_tf Add an envar to disable automatic provider installation (#14083) 2023-10-03 15:35:23 +00:00
bad_random_pp Make convert more lenient 2023-06-08 11:14:31 +01:00
codegen [sdk/program-gen] Implementing DeferredOutput for Go SDK and program-gen (#17885) 2025-01-04 18:47:30 +00:00
component_pp Test components in convert 2023-06-01 20:54:44 +01:00
import_node Fix flakey test (#15311) 2024-01-30 14:08:47 +00:00
random_pp Add per-language smoke tests to the integration tests 2023-05-06 09:23:19 +01:00
random_yaml Add a simple yaml convert smoke test 2023-08-09 17:48:41 +01:00
relative_plugin_node Ensure project plugins are absolute paths (#15470) 2024-02-22 11:43:18 +00:00
simple_schema Add per-language smoke tests to the integration tests 2023-05-06 09:23:19 +01:00
simple_tags Cover bool like and number like values in pulumi:tags test (#14092) 2023-10-07 18:27:03 +00:00