https://pulumi.com logo
Title
g

green-motherboard-37108

03/03/2021, 11:39 PM
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...
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

sparse-park-68967

03/03/2021, 11:52 PM
you should be able to just use
staging_vpc.id
- as the error suggests, the object is not subscriptable
🙌 1
g

green-motherboard-37108

03/03/2021, 11:56 PM
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...
vpc_id=aws_vpc["main"]["id"]
is
aws_vpc
in this case not the same type of resource i created for
staging_vpc
?