Beispiel #1
0
    def __init__(self, name, cidr_block, description=None):
        """Create a VPC stack.

        :param name: stack name
        :type name: str
        :param cidr_block: ipv4 address range for the vpc
        :type cird_block: str
        :param description: optional description
        :type description: str | None
        """
        super(VPCStack, self).__init__(name, description)
        self.add(VPC(self.name, cidr_block))
        self.add(InternetGateway(self.name + 'InternetGateway'))
        self.add(VPCGatewayAttachment(self.name + 'GateLink',
                                      self.vpc, self.gateway))
Beispiel #2
0
def test_nat_gateway():
    """Create a NATGateway."""
    s = Stack(name="MyStack")
    s += VPC("BuildVPC", "10.10.0.0/16")
    s += Subnet("BuildPublicSubnet", s["BuildVPC"], "10.10.10.0/24")
    s += Subnet("BuildPrivateSubnet", s["BuildVPC"], "10.10.20.0/24")
    s += InternetGateway("Gate")
    s += VPCGatewayAttachment("GateAttach", s["BuildVPC"], s["Gate"])
    s += RouteTable("RT", s["BuildVPC"])
    s += Route("PRoute", s["RT"], "0.0.0.0/0", s["Gate"], s["GateAttach"])
    s += SubnetRouteTableAssociation("RTSAssoc", s["BuildPublicSubnet"], s["RT"])
    s += EIP("NatEip", s["GateAttach"])
    s += NatGateway("NatGate", s["NatEip"], s["BuildPublicSubnet"])

    s += RouteTable("NATRT", s["BuildVPC"])
    s += Route("NATRoute", s["NATRT"], "0.0.0.0/0", s["NatGate"], s["GateAttach"])
    s += SubnetRouteTableAssociation("NatRTSAssoc", s["BuildPrivateSubnet"], s["NATRT"])
    assert s.body
Beispiel #3
0
def test_create_network():
    s = Stack(name='teststack')

    s = Stack(name='MyStack')
    s += VPC('BuildVPC', '10.10.0.0/16')
    s += InternetGateway('Gate')
    s += Subnet('BuildPublicSubnet', s['BuildVPC'], '10.10.10.0/24')
    s += Subnet('BuildPrivateSubnet', s['BuildVPC'], '10.10.20.0/24')
    s += VPCGatewayAttachment('GateAttach',
                              s['BuildVPC'],
                              s['Gate'])
    s += RouteTable('RT', s['BuildVPC'])
    s += Route('PRoute', s['RT'],
               '0.0.0.0/0',
               s['Gate'],
               s['GateAttach'])
    s += SubnetRouteTableAssociation('RTSAssoc',
                                     s['BuildPublicSubnet'],
                                     s['RT'])
    assert s.body
Beispiel #4
0
def test_nat_gateway():
    """Create a NATGateway."""
    s = Stack(name='MyStack')
    s += VPC('BuildVPC', '10.10.0.0/16')
    s += Subnet('BuildPublicSubnet', s['BuildVPC'], '10.10.10.0/24')
    s += Subnet('BuildPrivateSubnet', s['BuildVPC'], '10.10.20.0/24')
    s += InternetGateway('Gate')
    s += VPCGatewayAttachment('GateAttach', s['BuildVPC'], s['Gate'])
    s += RouteTable('RT', s['BuildVPC'])
    s += Route('PRoute', s['RT'], '0.0.0.0/0', s['Gate'], s['GateAttach'])
    s += SubnetRouteTableAssociation('RTSAssoc', s['BuildPublicSubnet'],
                                     s['RT'])
    s += EIP('NatEip', s['GateAttach'])
    s += NatGateway('NatGate', s['NatEip'], s['BuildPublicSubnet'])

    s += RouteTable('NATRT', s['BuildVPC'])
    s += Route('NATRoute', s['NATRT'], '0.0.0.0/0', s['NatGate'],
               s['GateAttach'])
    s += SubnetRouteTableAssociation('NatRTSAssoc', s['BuildPrivateSubnet'],
                                     s['NATRT'])
    assert s.body
Beispiel #5
0
def test_create_network():
    s = Stack(name="teststack")

    s = Stack(name="MyStack")
    s += VPC("BuildVPC", "10.10.0.0/16")
    s += InternetGateway("Gate")
    s += Subnet("BuildPublicSubnet", s["BuildVPC"], "10.10.10.0/24")
    s += Subnet("BuildPrivateSubnet", s["BuildVPC"], "10.10.20.0/24")
    s += VPCGatewayAttachment("GateAttach", s["BuildVPC"], s["Gate"])
    s += RouteTable("RT", s["BuildVPC"])
    s += Route("PRoute", s["RT"], "0.0.0.0/0", s["Gate"], s["GateAttach"])
    s += SubnetRouteTableAssociation("RTSAssoc", s["BuildPublicSubnet"], s["RT"])
    p = PolicyDocument().append(
        Allow(
            to="GetObject",
            on="arn:aws:s3:::abucket/*",
            apply_to=Principal(PrincipalKind.SERVICE, "ec2.amazonaws.com"),
        )
    )

    s += VPCEndpoint("S3EndPoint", "s3", s["BuildVPC"], [s["RT"]], policy_document=p)
    assert s.body
Beispiel #6
0
def test_create_network():
    s = Stack(name='teststack')

    s = Stack(name='MyStack')
    s += VPC('BuildVPC', '10.10.0.0/16')
    s += InternetGateway('Gate')
    s += Subnet('BuildPublicSubnet', s['BuildVPC'], '10.10.10.0/24')
    s += Subnet('BuildPrivateSubnet', s['BuildVPC'], '10.10.20.0/24')
    s += VPCGatewayAttachment('GateAttach', s['BuildVPC'], s['Gate'])
    s += RouteTable('RT', s['BuildVPC'])
    s += Route('PRoute', s['RT'], '0.0.0.0/0', s['Gate'], s['GateAttach'])
    s += SubnetRouteTableAssociation('RTSAssoc', s['BuildPublicSubnet'],
                                     s['RT'])
    p = PolicyDocument().append(
        Allow(to='GetObject',
              on='arn:aws:s3:::abucket/*',
              apply_to=Principal(PrincipalKind.SERVICE, 'ec2.amazonaws.com')))

    s += VPCEndpoint('S3EndPoint',
                     's3',
                     s['BuildVPC'], [s['RT']],
                     policy_document=p)
    assert s.body