https://pulumi.com logo
Title
a

average-nest-71706

03/11/2021, 8:38 AM
My code:
test = aws.lb.LoadBalancer(
							"MyTestALB",
							internal=False,
							load_balancer_type="application",
							security_groups=[alb_security_group.id],
							subnets=[__item["id"] for __item in aws_subnet["public"]],
							enable_deletion_protection=True,
							#access_logs=aws.lb.LoadBalancerAccessLogsArgs(
							#		bucket=
							#	)
						  )
I would like to understand what this line of code is saying:
subnets=[__item["id"] for __item in aws_subnet["public"]],
My question is how am I going to get the subnets, because the lb documentation assumed that I already the code getting the subnets and it is assigned to aws_subnet["public"].
b

broad-dog-22463

03/11/2021, 11:46 AM
you need to pass a list of subnet ids there
a

average-nest-71706

03/12/2021, 3:30 AM
When you said pass list of subnets ids, you mean this? https://www.pulumi.com/docs/reference/pkg/aws/ec2/getsubnetids/ I just started learning pulumi and totally no experience on this.
So far, what I have tried is this.
example_subnet_ids = aws.ec2.get_subnet_ids(vpc_id="vpc-f...")
example_subnet = [aws.ec2.get_subnet(id=__value) for __key, __value in example_subnet_ids.ids]
I got this error after running pulumi preview.
ValueError: too many values to unpack (expected 2)
b

broad-dog-22463

03/12/2021, 9:06 AM
hey @average-nest-71706 so the get_subnet_ids call will return a list of ids - you can then pass that list of subnet ids directly to the subnet parameter of LoadBalancer (which expects a list)