Code Monkey home page Code Monkey logo

Comments (2)

jpeezus avatar jpeezus commented on August 29, 2024

yes you would have to change the SubscriberVPC template to enable route propagation and it will be turned on during launch.

from aws-transit-vpc.

freimer avatar freimer commented on August 29, 2024

in commonLambdaFunctions.py:

def createVgwAttachToVpc(vpcId, vgwAsn, region, paGroup):
    """Creates a VGW and attach it to the VPC, returns VgwId
    """
    try:
        tags = [{'Key': 'Name', 'Value': paGroup}]
        import time
        ec2Connection = boto3.client('ec2', region_name=region)
        # Create VGW with vgwAsn
        response = ec2Connection.create_vpn_gateway(Type='ipsec.1', AmazonSideAsn=int(vgwAsn))
        vgw_id = response['VpnGateway']['VpnGatewayId']
        # Attach VGW to VPC
        while True:
            status = ec2Connection.attach_vpn_gateway(VpcId=vpcId, VpnGatewayId=vgw_id,
                                                      DryRun=False)['VpcAttachment']
            if status['State'] == 'attaching':
                time.sleep(2)
            elif status['State'] == 'attached':
                ec2Connection.create_tags(Resources=[vgw_id], Tags=tags)
                # Propagate routes to routing table
                route_tables = ec2Connection.describe_route_tables(
                    Filters=[{'Name': 'vpc-id', 'Values': [vpcId]},{'Name': 'association.main', 'Values': ['false']}])
                ec2Connection.enable_vgw_route_propagation(RouteTableId=route_tables['RouteTables'][0]['RouteTableId'],
                                                           GatewayId=vgw_id)
                return vgw_id
            else:
                return None
        # return response['VpnGateway']['VpnGatewayId']
    except Exception as e:
        logger.error("Error creating Vgw and Attaching it to VPC, Error : {}".format(str(e)))
        return False

This assumes that there are no additional route tables created in the subscribing VPC other than the non-default one created by the CF/TF template. The relevant change is the addition of these lines:

                # Propagate routes to routing table
                route_tables = ec2Connection.describe_route_tables(
                    Filters=[{'Name': 'vpc-id', 'Values': [vpcId]},{'Name': 'association.main', 'Values': ['false']}])
                ec2Connection.enable_vgw_route_propagation(RouteTableId=route_tables['RouteTables'][0]['RouteTableId'],
                                                           GatewayId=vgw_id)

from aws-transit-vpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.