Hey all, I’m using AWSSx package to create a AWS V...
# aws
s
Hey all, I’m using AWSSx package to create a AWS VPC as @little-cartoon-10569 kindly suggested in this conversation. I don’t understand the documentation though (https://www.pulumi.com/registry/packages/awsx/api-docs/ec2/vpc/): how I can get the ID of the VPC I create? For example:
Copy code
from pulumi_awsx import ec2

vpc = ec2.Vpc(resource_name="my-vpc")
print(vpc.id)
... outputs
None
. Any idea?
b
Hi @steep-lamp-20408, at the bottom of the page you can find the "output" graph where the available outputs are listed for each of the resources. In your case, if you want to use them as a reference for another resource you have to use the following syntax:
name_of_your_resource.id
Also note that if you want to make a reference to another resource it have to be created already!
s
Hi @boundless-tomato-68419. Yes, that’s what I did :
vpc.id
However it outputs
None
. Hence my question
Copy code
vpc = ec2.Vpc(resource_name="my-vpc")
print(vpc.id)
b
Its known only after initialization of the resource. Did you create it already?
s
Yes the creation is this line :
Copy code
vpc = ec2.Vpc(resource_name="my-vpc")
b
But i mean you did pulumi Up and you created the resources right?
s
well... yeah 🙂
b
I think that you have to actually export the specific outputs in order to be able to print them on the console. JS:
exports.bucketName = siteBucket.id;
Did you tried it?
s
I’m just using the print to debug, but I need to use the id of the VPC in another resources. I don’t need it in the console, this is just an example for the debug.
vpc.id
seems to be null whether it’s printed or not.
For example, this
Copy code
vpc = ec2.Vpc(resource_name="my-vpc")

public_subnet = aws.ec2.Subnet("my-subnet",
    vpc_id=vpc.id,
    cidr_block="10.0.1.0/24",
    tags={
        "Name": "Main",
    },
)
....would throw an error when creating the
public_subnet
resource, saying the
vpc_id
cannot be
null
.
b
Copy code
vpc = ec2.Vpc(resource_name="my-vpc")
But why is it ec2.vpc?
s
Because it’s the
ec2
from the
pulumi_awsx
package (
from pulumi_awsx import ec2
). Anyway the creation of the VPC is totally working, my point is about getting its
id
afterwards
l
It should work. You can try using
vpc.vpc.id
if you like: the awsx VPC wraps the aws VPC. They should have the same ID (they do in TS/JS.. maybe not in Python?).
👍 1
s
It seems
vpc_id
outputs a promise/output. Maybe I should use that.
God I love Pulumi but the doc is the worst 😅
@little-cartoon-10569 actually I don’t see how
pulumi_awsx.ec2.vpc
is better/simpler than AWS classic’s
pulumi_aws.ec2.Vpc
, so I’m switching to
pulumi_aws
. I get also a promise with
.id
from this. It should work.
l
The power of awsx is in the extra resources it creates for free: some subnets, an IGW, one NAT per private subnet, and all the route tables and routes you need. I prefer aws myself, but if you don't know all the extra bits you need for general purpose networking, then awsx is great.
👍 1
It also works out CIDRs for you.
Re: the output: you must use the output. You cannot get at the string id during deployment. It's not available until deployment completes.
s
I see! Thanks. Not very familiar with AWS devops so didn’t realize all this was necessary 😮
l
Build the awsx VPC in a test project with the correct public, private and isolated subnets, then look at the graph of resources it produces. Then convert that to your own code, using aws. This is the best option, at least until aws-native is fully featured.
💯 1