-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[codegen/go] Fix Go resource registrations #6641
Conversation
We've been emitting calls to `New<Resource>` for resource registrations in Go, passing `nil` for args. However, some of those `New<Resource>` functions actually check for `nil` args and return an error if the resource has required arguments. At first, I was looking for a way to check inside `New<Resource>` if the `URN` option was specified and in that case not error on `nil` args (like we do in other languages), but we don't provide a way to access the resource option values outside the Go SDK), so I don't think there is a way to do it this way for Go. So instead, this change updates the registration code to call `ctx.RegisterResource` directly instead of `New<Resource>`, where we can pass a `nil` args.
Diff for pulumi-random with merge commit ce338d8 |
Diff for pulumi-kubernetes with merge commit ce338d8 |
Diff for pulumi-azuread with merge commit ce338d8 |
Diff for pulumi-gcp with merge commit ce338d8 |
I confirmed that this fix worked by compiling new versions of package main
import (
"os"
"github.com/pulumi/pulumi-aws/sdk/v3/go/aws/iam"
"github.com/pulumi/pulumi-eks/sdk/go/eks"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
eksCluster, err := eks.NewCluster(ctx, "eks-cluster", &eks.ClusterArgs{
InstanceType: pulumi.String("t2.medium"),
DesiredCapacity: pulumi.Int(1),
MaxSize: pulumi.Int(1),
MinSize: pulumi.Int(1),
CreateOidcProvider: pulumi.Bool(true),
ProviderCredentialOpts: &eks.KubeconfigOptionsArgs{
ProfileName: pulumi.String(os.Getenv("AWS_PROFILE")),
},
})
if err != nil {
return err
}
oidcUrl := eksCluster.Core.OidcProvider().ApplyT(
func(oidc *iam.OpenIdConnectProvider) pulumi.StringOutput { return oidc.Url })
ctx.Export("oidcUrl", oidcUrl)
return nil
})
} |
Diff for pulumi-random with merge commit ce338d8 |
Diff for pulumi-azuread with merge commit ce338d8 |
Diff for pulumi-kubernetes with merge commit ce338d8 |
Thanks for the help, @lblackstone! |
Diff for pulumi-gcp with merge commit ce338d8 |
Diff for pulumi-azure with merge commit ce338d8 |
Diff for pulumi-aws with merge commit ce338d8 |
Diff for pulumi-azure-native with merge commit ce338d8 |
Thanks for the fix, @justinvp! |
- [sdk/go] Fix Go resource registrations (pulumi/pulumi#6641) - [sdk/python] Support `<Resource>Args` classes (pulumi/pulumi#6525)
- [sdk/go] Fix Go resource registrations (pulumi/pulumi#6641) - [sdk/python] Support `<Resource>Args` classes (pulumi/pulumi#6525)
- [sdk/go] Fix Go resource registrations (pulumi/pulumi#6641) - [sdk/python] Support `<Resource>Args` classes (pulumi/pulumi#6525)
- [sdk/go] Fix Go resource registrations (pulumi/pulumi#6641) - [sdk/python] Support `<Resource>Args` classes (pulumi/pulumi#6525)
We've been emitting calls to
New<Resource>
for resource registrations in Go, passingnil
for args. However, some of thoseNew<Resource>
functions actually check fornil
args and return an error if the resource has required arguments.At first, I was looking for a way to check inside
New<Resource>
if theURN
option was specified and in that case not error onnil
args (like we do in other languages), but we don't provide a way to access the resource option values outside the Go SDK), so I don't think there is a way to do it this way for Go.So instead, this change updates the registration code to call
ctx.RegisterResource
directly instead ofNew<Resource>
, where we can pass anil
args.Fixes pulumi/pulumi-eks#537