important-magician-41327
11/22/2021, 11:22 AMimport pulumi
import pulumi_aws as aws
main = aws.ec2.Subnet("main",
vpc_id=aws_vpc["main"]["id"],
cidr_block="10.0.1.0/24",
tags={
"Name": "Main",
})
Unfortunately specify the name of the resource does not work in my case, what Do I miss?
#Create VPC
vpc = aws.ec2.Vpc("vpc_1",
cidr_block="10.0.1.0/24",
)
vpc = aws.ec2.Vpc("vpc_2",
cidr_block="10.0.2.0/24",
)
#create WANem subnet
subnet_vpc1 = aws.ec2.Subnet("vpc_1",
vpc_id=vpc["vpc_1"].id,
cidr_block="10.0.1.0/24",
availability_zone=available.names[0],
)
#create WANem subnet
subnet_vpc2 = aws.ec2.Subnet("vpc_2",
vpc_id=vpc["vpc_2"].id,
cidr_block="10.0.2.0/24",
availability_zone=available.names[0],
)
My goal is to reference the VPC by the name, not by object. How can I do this?prehistoric-activity-61023
11/22/2021, 12:10 PMvpc
variable (and probably that’s not indented by you):
vpc = aws.ec2.Vpc("vpc_1",
cidr_block="10.0.1.0/24",
)
vpc = aws.ec2.Vpc("vpc_2",
cidr_block="10.0.2.0/24",
)
vpc["vpc_1"]
, vpc
is not a dict
#Create VPC
vpc1 = aws.ec2.Vpc("vpc_1",
cidr_block="10.0.1.0/24",
)
vpc2 = aws.ec2.Vpc("vpc_2",
cidr_block="10.0.2.0/24",
)
#create WANem subnet
subnet_vpc1 = aws.ec2.Subnet("vpc_1",
vpc_id=vpc1.id,
cidr_block="10.0.1.0/24",
availability_zone=available.names[0],
)
#create WANem subnet
subnet_vpc2 = aws.ec2.Subnet("vpc_2",
vpc_id=vpc2.id,
cidr_block="10.0.2.0/24",
availability_zone=available.names[0],
)
dict
for them:
vpc = {
"vpc_1": aws.ec2.Vpc("vpc_1", cidr_block="10.0.1.0/24"),
"vpc_1": aws.ec2.Vpc("vpc_1", cidr_block="10.0.2.0/24"),
}
then you’ll be able to access them with vpc["vpc_1"]
important-magician-41327
11/22/2021, 12:47 PMfor region in aws_regions:
vpc = aws.ec2.Vpc(f"vpc_{region}",
cidr_block="10.0.1.0/24",
)
for region in aws_regions:
subnet_vpc = aws.ec2.Subnet(f"vpc_{region}",
vpc_id=f"vpc_{region}".id,
cidr_block="10.0.1.0/24",
availability_zone=available.names[0],
)
prehistoric-activity-61023
11/22/2021, 12:59 PMfor region in aws_regions:
vpc = aws.ec2.Vpc(f"vpc_{region}",
cidr_block="10.0.1.0/24",
)
subnet_vpc = aws.ec2.Subnet(f"vpc_{region}",
vpc_id=vpc.id,
cidr_block="10.0.1.0/24",
availability_zone=available.names[0],
)
vpc
created just before created subnet_vpc
important-magician-41327
11/22/2021, 1:01 PMprehistoric-activity-61023
11/22/2021, 1:10 PMvpcs = {}
for region in aws_regions:
vpc = aws.ec2.Vpc(f"vpc_{region}",
cidr_block="10.0.1.0/24",
)
vpc[region] = vpc
…
from ... import vpcs
for region in aws_regions:
vpc = vpcs[region]
subnet_vpc = aws.ec2.Subnet(f"vpc_{region}",
vpc_id=vpc.id,
cidr_block="10.0.1.0/24",
availability_zone=available.names[0],
)
important-magician-41327
11/22/2021, 1:13 PM