pulumi/sdk/go/pulumi
Julien b74842933d
Avoid calling invokes with dependencies on unknown resources (#18133)
DependsOn for resources is an ordering constraint for register resource
calls. If a resource R1 depends on a resource R2, the register resource
call for R2 will happen after R1. This is ensured by awaiting the URN
for each resource dependency before calling register resource.

For invokes, this causes a problem when running under preview. During
preview, register resource immediately returns with the URN, however
this does not tell us if the resource "exists".

Instead of waiting for the dependency's URN, we wait for the ID. This
tells us that whether a physical resource exists (if the state is in
sync), and we can avoid calling the invoke when it is unknown.

The following example fails without this change:
```go
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/compute"
	"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/organizations"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		conf := config.New(ctx, "")
		billingAccountId := conf.Require("billing-account")
		billingAccount, err := organizations.GetBillingAccount(ctx, &organizations.GetBillingAccountArgs{
			BillingAccount: &billingAccountId,
		})
		if err != nil {
			return err
		}

		project, err := organizations.NewProject(ctx, "my-project", &organizations.ProjectArgs{
			Name:              pulumi.StringPtr("project-go"),
			AutoCreateNetwork: pulumi.BoolPtr(false),
			DeletionPolicy:    pulumi.StringPtr("DELETE"),
			BillingAccount:    pulumi.StringPtr(*billingAccount.BillingAccount),
		})
		if err != nil {
			return err
		}

		zonesOutput := compute.GetZonesOutput(ctx, compute.GetZonesOutputArgs{
			Region:  pulumi.StringPtr("us-central1"),
			Project: project.ProjectId,
			Status:  pulumi.StringPtr("UP"),
		},
			pulumi.DependsOn([]pulumi.Resource{project}),
		)

		ctx.Export("zones", zonesOutput)

		return nil
	})
}
```

With the change to wait for the CustomResource.ID, this correctly
returns an unknown during preview for `zones`.
2025-01-06 08:46:33 +00:00
..
config Clean up uses of .Error() (#14965) 2023-12-20 15:54:06 +00:00
errors allow better grpc error messages from Go component providers (#17464) 2024-10-10 07:13:31 +00:00
generate Add StringMapMapMap to Go SDK (#17417) 2024-09-29 10:05:30 +00:00
internals Use EqualError/ErrorContains instead of Error (#14737) 2023-12-08 06:40:14 +00:00
provider Prepare golangci-lint upgrade (#17065) 2024-08-28 07:57:38 +00:00
alias.go all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
alias_test.go ci: radical idea - what if slow tests & no stdout makes GH consider runner dead? 2022-03-06 14:52:13 -08:00
asset.go [sdk/{go,dotnet] Unmarshal invalid assets. (#7579) 2021-07-21 13:40:36 -07:00
callback.go fix potential concurrent map write in Go transforms (#16444) 2024-06-24 09:35:52 +00:00
context.go Avoid calling invokes with dependencies on unknown resources (#18133) 2025-01-06 08:46:33 +00:00
context_test.go Return when rejecting the InvokeOutput output on error (#18010) 2024-12-11 18:25:01 +00:00
internals.go sdk/go: Move Output implementation to internal 2023-07-25 18:13:35 -07:00
log.go chore: Update doc comments, coding style, fix lint 2022-10-13 13:50:49 -07:00
mocks.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
printf.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
printf_test.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
provider.go allow InputPropertyErrors from Calls (#17567) 2024-11-07 09:56:04 +00:00
provider_linked.go all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
provider_test.go Await output properties before closing the context (#15611) 2024-03-08 23:17:42 +00:00
resource.go Avoid calling invokes with dependencies on unknown resources (#18133) 2025-01-06 08:46:33 +00:00
resource_set.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
resource_test.go Avoid calling invokes with dependencies on unknown resources (#18133) 2025-01-06 08:46:33 +00:00
rpc.go Avoid calling invokes with dependencies on unknown resources (#18133) 2025-01-06 08:46:33 +00:00
rpc_test.go Inherit `protect` from `parent`s in the Go SDK (#17936) 2024-12-05 17:14:46 +00:00
run.go Use int32 in Go interfaces that map to protobufs using int32 (#17068) 2024-08-28 13:45:17 +00:00
run_test.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
stack_reference.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
stack_reference_test.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
transform.go add Go support for invoke transforms (#16617) 2024-07-15 08:28:11 +00:00
transformation.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
type_conversions.go [codegen/go] Improve optional params in invoke 2022-02-01 11:44:40 -08:00
types.go [sdk/program-gen] Implementing DeferredOutput for Go SDK and program-gen (#17885) 2025-01-04 18:47:30 +00:00
types_builtins.go Add StringMapMapMap to Go SDK (#17417) 2024-09-29 10:05:30 +00:00
types_builtins_test.go Add StringMapMapMap to Go SDK (#17417) 2024-09-29 10:05:30 +00:00
types_contravariance_test.go Use slice.Prealloc instead of make([]T, 0, ...) 2023-06-29 11:27:50 +01:00
types_test.go [sdk/program-gen] Implementing DeferredOutput for Go SDK and program-gen (#17885) 2025-01-04 18:47:30 +00:00
urnset.go Avoid calling invokes with dependencies on unknown resources (#18133) 2025-01-06 08:46:33 +00:00