Skip to content

Commit fb4786c

Browse files
jkodroffclaude
andauthored
Improve apply and all documentation clarity and correctness (#16401)
Clarifies the purpose and proper usage of apply and all methods, adds important warnings about resource creation in callbacks to prevent preview inconsistencies, and fixes syntax errors in code examples to ensure accuracy. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent 3666281 commit fb4786c

File tree

3 files changed

+72
-392
lines changed

3 files changed

+72
-392
lines changed

.vscode/markdown.code-snippets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"body": [
3838
"{{% notes type=\"info\" %}}",
3939
"TODO",
40-
"{{% /notes % }}",
40+
"{{% /notes %}}",
4141
],
4242
"description": "Notes callout field. Type can be any of the following: info, warning, tip"
4343
}

content/docs/iac/concepts/inputs-outputs/all.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ If you need to access and use multiple outputs together, the `all` function acts
2020

2121
This can be used to compute an entirely new output value, such as creating a new string by adding or concatenating outputs from two different resources together, or by creating a new data structure that uses their values. Just like with `apply`, the result of `all` is itself an Output<T>.
2222

23+
{{< notes type="warning" >}}
24+
Creating resources inside an `all` callback should be avoided whenever possible. Resources created inside `all` will not appear in `pulumi preview` unless all output values are already known. This means the preview output may not match the actual changes when `pulumi up` is run, making it difficult to understand what changes will be made to your infrastructure.
25+
26+
If you need to create a resource that depends on output values, pass the outputs directly as inputs to the resource instead of using `all`. Pulumi will automatically handle the dependency tracking and ensure resources are created in the correct order.
27+
{{< /notes >}}
28+
2329
## Creating a new string
2430

2531
Outputs that return to the engine as strings cannot be used directly in operations such as string concatenation until the output value has returned to Pulumi. In these scenarios, you'll need to wait for the value to return using [`apply`](/docs/concepts/inputs-outputs/apply/).
@@ -74,7 +80,7 @@ let connectionString = pulumi.all([sqlServer.name, database.name])
7480

7581
{{% choosable language python %}}
7682

77-
In python, you can pass in unnamed arguments to `Output.all` to create an Output list, for example:
83+
In Python, you can pass in unnamed arguments to `Output.all` to create an Output list, for example:
7884

7985
```python
8086
from pulumi import Output
@@ -139,7 +145,7 @@ var connectionString3 = Output.Tuple(sqlServer.name, database.name).Apply(t =>
139145

140146
// When all the input values have the same type, Output.all can be used
141147
var connectionString = Output.all(sqlServer.name(), database.name())
142-
.applyValue(t -> String.format("Server=tcp:%s.database.windows.net;initial catalog=%s;", t.get(0), t.get(1));
148+
.applyValue(t -> String.format("Server=tcp:%s.database.windows.net;initial catalog=%s;", t.get(0), t.get(1)));
143149

144150
// For more flexibility, 'Output.tuple' is used so that each unwrapped value will preserve their distinct type.
145151
var connectionString2 = Output.tuple(sqlServer.name, database.name)
@@ -264,7 +270,7 @@ connectionDetails := pulumi.All(sqlServer.IpAddress, database.Port).ApplyT(
264270
ipAddress := args[0].(string)
265271
port := args[1].(string)
266272
return map[string]interface{}{
267-
"server_ip": ipAddress),
273+
"server_ip": ipAddress,
268274
"database_port": port,
269275
}
270276
}
@@ -334,9 +340,3 @@ This example is not applicable in Pulumi YAML.
334340
{{% /choosable %}}
335341

336342
{{< /chooser >}}
337-
338-
## Creating a JSON object
339-
340-
You can also [create JSON objects](/docs/concepts/inputs-outputs/apply/#outputs-and-json) using multiple output values in Pulumi. Doing so requires the use of `apply` or one of Pulumi's [JSON-specific helpers](/docs/concepts/inputs-outputs/apply/#converting-outputs-to-json).
341-
342-
{{< example-program path="aws-s3websitebucket-oai-bucketpolicy" >}}

0 commit comments

Comments
 (0)