From cfbccd0744fa2970c8fdc1acf503ae4f77975309 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Sun, 21 Jul 2024 20:33:22 +0000 Subject: [PATCH] Admin: Improve handling of us-west region when retrieving EC2 instance types --- scripts/ec2_get_instance_type_offerings.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/ec2_get_instance_type_offerings.py b/scripts/ec2_get_instance_type_offerings.py index 3a173b2f80ca..8a9f4d222c45 100755 --- a/scripts/ec2_get_instance_type_offerings.py +++ b/scripts/ec2_get_instance_type_offerings.py @@ -62,15 +62,19 @@ def main(): ) # Ensure we use the correct US-west availability zones - # There are only two - for some accounts they are called us-west-1b and us-west-1c - # As our EC2-module assumes us-west-1a and us-west-1b, we may have to rename the zones coming from AWS + # There are three, but accounts only have access to two + # Because of this, some accounts have access to (us-west-1a or us-west-1b) and us-west-1c + # As our EC2-module assumes us-west-1a and us-west-1b, we have to rename the zones accordingly # https://github.com/getmoto/moto/issues/5494 if region == "us-west-1" and location_type == "availability-zone": zones = set([i["Location"] for i in instances]) + # If AWS returns b and c, we have to convert b --> a if zones == {"us-west-1b", "us-west-1c"}: for i in instances: if i["Location"] == "us-west-1b": i["Location"] = "us-west-1a" + # If AWS returns c, we always have to convert c --> b (the other location will always be a at this point) + if "us-west-1c" in zones: for i in instances: if i["Location"] == "us-west-1c": i["Location"] = "us-west-1b"