-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect availability zones reported for subnets in VPC #1422
Labels
awaiting-feedback
Blocked on input from the author
kind/bug
Some behavior is incorrect or out of spec
Comments
farra
added
kind/bug
Some behavior is incorrect or out of spec
needs-triage
Needs attention from the triage team
labels
Nov 12, 2024
This function appears to give me the correct results. def get_subnets_for_az2(vpc_id: pulumi.Input[str], target_az: str) -> pulumi.Output[list]:
"""
Get private subnets for a specific availability zone within a VPC.
Args:
vpc_id: The VPC ID to search in
target_az: Target availability zone
Returns:
pulumi.Output[list]: List of matching subnet IDs
"""
def get_matching_subnets(vid):
try:
# Query AWS for all subnets in the VPC and AZ
subnets = aws.ec2.get_subnets(
filters=[
{
"name": "vpc-id",
"values": [vid]
},
{
"name": "availability-zone",
"values": [target_az]
},
# Filter for private subnets by checking map_public_ip_on_launch
{
"name": "map-public-ip-on-launch",
"values": ["false"]
}
]
)
pulumi.log.info(f"Found {len(subnets.ids)} subnets in AZ {target_az}")
return subnets.ids
except Exception as e:
pulumi.log.error(f"Error finding subnets: {str(e)}")
return []
return pulumi.Output.from_input(vpc_id).apply(get_matching_subnets) |
Hey @farra, I tried reproducing it with this minimal example but couldn't: from typing import Sequence
import pulumi
import pulumi_awsx as awsx
import pulumi_aws as aws
def filter_subnets(subnets: Sequence['aws.ec2.Subnet'], desired_az: str):
def filter_subnet(subnet: 'aws.ec2.Subnet'):
return subnet.availability_zone.apply(lambda az: subnet if az == desired_az else None)
filtered_subnets = [filter_subnet(net) for net in subnets]
return pulumi.Output.all(*filtered_subnets).apply(lambda args: [net for net in args if net is not None])
vpc = awsx.ec2.Vpc("test-vpc", enable_dns_hostnames=True, cidr_block="10.0.0.0/16")
pulumi.export('selected_nets', vpc.subnets.apply(lambda subnets: filter_subnets(subnets, "us-west-2a")).apply(lambda subnets: [net.id for net in subnets])) This exports the two subnets in the These are the versions I'm using:
|
flostadler
added
awaiting-feedback
Blocked on input from the author
and removed
needs-triage
Needs attention from the triage team
labels
Nov 12, 2024
Hey @farra, were you able to try the program I posted above? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
awaiting-feedback
Blocked on input from the author
kind/bug
Some behavior is incorrect or out of spec
What happened?
Context
The motivation here is to set capacity reservations in the launch template. Capacity reservations are specific to an availability zone. When I set the subnet as part of the managed node group, I need to know that I'm using the assigned availability zone.
Issues
Pseudocode
Putting Outputs aside, I intended to write a function something like this:
Current Function
The current function takes an aws.ec2.Vpc and a dictionary of configuration from the pulumi config. That part isn't particularly relevant. This code has been written with some help from Claude and ChatGPT. I added logging to understand what was going on.
Output
When running
pulumi up
, I get the following output:Yet, the AWS console reports that, for example,
subnet-049611835250f0802
is inus-west-2a
notus-west-2c
.Example
This project gives the same results for me:
Output
Output of
pulumi about
Additional context
No response
Contributing
Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).
The text was updated successfully, but these errors were encountered: