ecs_composex.vpc package

Submodules

ecs_composex.vpc.aws_mappings module

Generic mappings for well-known AWS Settings not yet in SSM

ecs_composex.vpc.helpers module

ecs_composex.vpc.helpers. define_vpc_settings ( settings , vpc_module , vpc_stack ) [source]

Function to deal with vpc stack settings

ecs_composex.vpc.helpers. update_network_resources_vpc_config ( settings , vpc_stack ) [source]

Iterate over the settings.x_resources, over the root stack nested stacks. If the nested stack has x_resources that depend on VPC, update the stack parameters with the vpc stack settings

Although the first if should never be true, setting condition in case for safety.

ecs_composex.vpc.vpc_aws module

ecs_composex.vpc.vpc_aws. delete_subnet_from_settings ( subnets , subnet_key , vpc_settings ) [source]

Deletes subnets that are not part of the VPC from vpc_settings

Parameters :
  • subnets ( list [ dict ] ) –

  • subnet_key ( str ) –

  • vpc_settings ( dict ) –

ecs_composex.vpc.vpc_aws. lookup_x_vpc_settings ( vpc_resource ) [source]

Method to set VPC settings from x-vpc

Parameters :

vpc_resource ( ecs_composex.vpc.vpc_stack.Vpc ) –

Returns :

vpc_settings

Return type :

dict

ecs_composex.vpc.vpc_aws. validate_subnets_belong_with_vpc ( vpc_settings , subnet_keys , session = None ) [source]

Function to ensure all subnets belong to the identified VPC

Parameters :
  • vpc_settings ( dict ) –

  • subnet_keys ( list [ str ] ) –

  • session ( boto3.session.Session ) –

Raises :

boto3.client.exceptions

Return type :

None

ecs_composex.vpc.vpc_cloudmap module

Handles mapping x-vpc to cloudmap resource

ecs_composex.vpc.vpc_cloudmap. x_vpc_to_x_cloudmap ( x_vpc , x_resource , property_stack , properties_to_update , property_name , settings ) [source]

Updates properties of given resource with the VPC settings accordingly

Parameters :

ecs_composex.vpc.vpc_conditions module

ecs_composex.vpc.vpc_maths module

3 Layers subnets calculator for 3-tier VPC

ecs_composex.vpc.vpc_maths. cut_per_az ( az_cidr , layers_cidr ) [source]

Subdivide the range per AZ in the region

Parameters :
  • az_cidr – CIDR to split

  • layers_cidr – dict() getting updated with layers

Returns :

NIL

ecs_composex.vpc.vpc_maths. get_subnet_layers ( cidr , azs ) [source]

Get Subnets layers based on number of AZs

ecs_composex.vpc.vpc_maths. get_subnets ( cidr , azs ) [source]

Get the lists of Subnets CIDRs

ecs_composex.vpc.vpc_module module

ecs_composex.vpc.vpc_params module

Parameters related to the VPC settings. Used by ecs_composex.vpc and others

ecs_composex.vpc.vpc_stack module

Module for VpcStack

class ecs_composex.vpc.vpc_stack. Vpc ( name , definition , module , settings ) [source]

Bases: AwsEnvironmentResource

Class to represent the VPC

create_vpc ( template , settings ) [source]

Creates a new VPC from Properties (or from defaults)

Return type :

None

create_vpc_mappings ( vpc_settings ) [source]

Generates the VPC CFN Mappings

Parameters :
Returns :

default_ipv4_cidr = '100.64.72.0/24'
handle_x_dependencies ( settings , root_stack ) [source]

Function to have x-vpc update resources that have the x-vpc value where VpcID should be.

Return type :

None

init_outputs ( ) [source]

Initialize output properties to pass on to the other stacks that need these values

Return type :

None

lookup_vpc ( ) [source]

Method to set VPC settings from x-vpc

Return type :

None

required_subnets = ['AppSubnets', 'PublicSubnets', 'StorageSubnets']
set_azs_from_api ( ) [source]

Method to set the AWS Azs based on DescribeAvailabilityZones

Return type :

None

set_azs_from_vpc_import ( subnets , session = None ) [source]

