-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.bicep
More file actions
258 lines (245 loc) · 5.62 KB
/
Copy pathmain.bicep
File metadata and controls
258 lines (245 loc) · 5.62 KB
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
targetScope = 'resourceGroup'
// Define external IP address do GCP VPN gateway, criação de IP em GCP precisa ser rodado antes.
param gcp_vpn_gateway_ip string
param location string = 'eastus'
var virtualNetworkName = 'VNET01'
var subnetName = 'subnet01'
var gatewaySubnet = 'GatewaySubnet'
var networkInterfaceName = 'vm-nic'
var subnetRef = resourceId('Microsoft.Network/virtualNetworks/subnets', virtualNetworkName, subnetName)
var nsgName = 'vm-nsg'
var vpnIpPublicName = 'vpn-ipv4'
var ipPublicName = 'vm-ipv4'
var vmName = 'vm01'
var vpnGatewayName = 'vpn-gw'
var localNetworkGatewayName = 'localNetworkGateway'
var connectionName = 'vpnConnection'
var vmSize = 'Standard_B1ls'
// Define VNET e Subnet
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2021-05-01' = {
name: virtualNetworkName
location: location
properties: {
addressSpace: {
addressPrefixes: [
'10.10.0.0/25'
]
}
subnets: [
{
name: subnetName
properties: {
addressPrefix: '10.10.0.0/27'
}
}
{
name: gatewaySubnet
properties: {
addressPrefix: '10.10.0.32/27'
}
}
]
}
}
// Criar Ip Publico para VM
resource vpnPublicIP 'Microsoft.Network/publicIPAddresses@2021-02-01' = {
name: vpnIpPublicName
location: location
properties: {
publicIPAddressVersion: 'IPv4'
publicIPAllocationMethod: 'Dynamic'
}
}
resource publicIP 'Microsoft.Network/publicIPAddresses@2021-02-01' = {
name: ipPublicName
location: location
properties: {
publicIPAddressVersion: 'IPv4'
publicIPAllocationMethod: 'Dynamic'
}
}
// Define VPN Gateway do Tunnel em Azure
resource vpnGateway 'Microsoft.Network/virtualNetworkGateways@2021-02-01' = {
name: vpnGatewayName
location: location
dependsOn: [
vpnPublicIP
virtualNetwork
]
properties: {
ipConfigurations: [
{
name: 'vnetGatewayConfig'
properties: {
privateIPAllocationMethod: 'Dynamic'
subnet: {
id: '${virtualNetwork.id}/subnets/GatewaySubnet'
}
publicIPAddress: {
id: vpnPublicIP.id
}
}
}
]
gatewayType: 'Vpn'
vpnType: 'RouteBased'
enableBgp: false
sku: {
name: 'Basic'
tier: 'Basic'
}
}
}
// Define o local network gateway para GCP network in Azure
resource localNetworkGateway 'Microsoft.Network/localNetworkGateways@2021-02-01' = {
name: localNetworkGatewayName
location: location
properties: {
localNetworkAddressSpace: {
addressPrefixes: [
'10.20.0.0/25'
]
}
gatewayIpAddress: '${gcp_vpn_gateway_ip}'
}
}
// Define the connection between the VPN gateways in Azure and GCP
resource connection 'Microsoft.Network/connections@2021-02-01' = {
name: connectionName
location: location
dependsOn: [
localNetworkGateway
vpnGateway
]
properties: {
virtualNetworkGateway1: {
id: vpnGateway.id
}
localNetworkGateway2: {
id: localNetworkGateway.id
}
connectionType: 'IPsec'
routingWeight: 10
sharedKey: 'shared-key-here'
connectionProtocol: 'IKEv2'
}
}
// Define NSG
resource nsg 'Microsoft.Network/networkSecurityGroups@2021-02-01' = {
name: nsgName
location: location
properties: {
securityRules: [
{
name: 'ssh-allow'
properties: {
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '22'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 300
direction: 'Inbound'
}
}
{
name: 'icmp-allow'
properties: {
protocol: 'Icmp'
sourcePortRange: '*'
destinationPortRange: '*'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 301
direction: 'Inbound'
}
}
{
name: 'gcp-allow'
properties: {
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '*'
sourceAddressPrefix: '10.20.0.0/25'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 302
direction: 'Inbound'
}
}
]
}
}
// Define NIC
resource nic 'Microsoft.Network/networkInterfaces@2021-02-01' = {
name: networkInterfaceName
location: location
dependsOn: [
publicIP
]
properties: {
ipConfigurations: [
{
name: 'ip-config'
properties: {
subnet: {
id: subnetRef
}
publicIPAddress: {
id: publicIP.id
}
privateIPAllocationMethod: 'Dynamic'
}
}
]
networkSecurityGroup: {
id: nsg.id
}
}
}
// Create the VM in Azure
resource vm 'Microsoft.Compute/virtualMachines@2021-03-01' = {
name: vmName
location: location
dependsOn: [
nic
]
properties: {
hardwareProfile: {
vmSize: vmSize
}
storageProfile: {
imageReference: {
publisher: 'Canonical'
offer: 'UbuntuServer'
sku: '18.04-LTS'
version: 'latest'
}
osDisk: {
createOption: 'fromImage'
}
}
osProfile: {
computerName: vmName
adminUsername: 'ubuntu01'
adminPassword: 'pwd-here'
linuxConfiguration: {
disablePasswordAuthentication: false
}
}
networkProfile: {
networkInterfaces: [
{
id: nic.id
properties: {
primary: true
}
}
]
}
}
}
// Define Outputs
output vpnPublicIPName string = vpnPublicIP.name