Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Merge pull request #113 from aryszka/custom-subnets
Browse files Browse the repository at this point in the history
use custom names for custom subnets
  • Loading branch information
jonathanbeber committed Jul 7, 2021
2 parents 509364d + e4c0175 commit 57fb3c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sevenseconds/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .config.configure import start_configuration, start_cleanup

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
SUPPORTED_CONFIG_VERSION = 9
SUPPORTED_CONFIG_VERSION = 10


def print_version(ctx, param, value):
Expand Down
8 changes: 6 additions & 2 deletions sevenseconds/config/vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def configure_vpc(account: AccountData, region, base_ami_id):
info('Region with non default VPC-Network: {}'.format(vpc_net))
with ActionOnExit('Finding existing default VPC..'):
vpc = find_vpc(ec2, VPC_NET)
if vpc:
# we only need to delete it if we use different settings for the VPC:
if vpc and vpc_net != VPC_NET:
with ActionOnExit('Deleting old default VPC..') as act:
delete_vpc(vpc, region)
delete_vpc_addresses(account.session, region)
Expand Down Expand Up @@ -255,6 +256,8 @@ def delete_rds_subnet_group(session: object, region: str):
def configure_subnet(vpc, subnet: Subnet, dry_run: bool, waiter):
name = '{}-{}'.format(subnet.subnet_type, subnet.availability_zone)
tags = dict(subnet.tags)
custom_name = tags.get('zalando.org/custom-subnet')
name = custom_name and '{}-{}-{}'.format(subnet.subnet_type, custom_name, subnet.availability_zone) or name
tags['Name'] = name
existing_subnet = find_subnet(vpc, subnet.cidr)
if not existing_subnet:
Expand All @@ -268,7 +271,8 @@ def configure_subnet(vpc, subnet: Subnet, dry_run: bool, waiter):
{'Name': 'availabilityZone',
'Values': [subnet.availability_zone]}
])
existing_subnet.create_tags(Tags=[{'Key': k, 'Value': v} for k, v in tags.items()])
if not dry_run:
existing_subnet.create_tags(Tags=[{'Key': k, 'Value': v} for k, v in tags.items()])


def find_subnet(vpc: object, cidr):
Expand Down

0 comments on commit 57fb3c0

Please sign in to comment.