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

Document dependsOn workarounds for invokes #12327

Merged
merged 2 commits into from
Aug 23, 2024
Merged

Conversation

lunaris
Copy link
Contributor

@lunaris lunaris commented Jul 22, 2024

Invokes, or provider functions, are exposed in many SDKs alongside resources, and allow programs to call arbitrary provider-specific APIs. Just as resources may be passed resource options, so may invokes be passed invoke options, with the usual suspects such as parent and provider making an appearance and appearing as one might expect.

One resource option that is currently not available as an invoke option, despite appearing a natural addition, is dependsOn, which allows Pulumi users to make explicit dependencies and ordering constraints in their programs that Pulumi cannot otherwise track. One reason that dependsOn does not currently exist as an invoke option is that any given invoke can be called in one of two ways:

  • A "direct form", whereby the function accepts plain arguments and either blocks until it returns a value or returns a language-native asynchronous value (such as a Promise in NodeJS or a Task in Python, for instance).

  • An "output form", whereby the function accepts any Pulumi Input values and returns a Pulumi Output value.

Since direct-form invocations do not use Pulumi Inputs or Outputs, they do not form part of the Pulumi dependency graph. Passing dependsOn to a direct-form invocation would therefore make no sense. The sharing of the set of invoke options between the two forms means that dependsOn is consequently not currently available.

Thankfully, one can work around the absence of dependsOn for output-form invocations using e.g. pulumi.all and .apply. This commit updates the documentation on invokes/provider functions to (hopefully) make this clear and provide examples where possible. While we are here we also bolster some of the other pieces of documentation on provider functions, such as defining the terms "direct form" and "output form" which are already referenced on other pages.

Fixes pulumi/pulumi#14243

image
image
image

@lunaris lunaris requested a review from a team July 22, 2024 10:56
@pulumi-bot
Copy link
Collaborator

@lunaris lunaris force-pushed the wjones/depends-on-invokes branch from f85c9e2 to 82374ee Compare July 22, 2024 15:10
@pulumi-bot
Copy link
Collaborator

@interurban interurban requested a review from a team July 22, 2024 17:29
Copy link
Contributor

@cnunciato cnunciato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing this up! No major issues with the content, only some suggestions for clarity, but it'd be good to fix up the code to use shortcodes instead of raw markup.

content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
@@ -203,18 +356,18 @@ def get_kubeconfig(self,
<div>
<pulumi-choosable type="language" values="java">

(no example available for Java)
No example available for Java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there just no examples in Java and YAML, or are provider methods not supported in those languages? If not supported, is it that they aren't supported yet (in which case it'd also be good to link to an issue), or that they'll never be? (Generally best to be clear on things like this, as folks will likely wonder the same.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not actually sure on this -- I've merely (perhaps wrongly) added some cosmetic changes to this bit but am not responsible for the original docs (nor sure on the answers to your questions).


</pulumi-choosable>
</div>

</pulumi-examples></div>

Unlike provider functions, methods always take `Input` arguments, and return an `Output`. Methods do not have invoke options.
Unlike provider functions, methods always appear in the _output form_: they take `Input` arguments, and return an `Output`. Moreover, methods do not accept invoke options.
Copy link
Contributor

@cnunciato cnunciato Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, methods do not accept invoke options.

Just curious -- what does it actually mean that "methods don't accept invoke options"? If "invoke options" are themselves just function arguments, and methods do take arguments, what is this sentence supposed to convey to me as a user? If we deleted it, would anything useful or important be lost?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for a "normal" invoke you can do something like aws.getAmi(..., { provider: myCustomProvider }), for instance, where { provider: myCustomProvider } are the invoke options (akin to resource options). Methods don't allow this, (presumably -- again not an expert here) because they'll inherit the options from the resource on which they are being called (so e.g. we don't want to allow you to overload the provider since the owning resource will have already defined one). So at a language level, yes, the method takes arguments, but only those which are inputs to the function, not the "second set" that let you control bits around how Pulumi performs the invoke. If that makes sense? Happy to make changes as you see fit on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does make sense, thanks! I didn't realize it was this "second set" that this referred to.

@lunaris lunaris force-pushed the wjones/depends-on-invokes branch from 82374ee to 0b5e542 Compare July 26, 2024 13:10
@pulumi-bot
Copy link
Collaborator

Copy link
Member

@jkodroff jkodroff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few suggestions to make scanning the page easier and to make some things more explicit.

content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
Invokes, or provider functions, are exposed in many SDKs alongside
resources, and allow programs to call arbitrary provider-specific APIs.
Just as resources may be passed resource options, so may invokes be
passed invoke options, with the usual suspects such as `parent` and
`provider` making an appearance and appearing as one might expect.

One resource option that is currently not available as an invoke option,
despite appearing a natural addition, is `dependsOn`, which allows
Pulumi users to make explicit dependencies and ordering constraints in
their programs that Pulumi cannot otherwise track. One reason that
`dependsOn` does not currently exist as an invoke option is that any
given invoke can be called in one of two ways:

* A "direct form", whereby the function accepts plain arguments and
  either blocks until it returns a value or returns a language-native
  asynchronous value (such as a `Promise` in NodeJS or a `Task` in
  Python, for instance).

* An "output form", whereby the function accepts any Pulumi `Input`
  values and returns a Pulumi `Output` value.

Since direct-form invocations do not use Pulumi `Input`s or `Output`s,
they do not form part of the Pulumi dependency graph. Passing
`dependsOn` to a direct-form invocation would therefore make no sense.
The sharing of the set of invoke options between the two forms means
that `dependsOn` is consequently not currently available.

Thankfully, one can work around the absence of `dependsOn` for
output-form invocations using e.g. `pulumi.all` and `.apply`. This
commit updates the documentation on invokes/provider functions to
(hopefully) make this clear and provide examples where possible. While
we are here we also bolster some of the other pieces of documentation on
provider functions, such as defining the terms "direct form" and "output
form" which are already referenced on other pages.

Fixes pulumi/pulumi#14243
@pulumi-bot
Copy link
Collaborator

Copy link
Contributor

@cnunciato cnunciato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of suggestions, but otherwise looks good! 🚀

content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
content/docs/concepts/resources/functions.md Outdated Show resolved Hide resolved
Co-authored-by: Christian Nunciato <[email protected]>
@lunaris lunaris enabled auto-merge (squash) August 23, 2024 10:16
@pulumi-bot
Copy link
Collaborator

@lunaris lunaris merged commit fe11fe2 into master Aug 23, 2024
5 checks passed
@lunaris lunaris deleted the wjones/depends-on-invokes branch August 23, 2024 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add depends_on for InvokeOptions
6 participants