hey all! stoked to join, thanks for having me! aws...
# getting-started
g
hey all! stoked to join, thanks for having me! aws + python: trying to create a vpc and then 2 subnets attached to it but im having trouble getting the syntax right for referencing the vpc id and either get that its not found or
TypeError: 'Vpc' object is not subscriptable
. tl;dr how do i correctly reference the vpc id? any helpful pointers in the right direction would be much appreciated! 🙏 code in thread...
Copy code
import pulumi
import pulumi_aws as aws

staging_vpc = aws.ec2.Vpc(resource_name="staging_vpc", cidr_block="10.0.0.0/16")

private_cidrs = aws.ec2.Subnet("private_cidrs",
    cidr_block="10.0.0.0/19",
    map_public_ip_on_launch=False,
    tags={
        "Name": "private-cidrs",
    },
    vpc_id=staging_vpc["staging_vpc"]["id"])

public_cidrs = aws.ec2.Subnet("public_cidrs",
    cidr_block="10.0.128.0/20",
    map_public_ip_on_launch=False,
    tags={
        "Name": "public-cidrs",
    },
    vpc_id=staging_vpc["staging_vpc"]["id"])


# Export
pulumi.export('staging_vpc_name', staging_vpc.id)
pulumi.export('private_cidrs', private_cidrs.id)
pulumi.export('public_cidrs', public_cidrs.id)
ive tried several attempts at referencing with no luck. is this a potentially a race condition where the subnets are trying to reference the vpc_id but it doesnt quite exist yet?
this feels like a "getting started" thing but im happy to repost in aws if that seems more approriate
s
you should be able to just use
staging_vpc.id
- as the error suggests, the object is not subscriptable
🙌 1
g
i could have sworn i tried that and got an error that it was expecting a string... but that worked, thanks vivek!!
🚀 1
i guess my main point of confusion stemmed from examples like this from the security group...
Copy code
vpc_id=aws_vpc["main"]["id"]
is
aws_vpc
in this case not the same type of resource i created for
staging_vpc
?