Skip to content

Commit 0f4c6c5

Browse files
jkodroffclaude
andcommitted
Restructure Functions documentation as top-level concept
- Create new Functions overview page explaining three function types - Move provider functions from resources section to functions section - Move get functions from resources section to functions section - Extract resource methods into separate page - Remove JavaScript example from get functions page - Update navigation structure and menu weights Addresses GitHub issue #15438 by elevating Functions from a sub-page of Resources to a top-level concept in the documentation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bd79651 commit 0f4c6c5

File tree

4 files changed

+137
-88
lines changed

4 files changed

+137
-88
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title_tag: "Functions"
3+
meta_desc: Learn about the three types of functions available in Pulumi programs - provider functions, get functions, and resource methods.
4+
title: Functions
5+
h1: Functions
6+
meta_image: /images/docs/meta-images/docs-meta.png
7+
menu:
8+
iac:
9+
name: Functions
10+
parent: iac-concepts
11+
weight: 60
12+
identifier: iac-concepts-functions
13+
concepts:
14+
name: Functions
15+
parent: Overview
16+
weight: 6
17+
---
18+
19+
Pulumi provides three types of functions that you can use in your programs to interact with cloud resources and retrieve data from cloud providers. Understanding these different function types and when to use them is essential for writing effective Pulumi programs.
20+
21+
## Provider functions
22+
23+
**[Provider functions](/docs/iac/concepts/functions/provider-functions/)** are functions exposed in Pulumi providers that allow you to query cloud APIs to retrieve data that is not part of a resource. These functions are often used to look up information about existing cloud resources that you need in your Pulumi program.
24+
25+
For example, you might use a provider function to get the latest virtual machine image ID for a specific operating system.
26+
27+
## Get functions
28+
29+
**[Get functions](/docs/iac/concepts/functions/get-functions/)** are static functions available on all Pulumi resource types that allow you to reference an existing resource that is not managed by Pulumi. Unlike the `pulumi import` command which brings resources under Pulumi management, get functions simply allow you to read the properties of existing resources.
30+
31+
Get functions are useful when you know an unmanaged resource's identity and need to reference properties of the unmanaged resource in resources that _are_ managed by Pulumi.
32+
33+
For example, you might want to get a virtual network by ID and use its CIDR block in a firewall rule.
34+
35+
Resources accessed via get functions will never be updated or deleted by Pulumi.
36+
37+
## Resource methods
38+
39+
**[Resource methods](/docs/iac/concepts/functions/resource-methods/)** are functions attached to specific resource types that return computed values from resources you are managing with Pulumi. These methods are called on resource instances and typically provide additional derived information about that resource.
40+
41+
For example, some managed Kubernetes cluster resources have a resource method to return the generate Kubeconfig file.
42+
43+
## Choosing the right function type
44+
45+
- Use **provider functions** when you need to query cloud provider APIs for data or configuration
46+
- Use **get functions** when you need to reference existing resources that aren't managed by Pulumi
47+
- Use **resource methods** when you need to get computed values from resources you're managing with Pulumi
48+
49+
Understanding these distinctions will help you write more effective Pulumi programs.

content/docs/iac/concepts/resources/get.md renamed to content/docs/iac/concepts/functions/get-functions.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ meta_image: /images/docs/meta-images/docs-meta.png
77
menu:
88
iac:
99
name: Get functions
10-
parent: iac-concepts-resources
11-
weight: 7
10+
parent: iac-concepts-functions
11+
weight: 2
1212
concepts:
13-
parent: resources
14-
weight: 7
13+
parent: functions
14+
weight: 2
1515
aliases:
16+
- /docs/iac/concepts/resources/get/
1617
- /docs/intro/concepts/resources/get/
1718
- /docs/concepts/resources/get/
1819
---
@@ -26,23 +27,8 @@ Two values are passed to the `get` function:
2627

2728
You can use the `get` function to consume properties from a resource that was provisioned elsewhere. For example, this program reads an existing EC2 Security Group whose ID is `sg-0dfd33cdac25b1ec9` and uses the result as input to create an EC2 Instance that Pulumi will manage:
2829

