-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetwork.py
82 lines (61 loc) · 1.93 KB
/
network.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
"""Module with VPC resources."""
from __future__ import print_function
from troposphere import (
Ref, Output, ec2, GetAtt
)
from stacker.blueprints.base import Blueprint
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# LOGICAL RESOURCES NAMES
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VPC_NAME = 'VPC'
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# RESOURCES IDs
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VPC_ID = Ref(VPC_NAME)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# OUTPUT VARIABLES
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OUTPUT_VPC_ID = 'VpcId'
AWS_TEMPLATE_VERSION = '2010-09-09'
class NETWORKING(Blueprint):
"""Stacker blueprint for creating a Basic VPC."""
VARIABLES = {
'VpcCidr': {
'type': str,
'description': 'CIDR block range for VPC ip space',
},
'VpcName': {
'type': str,
'description': 'The Name of the deployed VPC',
'Default': 'myVPC'
}
}
def create_vpc(self):
"""Create the VPC resources."""
template = self.template
variables = self.get_variables()
self.template.add_version(AWS_TEMPLATE_VERSION)
self.template.add_description('Create a VPC')
vpc = ec2.VPC(
VPC_NAME,
CidrBlock=variables['VpcCidr'],
EnableDnsSupport=True,
EnableDnsHostnames=True,
Tags=[ec2.Tag('Name', variables['VpcName'])]
)
template.add_resource(vpc)
template.add_output(
Output(
OUTPUT_VPC_ID,
Value=VPC_ID
)
)
def create_template(self):
"""Create template (main function called by Stacker)."""
self.create_vpc()
# Helper section to enable easy blueprint -> template generation
# (just run `python <thisfile>` to output the json)
if __name__ == "__main__":
from stacker.context import Context
print(NETWORKING('test', Context({'namespace': 'test'}), None).to_json())