forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vdc.py
259 lines (244 loc) · 7.76 KB
/
vdc.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
from pulumi import ResourceOptions
from pulumi.resource import CustomTimeouts
from pulumi_azure import core, network, compute
# Variables that may need to be injected before calling functions:
# vdc.resource_group_name = props.resource_group_name
# vdc.tags = props.tags
# vdc.self = self
def bastion_host(stem, subnet_id, depends_on=None):
ab_pip = network.PublicIp(
f'{stem}-ab-pip-',
resource_group_name = resource_group_name,
sku = 'Standard',
allocation_method = 'Static',
tags = tags,
opts = ResourceOptions(parent=self),
)
ab = compute.BastionHost(
f'{stem}-ab-',
resource_group_name = resource_group_name,
ip_configuration = {
'name': f'{stem}-ab-ipconf',
'publicIpAddressId': ab_pip.id,
'subnet_id': subnet_id,
},
tags = tags,
opts = ResourceOptions(parent=self, depends_on=depends_on),
)
return ab
def expressroute_gateway(stem, subnet_id, depends_on=None):
er_gw_pip = network.PublicIp(
f'{stem}-er-gw-pip-',
resource_group_name = resource_group_name,
allocation_method = 'Dynamic',
tags = tags,
opts = ResourceOptions(parent=self),
)
er_gw = network.VirtualNetworkGateway(
f'{stem}-er-gw-',
resource_group_name = resource_group_name,
sku = 'Standard',
type = 'ExpressRoute',
vpn_type = 'RouteBased',
ip_configurations = [{
'name': f'{stem}-er-gw-ipconf',
'publicIpAddressId': er_gw_pip.id,
'subnet_id': subnet_id,
}],
tags = tags,
opts = ResourceOptions(
parent=self,
depends_on=depends_on,
custom_timeouts=CustomTimeouts(
create='1h',
update='1h',
delete='1h',
),
),
)
return er_gw
def firewall(stem, fw_sn_id, fwm_sn_id, depends_on=None):
fw_pip = network.PublicIp(
f'{stem}-fw-pip-',
resource_group_name = resource_group_name,
sku = 'Standard',
allocation_method = 'Static',
tags = tags,
opts = ResourceOptions(parent=self),
)
# fwm_pip = network.PublicIp( # requires api 2019-11-01 or later
# f'{stem}-fwm-pip-',
# resource_group_name = resource_group_name,
# sku = 'Standard',
# allocation_method = 'Static',
# tags = tags,
# opts = ResourceOptions(parent=self),
# )
fw = network.Firewall(
f'{stem}-fw-',
resource_group_name = resource_group_name,
# sku = 'AZFW_VNet', # not required but distinguishes from 'AZFW_Hub'
ip_configurations = [{
'name': f'{stem}-fw-ipconf',
'publicIpAddressId': fw_pip.id,
'subnet_id': fw_sn_id,
}],
# management_ip_configuration = { # requires api 2019-11-01 or later
# 'name': f'{stem}-fwm-ipconf',
# 'publicIpAddressId': fwm_pip.id,
# 'subnet_id': fwm_sn_id,
# },
tags = tags,
opts = ResourceOptions(
parent=self,
depends_on=depends_on,
custom_timeouts=CustomTimeouts(
create='1h',
update='1h',
delete='1h',
),
),
)
return fw
def resource_group(stem):
rg = core.ResourceGroup(
f'{stem}-vdc-rg-',
tags = tags,
)
return rg.name
def route_table(stem, disable_bgp_route_propagation=None, depends_on=None):
rt = network.RouteTable(
f'{stem}-rt-',
resource_group_name = resource_group_name,
disable_bgp_route_propagation = disable_bgp_route_propagation,
tags = tags,
opts = ResourceOptions(parent=self, depends_on=depends_on),
)
return rt
def route_to_virtual_appliance(
stem,
route_table_name,
address_prefix,
next_hop_in_ip_address,
):
r_va = network.Route(
f'{stem}-r-',
resource_group_name = resource_group_name,
address_prefix = address_prefix,
next_hop_type = 'VirtualAppliance',
next_hop_in_ip_address = next_hop_in_ip_address,
route_table_name = route_table_name,
opts = ResourceOptions(parent=self),
)
return r_va
def route_to_virtual_network(stem, route_table_name, address_prefix):
r_vn = network.Route(
f'{stem}-r-',
resource_group_name = resource_group_name,
address_prefix = address_prefix,
next_hop_type = 'VnetLocal',
route_table_name = route_table_name,
opts = ResourceOptions(parent=self),
)
return r_vn
def subnet(stem, virtual_network_name, address_prefix, depends_on=None):
sn = network.Subnet(
f'{stem}-sn-',
resource_group_name = resource_group_name,
address_prefixes = [address_prefix],
virtual_network_name = virtual_network_name,
opts = ResourceOptions(parent=self, depends_on=depends_on),
)
return sn
def subnet_route_table(stem, route_table_id, subnet_id):
rta = network.SubnetRouteTableAssociation(
f'{stem}-sn-rta',
route_table_id = route_table_id,
subnet_id = subnet_id,
opts = ResourceOptions(parent=self),
)
return rta
def subnet_special(
stem,
name,
virtual_network_name,
address_prefix,
depends_on=[],
):
sn = network.Subnet(
f'{stem}-sn',
name = name,
resource_group_name = resource_group_name,
address_prefixes = [address_prefix],
virtual_network_name = virtual_network_name,
opts = ResourceOptions(
parent=self,
delete_before_replace=True,
depends_on=depends_on,
),
)
return sn
def virtual_network(stem, address_spaces):
vn = network.VirtualNetwork(
f'{stem}-vn-',
resource_group_name = resource_group_name,
address_spaces = address_spaces,
tags = tags,
opts = ResourceOptions(parent=self),
)
return vn
def vnet_peering(
stem,
virtual_network_name,
peer,
remote_virtual_network_id,
allow_forwarded_traffic=None,
allow_gateway_transit=None,
use_remote_gateways=None,
depends_on=None,
):
vnp = network.VirtualNetworkPeering(
f'{stem}-{peer}-vnp-',
resource_group_name = resource_group_name,
virtual_network_name = virtual_network_name,
remote_virtual_network_id = remote_virtual_network_id,
allow_forwarded_traffic = allow_forwarded_traffic,
allow_gateway_transit = allow_gateway_transit,
use_remote_gateways = use_remote_gateways,
allow_virtual_network_access = True,
opts = ResourceOptions(parent=self, depends_on=depends_on),
)
return vnp
def vpn_gateway(stem, subnet_id, depends_on=None):
vpn_gw_pip = network.PublicIp(
f'{stem}-vpn-gw-pip-',
resource_group_name = resource_group_name,
allocation_method = 'Dynamic',
tags = tags,
opts = ResourceOptions(parent=self),
)
vpn_gw = network.VirtualNetworkGateway(
f'{stem}-vpn-gw-',
resource_group_name = resource_group_name,
sku = 'VpnGw1',
type = 'Vpn',
vpn_type = 'RouteBased',
ip_configurations = [{
'name': f'{stem}-vpn-gw-ipconf',
'publicIpAddressId': vpn_gw_pip.id,
'subnet_id': subnet_id,
}],
tags = tags,
opts = ResourceOptions(
parent=self,
depends_on=depends_on,
custom_timeouts=CustomTimeouts(
create='1h',
update='1h',
delete='1h',
),
),
)
return vpn_gw
if __name__ == "__main__":
print(dir())