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

Missing Output-based function calls in generated code #393

Open
kylepl opened this issue Nov 3, 2023 · 6 comments
Open

Missing Output-based function calls in generated code #393

kylepl opened this issue Nov 3, 2023 · 6 comments
Assignees

Comments

@kylepl
Copy link

kylepl commented Nov 3, 2023

While waiting on #389, I've managed to get the Kotlin version building locally, and can use it (mainly) reasonably.

One thing I've noticed though, is for functions, there is only the "PlainArgs" versions, not the "Args" version which is output-based.

e.g. for getConnectionString (see the schema) all that is generated is:

public final suspend fun getConnectionString(database: kotlin.String? = COMPILED_CODE, id: kotlin.String, os: kotlin.String? = COMPILED_CODE, password: kotlin.String? = COMPILED_CODE, sqlUser: kotlin.String? = COMPILED_CODE): com.pulumi.cockroach.kotlin.outputs.GetConnectionStringResult { }

public final suspend fun getConnectionString(argument: suspend com.pulumi.cockroach.kotlin.inputs.GetConnectionStringPlainArgsBuilder.() -> kotlin.Unit): com.pulumi.cockroach.kotlin.outputs.GetConnectionStringResult { }

while I'm expecting one that takes in GetConnectionStringArgsBuilder as well.

When I inspect the generated Java that the Kotlin is wrapping, I do see GetConnectionStringArgs, in addition to GetConnectionStringPlainArgs.

Now it's possible I've misconfigured something, so not trying to waste too much time - just checking if this is a known issue or has an obvious mis-configuration on my part.

@kylepl
Copy link
Author

kylepl commented Nov 3, 2023

I've realized that this also applies to examples like DigitalOcean, which is already integrated. e.g. getDomain in DigitalOcean only has bindings for GetDomainPlainArgsBuilder even though the underlying Java bindings have a GetDomainArgs in addition to GetDomainPlainArgs.

For a full example there is these two in DigitalOcean Java:

public static Output<GetDomainResult> getDomain(GetDomainArgs args, InvokeOptions options) {
    return Deployment.getInstance().invoke("digitalocean:index/getDomain:getDomain", TypeShape.of(GetDomainResult.class), args, Utilities.withVersion(options));
}

public static CompletableFuture<GetDomainResult> getDomainPlain(GetDomainPlainArgs args, InvokeOptions options) {
    return Deployment.getInstance().invokeAsync("digitalocean:index/getDomain:getDomain", TypeShape.of(GetDomainResult.class), args, Utilities.withVersion(options));
}

Thus, not specific to Cockroach.

I would note, that the Pulumi documentation about this is out-of-date, not that it says "// Output-based functions aren't available in Java yet" when Java is selected - which seems to have been fixed.

Thus my summary is this is a missing feature. Not sure what the difficulty is.

@jplewa
Copy link
Member

jplewa commented Nov 6, 2023

To be honest, Java has been making some wild breaking changes with this one:

image image

We intentionally added only one version, as we assumed the "plain" version would be sufficient, but I can look into adding an output-based one if you find it valuable.

@jplewa jplewa self-assigned this Nov 6, 2023
@kylepl
Copy link
Author

kylepl commented Nov 6, 2023

Yeah, those kind of breaking changes are tough.

In my case, I'm new to Kotlin, so perhaps I'm missing how this can be done easily, so if I have some Output foo, and trying to call wrapped-function exampleFunction, where exampleFunction is imported from the Java bindings, right now, from within a Pulumi.run:

val result = exampleFunction(ExampleFunctionArgs.Builder().id(foo).build())

and this works, but of course is a different style then everything else.

I've been unable to figure out a way to call the simple-input Kotlin functions given the Output. applyValue doesn't like the suspend'able function called in it.

So if there is any easy way for that to be written concisely, great, otherwise, for me at least, the Output-based version would be quite useful. Or perhaps it means that a wrapped Output with an applyValue that takes suspendable functions would be useful. But also the docs say that func is not allowed to make resources, so maybe my attempt was just wrong anyways.

@jplewa
Copy link
Member

jplewa commented Nov 6, 2023

Could you tell me what function you're using? I looked at the arguments of some plain/Output versions in Java and I don't see outputs in any of them, but I might be missing something 😊 I know they return Outputs (instead of CompletableFutures), but the arguments seem the same to me? EDIT: Never mind, I missed the fact that they have overloads that accept outputs!

OrganizationsFunctions.getActiveFolderPlain(
    com.pulumi.gcp.organizations.inputs.GetActiveFolderPlainArgs.builder()
        .displayName("displayName")
        .parent("parent")
        .build()
)

OrganizationsFunctions.getActiveFolder(
    com.pulumi.gcp.organizations.inputs.GetActiveFolderArgs.builder()
        .displayName("displayName")
        .displayName(Output.of("displayName")) // alternatively
        .parent("parent")
        .parent(Output.of("parent")) // alternatively
        .build()
)

@jplewa
Copy link
Member

jplewa commented Nov 6, 2023

@kylepl Apologies for the confusion in my previous comment, I get the issue now. We have quite limited resources right now, but I'll put this at the top of my to-do list 😊

@kylepl
Copy link
Author

kylepl commented Nov 6, 2023

Thanks for investigating!

And yep, no rush on my side. I realize I've created a lot of requests, just surfacing them. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants