https://pulumi.com logo
#general
Title
# general
f

freezing-sugar-24066

11/10/2021, 9:08 PM
Hello, I’m just getting started with Pulumi, in a Webiny project. I need to simulate a Terraform
data
block. I saw that this can be done by
aws.ec2.getVpc()
. However, this returns a
Promise<aws.ec2.GetVpcResult>
instead of a
Vpc
(which has
pulumi.Output<string>
properties) and the two objects are very different. Am I barking up the right tree, here? I see the static
Vpc.get()
method, but it has parameters I don’t know the meaning of, such as `id: pulumi.Input<pulumi.ID>`… what would I pass in there? If I go down the
getVpc()
route with the Promise, could I end up having any kind of race condition issue between the time the details of that VPC are fetched and the actual stack deploys?
l

little-cartoon-10569

11/10/2021, 9:12 PM
If you're just getting data from the VPC object, then you can use
getVpc()
. You won't get a Vpc object.
If you want to manage the Vpc in Pulumi (equivalent to a
resource
in Terraform, then you must import the VPC.
And half-way between those options is
Vpc.get()
, which is similar to
getVpc
but uses the normal Pulumi classes. It's read-only though, so similar to a
data
.
I would suggest not trying to simulate anything Terraform-y. You will need a new mental model, as Terraform and Pulumi require fairly different ways of thinking.
f

freezing-sugar-24066

11/10/2021, 11:38 PM
Thanks for the info. I need to simply use existing VPCs that Pulumi will not manage
I’m not really trying to simulate anything in Terraform, I said “simulate” just to convey the goal: get a reference to a resource and use it, without Pulumi controlling or creating that resource.
It’s very clear to me that Pulumi’s lifecycle is a different way of thinking about things than normal code… but it is in fact close to how Terraform does things (though that may not be apparent to some from looking at .hcl code which almost looks procedural).
l

little-cartoon-10569

11/10/2021, 11:47 PM
Ok. Well then you can use
Vpc.get()
or
getVpc()
, either is good and they have very different APIs and returned objects.