29-
{{< chooser language "javascript,typescript,python,go,csharp,java,yaml" >}}
30+
{{< chooser language "typescript,python,go,csharp,java,yaml" >}}
3031

31-
{{% choosable language javascript %}}
32-
33-
```javascript
34-
let aws = require("@pulumi/aws");
35-
36-
let group = aws.ec2.SecurityGroup.get("group", "sg-0dfd33cdac25b1ec9");
37-
38-
let server = new aws.ec2.Instance("web-server", {
39-
ami: "ami-6869aa05",
40-
instanceType: "t2.micro",
41-
securityGroups: [ group.name ], // reference the security group resource above
42-
});
43-
```
44-
45-
{{% /choosable %}}
4632
{{% choosable language typescript %}}
4733

4834
```typescript

content/docs/iac/concepts/resources/functions.md renamed to content/docs/iac/concepts/functions/provider-functions.md

Lines changed: 6 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ meta_image: /images/docs/meta-images/docs-meta.png
77
menu:
88
iac:
99
name: Provider functions
10-
parent: iac-concepts-resources
11-
weight: 7
10+
parent: iac-concepts-functions
11+
weight: 1
1212
concepts:
13-
parent: resources
14-
weight: 7
13+
parent: functions
14+
weight: 1
1515
aliases:
16+
- /docs/iac/concepts/resources/functions/
1617
- /docs/intro/concepts/resources/functions/
1718
- /docs/concepts/resources/functions/
1819
---
@@ -263,7 +264,7 @@ While the direct and output forms of a provider function will both return the sa
263264

264265
## Choosing between direct form and output form
265266

266-
There are several common scenarios where one form or the other _must_ be used:
267+
There are several common scenarios where either direct form or output form must or should be used:
267268

268269
* **If you need a provider function's result to determine whether a resource should be created at all**, you must use the provider function's the direct form. The direct form of a function executes _while_ the Pulumi engine is formulating the dependency graph (that is, determining what resources need to be created, updated, or deleted), so in order to figure out whether a resource belongs in the graph at all, that decision has to always be calculated up front.
269270
* **If you need resources to be created or updated before the function is invoked**, you should use the provider function's output form. (It is _possible_ to use the direct form in this case, but it requires wrapping the call in an `apply`, which can be awkward from a readability standpoint.) Dependencies in the output form of a function are tracked identically to resources: all inputs to the function must be resolved before the function executes. If you need to specify a dependency that isn't already implied by an input to the function's arguments, you can use the `dependsOn` function option to specify additional dependencies (just like you can with resources).
@@ -276,66 +277,3 @@ Pulumi recommends you choose the output form of a function unless you have a spe
276277

277278
Assuming there is no specific reason to choose one or the other, the choice between the two forms is ultimately a preference: there is no significant difference in either performance or code maintainability between the two forms.
278279
{{% / notes %}}
279-
280-
## Resource methods
281-
282-
Provider SDKs may also include _methods_ attached to a resource type. For example, in the [EKS](/registry/packages/eks/api-docs/) SDK, the `Cluster` resource has a [.GetKubeconfig](/registry/packages/eks/api-docs/cluster/#method_GetKubeconfig) method:
283-
284-
<div><pulumi-examples>
285-
<div><pulumi-chooser type="language" options="typescript,python,go,csharp,java,yaml"></pulumi-chooser></div>
286-
<div>
287-
<pulumi-choosable type="language" values="typescript">
288-
289-
```typescript
290-
getKubeconfig(args?: Cluster.GetKubeconfigArgs): Output<Cluster.GetKubeconfigResult>
291-
```
292-
293-
</pulumi-choosable>
294-
</div>
295-
<div>
296-
<pulumi-choosable type="language" values="csharp">
297-
298-
```csharp
299-
public Output<string> GetKubeconfig(Cluster.GetKubeconfigArgs? args)
300-
```
301-
302-
</pulumi-choosable>
303-
</div>
304-
<div>
305-
<pulumi-choosable type="language" values="go">
306-
307-
```go
308-
func (r *Cluster) GetKubeconfig(ctx *Context, args *ClusterGetKubeconfigArgs) (pulumi.StringOutput, error)
309-
```
310-
311-
</pulumi-choosable>
312-
</div>
313-
<div>
314-
<pulumi-choosable type="language" values="python">
315-
316-
```python
317-
def get_kubeconfig(self,
318-
profile_name: Optional[pulumi.Input[str]] = None,
319-
role_arn: Optional[pulumi.Input[str]] = None) -> Output[str]
320-
```
321-
322-
</pulumi-choosable>
323-
</div>
324-
<div>
325-
<pulumi-choosable type="language" values="java">
326-
327-
No example available for Java
328-
329-
</pulumi-choosable>
330-
</div>
331-
<div>
332-
<pulumi-choosable type="language" values="yaml">
333-
334-
No example available for YAML
335-
336-
</pulumi-choosable>
337-
</div>
338-
339-
</pulumi-examples></div>
340-
341-
Unlike provider functions, methods always appear in the _output form_: they take `Input` arguments, and return an `Output` (because they cannot execute until after the resources has been created). Moreover, methods do not accept invoke options.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title_tag: "Resource Methods"
3+
meta_desc: Learn about resource methods - functions attached to resource types that return computed values from resources you are managing with Pulumi.
4+
title: Resource methods
5+
h1: Resource methods
6+
meta_image: /images/docs/meta-images/docs-meta.png
7+
menu:
8+
iac:
9+
name: Resource methods
10+
parent: iac-concepts-functions
11+
weight: 3
12+
concepts:
13+
parent: functions
14+
weight: 3
15+
---
16+
17+
Provider SDKs may also include _methods_ attached to a resource type. These methods return computed values from resources you are managing with Pulumi. For example, in the [EKS](/registry/packages/eks/api-docs/) SDK, the `Cluster` resource has a [.GetKubeconfig](/registry/packages/eks/api-docs/cluster/#method_GetKubeconfig) method:
18+
19+
<div><pulumi-examples>
20+
<div><pulumi-chooser type="language" options="typescript,python,go,csharp,java,yaml"></pulumi-chooser></div>
21+
<div>
22+
<pulumi-choosable type="language" values="typescript">
23+
24+
```typescript
25+
getKubeconfig(args?: Cluster.GetKubeconfigArgs): Output<Cluster.GetKubeconfigResult>
26+
```
27+
28+
</pulumi-choosable>
29+
</div>
30+
<div>
31+
<pulumi-choosable type="language" values="csharp">
32+
33+
```csharp
34+
public Output<string> GetKubeconfig(Cluster.GetKubeconfigArgs? args)
35+
```
36+
37+
</pulumi-choosable>
38+
</div>
39+
<div>
40+
<pulumi-choosable type="language" values="go">
41+
42+
```go
43+
func (r *Cluster) GetKubeconfig(ctx *Context, args *ClusterGetKubeconfigArgs) (pulumi.StringOutput, error)
44+
```
45+
46+
</pulumi-choosable>
47+
</div>
48+
<div>
49+
<pulumi-choosable type="language" values="python">
50+
51+
```python
52+
def get_kubeconfig(self,
53+
profile_name: Optional[pulumi.Input[str]] = None,
54+
role_arn: Optional[pulumi.Input[str]] = None) -> Output[str]
55+
```
56+
57+
</pulumi-choosable>
58+
</div>
59+
<div>
60+
<pulumi-choosable type="language" values="java">
61+
62+
No example available for Java
63+
64+
</pulumi-choosable>
65+
</div>
66+
<div>
67+
<pulumi-choosable type="language" values="yaml">
68+
69+
No example available for YAML
70+
71+
</pulumi-choosable>
72+
</div>
73+
74+
</pulumi-examples></div>
75+
76+
Unlike provider functions, methods always appear in the _output form_: they take `Input` arguments, and return an `Output` (because they cannot execute until after the resource has been created). Resource methods do not accept invoke options.

0 commit comments

Comments
 (0)