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

Add back in information about creating resources in apply #12459

Open
pierskarsenbarg opened this issue Aug 6, 2024 · 3 comments
Open

Add back in information about creating resources in apply #12459

pierskarsenbarg opened this issue Aug 6, 2024 · 3 comments
Assignees
Labels
area/docs Improvements or additions to documentation
Milestone

Comments

@pierskarsenbarg
Copy link
Member

Problem description

We used to include a note that when you created resources in an apply() there resource outputs were unknown so there may be side-effects:

Image

(from https://web.archive.org/web/20240127231146/https://www.pulumi.com/docs/concepts/inputs-outputs/)

It seems to have gone missing

@pierskarsenbarg pierskarsenbarg added the needs-triage Needs attention from the triage team label Aug 6, 2024
@github-project-automation github-project-automation bot moved this to 🤔 Triage in Docs 📚 Aug 6, 2024
@jkodroff
Copy link
Member

jkodroff commented Aug 6, 2024

Double-check my info here, but:

  1. I believe apply will run in preview if the unknowns are satisfied.
  2. I am certain that in some circumstances, creating resources in an apply is unavoidable (e.g. adding routes to every route table in the AWSX VPC). This typically happens when needing to iterate over types like pulumi.Output<string[]> because the length of the list cannot be known until the resources are provisioned.

Here's a first draft of the content. Feedback welcome.

Note that the code in an apply will not run during pulumi preview unless all dependent values are known. This means that you should avoid creating Pulumi resources in an apply whenever possible because when resources are created within apply, the pulumi preview output may not necessarily match the actual actions taken during pulumi apply.

There are some edge cases where creating resources in apply is necessary. The most common case for creating resources in apply is when you need to iterate over a list output type, e.g., pulumi.Output<string[]>, for example adding a tag to every public subnet in the awsx.ec2.Vpc component. In this case, the length of the list of strings cannot be determined until the VPC component has been provisioned because the number of public subnets in the VPC is variable and based on a variable length input (the list of availability zones).

@thoward thoward added area/docs Improvements or additions to documentation and removed needs-triage Needs attention from the triage team labels Aug 12, 2024
@thoward thoward moved this from 🤔 Triage to 🎬 Ready in Docs 📚 Aug 12, 2024
@thoward thoward added this to the 0.109 milestone Aug 12, 2024
@interurban interurban modified the milestones: 0.109, 0.110 Sep 13, 2024
@interurban interurban modified the milestones: 0.110, 0.111 Oct 1, 2024
@interurban interurban modified the milestones: 0.111, 0.112 Oct 30, 2024
@thoward thoward self-assigned this Nov 13, 2024
@thoward thoward modified the milestones: 0.112, 0.113 Nov 13, 2024
@thoward
Copy link
Contributor

thoward commented Nov 13, 2024

@thoward to look into this and determine what's accurate vs what we've published.

@jkodroff
Copy link
Member

jkodroff commented Nov 14, 2024

For my use case described above, the length of the list must truly be unknown. If you're creating an AWSX VPC, and you already know you will have 3 AZs, you can just do something like:

const vpc = new awsx.ec2.Vpc("my-vpc");

const subnetId1 = vpc.publicSubnetIds.apply(ids => id[0]);
const subnetId2 = vpc.publicSubnetIds.apply(ids => id[1]);
const subnetId3 = vpc.publicSubnetIds.apply(ids => id[2]);

[subnetId1, subnetId2, subnetId3].forEach(id => {
  // add some routes to a routing table, etc
});

This would obviate the need to create resources in an apply.

@interurban interurban modified the milestones: 0.113, 0.114 Dec 2, 2024
@interurban interurban modified the milestones: 0.114, 0.115 Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs Improvements or additions to documentation
Projects
Status: 🎬 Ready
Development

No branches or pull requests

4 participants