This message was deleted.
s
This message was deleted.
l
Right approach to creation. The ID of a Vpc is an Input, which is a union of string and IDOutput. You can use either. However, you shouldn't need to check if the resource already exists: that's Pulumi's job.
If you used Pulumi to create it originally, then Pulumi still knows about it and won't create it again. This is part of the declarative approach to resource provisioning.
If the resource was created outside of Pulumi, then instead of conditionally creating the resource, the appropriate thing to do is to unconditionally import it once, then allow Pulumi to manage the resource from then on.
f
Ah okay I see - yes this was my approach for cases where we have a VPC created outside of pulumi. So conditional creation isn't a workable solution. Well thank you for the clearing that up @little-cartoon-10569
b
yep, agree with tenwit here. just to clarify though, there is a way of doing this. just make the
CreateSubnet
function take
IDOutput
and then check if the vpc exists in the calling code
l
It's workable, but you'd need to wrap almost your entire Pulumi program in conditions. It doesn't fit the declarative model. Pulumi isn't imperative: you don't ask Pulumi to do something like create a VPC. You declare something: you ask it to ensure that the the VPC exists.
b
some thing like:
Copy code
var vpc *vpc
if config.CreateNewVPC {
  // create a new VPC
  vpc = aws.NewVPC
} else {
  vpc = aws.LookupVPC
}

subnets = CreateSubnets(ctx, vpc.ID()
f
thank you both
useful info
b
also, you probably want to make your function ComponentResources
f
oh okay i better find out what that means! googles
b
f
ta