<commit_before>#!/bin/bash

## vNet to vNet VPN Gateway connections
az network vpn-connection create --name Hub2OnPrem --vnet-gateway1 Hub-vnet-gw --vnet-gateway2 OnPrem-vnet-gw --shared-key M1crosoft123 --resource-group VDC-Hub
az network vpn-connection create --name OnPrem2Hub --vnet-gateway1 OnPrem-vnet-gw --vnet-gateway2 Hub-vnet-gw --shared-key M1crosoft123 --resource-group VDC-OnPrem

csrPip=$(az network nic ip-config list --resource-group VDC-NVA --nic-name csr-pip --query "[? name == 'ipconfig1'].publicIpAddress.ipAddress" --output tsv)<commit_msg>Updated internal script<commit_after>#!/bin/bash

## vNet to vNet VPN Gateway connections
hubVpnGwId=$(az network vnet-gateway show --resource-group VDC-Hub --name Hub-vpn-gw --query id --output tsv)
onpremVpnGwId=$(az network vnet-gateway show --resource-group VDC-OnPrem --name OnPrem-vpn-gw --query id --output tsv)

az network vpn-connection create --name Hub2OnPrem --vnet-gateway1 $hubVpnGwId --vnet-gateway2 $onpremVpnGwId --shared-key M1crosoft123 --resource-group VDC-Hub
az network vpn-connection create --name OnPrem2Hub --vnet-gateway1 $onpremVpnGwId --vnet-gateway2 $hubVpnGwId --shared-key M1crosoft123 --resource-group VDC-OnPrem

## Configure the CSR 

csrPip=$(az network public-ip show --name csr-pip --resource-group VDC-NVA --query ipAddress --output tsv)

ssh labuser@$csrPip <<-EOF
	conf t
	interface gig1
	ip address dhcp
	no shut
	interface gig2 
	ip address dhcp
	no shut
	file prompt quiet
	end
	copy running-config startup-config
	show ip interface brief
	exit
	EOF

## Create UDR for Hub vNet to static "external" CSR internal IP

az network route-table create --name OnPrem-UDR --resource-group VDC-OnPrem
az network route-table route create --name Spoke1-Route --address-prefix 10.1.0.0/16 --next-hop-type VirtualAppliance --next-hop-ip-address 10.101.1.4 --route-table-name OnPrem-UDR --resource-group VDC-OnPrem
az network route-table route create --name Spoke2-Route --address-prefix 10.2.0.0/16 --next-hop-type VirtualAppliance --next-hop-ip-address 10.101.1.4 --route-table-name OnPrem-UDR --resource-group VDC-OnPrem
az network vnet subnet update --name GatewaySubnet --vnet-name OnPrem-vnet --route-table OnPrem-UDR --resource-group VDC-OnPrem

## Create UDR for Hub vNet to static "external" CSR internal IP

az network route-table create --name Hub-UDR --resource-group VDC-Hub
az network route-table route create --name Spoke1-Route --address-prefix 10.1.0.0/16 --next-hop-type VirtualAppliance --next-hop-ip-address 10.101.1.4 --route-table-name Hub-UDR --resource-group VDC-Hub
az network route-table route create --name Spoke2-Route --address-prefix 10.2.0.0/16 --next-hop-type VirtualAppliance --next-hop-ip-address 10.101.1.4 --route-table-name Hub-UDR --resource-group VDC-Hub
az network vnet subnet update --name GatewaySubnet --vnet-name Hub-vnet --route-table Hub-UDR --resource-group VDC-Hub

## And for the spokes to the "internal" CSR internal IP

az network route-table create --name Spoke1-UDR -g VDC-Spoke1
az network route-table create --name Spoke2-UDR -g VDC-Spoke2

az network route-table route create --name OnPrem-Route --address-prefix 10.102.0.0/16 --next-hop-type VirtualAppliance --next-hop-ip-address 10.101.2.4 --route-table-name Spoke1-UDR -g VDC-Spoke1
az network route-table route create --name OnPrem-Route --address-prefix 10.102.0.0/16 --next-hop-type VirtualAppliance --next-hop-ip-address 10.101.2.4 --route-table-name Spoke2-UDR -g VDC-Spoke2

az network vnet subnet update --name Spoke1-vnet-subnet1 --vnet-name Spoke1-vnet --route-table Spoke1-UDR -g VDC-Spoke1
az network vnet subnet update --name Spoke2-vnet-subnet1 --vnet-name Spoke2-vnet --route-table Spoke2-UDR -g VDC-Spoke2

## Update peerings 

az network vnet peering update --set useRemoteGateways=true --resource-group VDC-Spoke1 --name to-Hub-vnet --vnet-name Spoke1-vnet
az network vnet peering update --set useRemoteGateways=true --resource-group VDC-Spoke2 --name to-Hub-vnet --vnet-name Spoke2-vnet

# Test out the connectivity

onpremVmPip=$(az network public-ip show --name OnPrem-vm-pip --resource-group VDC-OnPrem --query ipAddress --output tsv)
spoke1LbPip=$(az network public-ip show --name Spoke1-lb-pip --resource-group VDC-Spoke1 --query ipAddress --output tsv)

ssh labuser@$onpremVmPip 
{'fraction_non_alphanumeric': 0.12407063197026022, 'fraction_numerical': 0.03438661710037175, 'mean_word_length': 3.594450373532551, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 12, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1964112', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1507, 'n_words': 432}