Function to get the list of AZs for a given set of subnets

Return type :

None

storage_subnets_count ( ) [source]
Return type :

int

class ecs_composex.vpc.vpc_stack. XStack ( title , settings , module , ** kwargs ) [source]

Bases: ComposeXStack

Class to create the VPC Stack

create_new_default_vpc ( title , vpc_module , settings ) [source]

In case no x-vpc was specified but the deployment settings require a new VPC, allows for an easy way to set one.

property vpc_id

Gives the VPC ID :return:

ecs_composex.vpc.vpc_stack. init_vpc_template ( ) [source]

Simple wrapper function to create the VPC Template

Return type :

troposhere.Template

ecs_composex.vpc.vpc_subnets module

Functions to add the three VPC layer type subnets:

  • Storage

  • Public

  • App

RTB -> Route Table

Storage subnet type : All subnets use the same RTB, no route to 0.0.0.0/0 Public subnet type: All subnets use the same RTB, route to 0.0.0.0/0 via InternetGateway App subnet type: Each subnet has its own RTB, each RTB points to a different NAT Gateway in its respective AZ

ecs_composex.vpc.vpc_subnets. add_apps_subnets ( template , vpc , az_index , layers , nats , endpoints = None ) [source]

Function to add application/hosts subnets to the VPC

Parameters :
  • template – VPC Template()

  • vpc – Vpc() for Ref()

  • az_index ( list ) – index for the AZ (a,b,c ..)

  • nats – list of NatGateway()

Returns :

tuple() list of rtb, list of subnets

ecs_composex.vpc.vpc_subnets. add_gateway_endpoint ( service , rtbs , template ) [source]

Function to add a service endpoint for gateways

ecs_composex.vpc.vpc_subnets. add_interface_endpoint ( sg , service , subnets , template ) [source]

Function to add a service endpoint for gateways

ecs_composex.vpc.vpc_subnets. add_public_subnets ( template , vpc , az_index , layers , igw , single_nat , disable_nat = False ) [source]

Function to add public subnets for the VPC

Parameters :
  • layers ( dict ) – layers of subnets

  • igw ( troposphere.ec2.InternetGateway ) – internet gateway to route to

  • single_nat ( boolean ) – whether we should have a single NAT Gateway

  • template ( troposphere.Template ) – VPC Template()

  • vpc ( troposphere.ec2.Template ) – Vpc() for Ref()

  • az_range ( list ) – range for iteration over select AZs

Returns :

tuple() list of rtb, list of subnets, list of nats

ecs_composex.vpc.vpc_subnets. add_storage_subnets ( template , vpc , az_index , layers ) [source]

Function to add storage subnets inside the VPC

Parameters :
  • layers ( dict ) – VPC layers

  • template ( troposphere.Template ) – VPC Template()

  • vpc ( troposphere.ec2.Vpc ) – Vpc() for Ref()

  • az_index ( list ) – List of AZ Index (a,b,c..)

Returns :

tuple() list of rtb, list of subnets

ecs_composex.vpc.vpc_subnets. define_nats ( az_index , nats ) [source]

if there is not as many nats as there are AZs, that means we need to re-use that NAT GW for each app subnet

If nats is empty, that means DisableNat is true and there for we just need an iterable with None for each AZ

Parameters :
  • az_index ( list ) –

  • nats ( list ) –

Returns :

List of nats to use

Return type :

list

ecs_composex.vpc.vpc_template module

Create the VPC template and its associated resources

ecs_composex.vpc.vpc_template. add_vpc_core ( template , vpc_cidr , dhcp_options ) [source]

Function to create the core resources of the VPC and add them to the core VPC template

Parameters :
  • template – VPC Template()

  • vpc_cidr – str of the VPC CIDR i.e. 192.168.0.0/24

Returns :

tuple() with the vpc and igw object

ecs_composex.vpc.vpc_template. add_vpc_flow ( template , vpc , boundary = None ) [source]

Function to add VPC Flow Log to log VPC

Parameters :
  • template ( troposphere.Template ) –

  • vpc – The VPC Object

  • boundary ( str ) –

Module contents