Skip to content

Commit

Permalink
Filter out gov regions.
Browse files Browse the repository at this point in the history
  • Loading branch information
costastf committed Nov 28, 2023
1 parent 3dc010d commit 425a354
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions awsapilib/controltower/controltower.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,9 @@ def region(self):
return self._region

@staticmethod
def get_available_regions(enable_gov_regions=False):
def get_available_regions():
"""The regions that control tower can be active in.
Args:
enable_gov_regions: A boolean flag indicating whether to enable the gov regions
Returns:
regions (list): A list of strings of the regions that control tower can be active in.
Expand All @@ -210,9 +207,8 @@ def get_available_regions(enable_gov_regions=False):
return []
regions = [entry.get('id', '').split(':')[1]
for entry in response.json().get('prices')
if entry.get('id').startswith('controltower')]
if not enable_gov_regions:
regions = [region for region in regions if 'gov' not in region.lower()]
if all([entry.get('id').startswith('controltower'),
'gov' not in entry.get('id')])]
return regions

@property
Expand Down Expand Up @@ -1230,8 +1226,7 @@ def deploy(self, # pylint: disable=too-many-arguments,too-many-locals
custom_ou_name: str = 'Sandbox',
regions: Optional[list] = None,
retries: int = 10,
wait: int = 1,
enable_gov_regions=False) -> bool:
wait: int = 1) -> bool:
"""Deploys control tower.
Returns:
Expand All @@ -1243,7 +1238,7 @@ def deploy(self, # pylint: disable=too-many-arguments,too-many-locals
return True
regions = self._validate_regions(regions or [self.region])
region_list = [{"Region": region, "RegionConfigurationStatus": "ENABLED" if region in regions else "DISABLED"}
for region in self.get_available_regions(enable_gov_regions)]
for region in self.get_available_regions()]
validation = self._pre_deploy_check()
self.logger.debug('Got validation response %s.', validation)
if not all(list(entry.values()).pop().get('Result') == 'SUCCESS' for entry in validation):
Expand Down

0 comments on commit 425a354

Please sign in to comment.