mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Merge pull request #485 from JocaPC/master
Updating Create JumpboxVm for Managed Instance
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<!-- PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback -->
|
||||
@@ -6,17 +6,8 @@
|
||||
<AssemblyOriginatorKeyFile>hrkljush.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Remove="Areas\**" />
|
||||
<Compile Remove="SqlServerRestApi\**" />
|
||||
<Compile Remove="wwwroot\public\**" />
|
||||
<Content Remove="Areas\**" />
|
||||
<Content Remove="SqlServerRestApi\**" />
|
||||
<Content Remove="wwwroot\public\**" />
|
||||
<EmbeddedResource Remove="Areas\**" />
|
||||
<EmbeddedResource Remove="SqlServerRestApi\**" />
|
||||
<EmbeddedResource Remove="wwwroot\public\**" />
|
||||
<None Remove="Areas\**" />
|
||||
<None Remove="SqlServerRestApi\**" />
|
||||
<None Remove="wwwroot\public\**" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<#@ output extension=".yaml"#>
|
||||
<#@ assembly name="Newtonsoft.Json" #>
|
||||
<#@ template language="C#" hostspecific="True" #>
|
||||
<#
|
||||
var o = Newtonsoft.Json.Linq.JObject.Parse(System.IO.File.ReadAllText(this.Host.ResolvePath("..") + "\\appsettings.json"));
|
||||
var json = o["ApiModel"].ToString();
|
||||
TableDef[] config = Newtonsoft.Json.JsonConvert.DeserializeObject<TableDef[]>(json);
|
||||
#>
|
||||
swagger: "2.0"
|
||||
info:
|
||||
description: "OData service exposing information from WideWorldImporters database."
|
||||
version: "1.0.0"
|
||||
title: "Wide World Importers"
|
||||
termsOfService: "http://swagger.io/terms/"
|
||||
contact:
|
||||
email: "sqlserversamples@microsoft.com"
|
||||
license:
|
||||
name: "Apache 2.0"
|
||||
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
host: "localhost:64958"
|
||||
basePath: "/OData"
|
||||
tags:
|
||||
<# foreach(var t in config) {#>
|
||||
<# if(string.IsNullOrEmpty(t.ODataColumns)) continue; #>
|
||||
- name: "<#= t.Table #>"
|
||||
description: "Information about <#= t.Table #>"
|
||||
<# } #>
|
||||
schemes:
|
||||
- "https"
|
||||
- "http"
|
||||
paths:
|
||||
<# foreach(var t in config) {#>
|
||||
<# if(string.IsNullOrEmpty(t.ODataColumns)) continue; #>
|
||||
|
||||
/<#= t.Table #>:
|
||||
get:
|
||||
tags:
|
||||
- "<#= t.Table #>"
|
||||
summary: "Find information about <#= t.Table #>"
|
||||
description: "Multiple status values can be provided with comma separated strings"
|
||||
operationId: "<#= t.Table #>"
|
||||
produces:
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "$select"
|
||||
in: "query"
|
||||
description: "Selecting the properties that should be returned by service"
|
||||
required: false
|
||||
type: "array"
|
||||
items:
|
||||
type: "string"
|
||||
enum:<# foreach(var c in t.ODataColumns.Split(',')) {#>
|
||||
- "<#= c #>"<# } #>
|
||||
collectionFormat: "multi"
|
||||
- name: "$orderby"
|
||||
in: "query"
|
||||
description: "Ordering results by properties"
|
||||
required: false
|
||||
type: "array"
|
||||
items:
|
||||
type: "string"
|
||||
enum:<# foreach(var c in t.ODataColumns.Split(',')) {#>
|
||||
- "<#= c #>"
|
||||
- "<#= c #> asc"
|
||||
- "<#= c #> desc"<# } #>
|
||||
collectionFormat: "multi"
|
||||
- name: "$top"
|
||||
in: "query"
|
||||
description: "Selecting the properties that should be returned by service"
|
||||
required: false
|
||||
type: "integer"
|
||||
- name: "$skip"
|
||||
in: "query"
|
||||
description: "Selecting the properties that should be returned by service"
|
||||
required: false
|
||||
type: "integer"
|
||||
- name: "$apply"
|
||||
in: "query"
|
||||
description: "aggregation function that should be applied on the results"
|
||||
required: false
|
||||
type: "string"
|
||||
- name: "$filter"
|
||||
in: "query"
|
||||
description: "Condition that returned items must satisfy"
|
||||
required: false
|
||||
type: "string"
|
||||
responses:
|
||||
200:
|
||||
description: "Provided information about <#= t.Table #>."
|
||||
400:
|
||||
description: "The OData request is not valid"
|
||||
500:
|
||||
description: "Cannot process request"<# } #>
|
||||
<#+
|
||||
public class TableDef {
|
||||
public string Schema {get; set;}
|
||||
public string Table {get; set;}
|
||||
public string ODataColumns {get; set;}
|
||||
public bool IsReadOnly {get; set;}
|
||||
}
|
||||
#>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,12 +2,24 @@ $parameters = $args[0]
|
||||
|
||||
$subscriptionId = $parameters['subscriptionId']
|
||||
$resourceGroupName = $parameters['resourceGroupName']
|
||||
$virtualMachineName = $parameters['virtualMachineName']
|
||||
$virtualNetworkName = $parameters['virtualNetworkName']
|
||||
$managementSubnetName = $parameters['subnetName']
|
||||
$administratorLogin = $parameters['administratorLogin']
|
||||
$administratorLoginPassword = $parameters['administratorLoginPassword']
|
||||
|
||||
$scriptUrlBase = $args[1]
|
||||
|
||||
if($virtualMachineName -eq '' -or $virtualMachineName -eq $null) {
|
||||
$virtualMachineName = 'Jumpbox'
|
||||
Write-Host "VM Name: 'Jumpbox'." -ForegroundColor Green
|
||||
}
|
||||
|
||||
if($managementSubnetName -eq '' -or $managementSubnetName -eq $null) {
|
||||
$managementSubnetName = 'Management'
|
||||
Write-Host "Using subnet 'Management' to deploy jumpbox VM." -ForegroundColor Green
|
||||
}
|
||||
|
||||
function VerifyPSVersion
|
||||
{
|
||||
Write-Host "Verifying PowerShell version, must be 5.0 or higher."
|
||||
@@ -27,26 +39,27 @@ function EnsureLogin ()
|
||||
$context = Get-AzureRmContext
|
||||
If($null -eq $context.Subscription)
|
||||
{
|
||||
Write-Host "Loging in ..."
|
||||
Write-Host "Sign-in..."
|
||||
If($null -eq (Login-AzureRmAccount -ErrorAction SilentlyContinue -ErrorVariable Errors))
|
||||
{
|
||||
Write-Host ("Login failed: {0}" -f $Errors[0].Exception.Message) -ForegroundColor Red
|
||||
Write-Host ("Sign-in failed: {0}" -f $Errors[0].Exception.Message) -ForegroundColor Red
|
||||
Break
|
||||
}
|
||||
}
|
||||
Write-Host "User logedin." -ForegroundColor Green
|
||||
Write-Host "Sign-in successful." -ForegroundColor Green
|
||||
}
|
||||
|
||||
function SelectSubscriptionId {
|
||||
param (
|
||||
$subscriptionId
|
||||
)
|
||||
Write-Host "Selecting subscription '$subscriptionId'."
|
||||
Write-Host "Selecting subscription '$subscriptionId'..."
|
||||
$context = Get-AzureRmContext
|
||||
If($context.Subscription.Id -ne $subscriptionId)
|
||||
{
|
||||
Try
|
||||
{
|
||||
Write-Host "Switching subscription $context.Subscription.Id to '$subscriptionId'." -ForegroundColor Green
|
||||
Select-AzureRmSubscription -SubscriptionId $subscriptionId -ErrorAction Stop | Out-null
|
||||
}
|
||||
Catch
|
||||
@@ -65,14 +78,18 @@ function LoadVirtualNetwork {
|
||||
)
|
||||
Write-Host("Loading virtual network '{0}' in resource group '{1}'." -f $virtualNetworkName, $resourceGroupName)
|
||||
$virtualNetwork = Get-AzureRmVirtualNetwork -ResourceGroupName $resourceGroupName -Name $virtualNetworkName -ErrorAction SilentlyContinue
|
||||
If($null -ne $virtualNetwork.Id)
|
||||
$id = $virtualNetwork.Id
|
||||
If($null -ne $id)
|
||||
{
|
||||
Write-Host "Virtual network loaded." -ForegroundColor Green
|
||||
Write-Host "Virtual network with id $id is loaded." -ForegroundColor Green
|
||||
If($virtualNetwork.VirtualNetworkPeerings.Count -gt 0) {
|
||||
Write-Host "Virtual network is loaded, but it should not have peerings." -ForegroundColor Red
|
||||
}
|
||||
return $virtualNetwork
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "Virtual network not found." -ForegroundColor Red
|
||||
Write-Host "Virtual network $virtualNetworkName cannot be found." -ForegroundColor Red
|
||||
Break
|
||||
}
|
||||
}
|
||||
@@ -88,7 +105,7 @@ function SetVirtualNetwork
|
||||
}
|
||||
Catch
|
||||
{
|
||||
Write-Host "Failed: $_" -ForegroundColor Red
|
||||
Write-Host "Failed to configure Virtual Network: $_" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +139,7 @@ function ConvertUInt32ToIPAddress
|
||||
function CalculateNextAddressPrefix
|
||||
{
|
||||
param($virtualNetwork, $prefixLength)
|
||||
Write-Host "Calculating address prefix."
|
||||
Write-Host "Calculating address prefix with length $prefixLength..."
|
||||
$startIPAddress = 0
|
||||
ForEach($addressPrefix in $virtualNetwork.AddressSpace.AddressPrefixes)
|
||||
{
|
||||
@@ -133,7 +150,9 @@ function CalculateNextAddressPrefix
|
||||
}
|
||||
}
|
||||
$startIPAddress += 1
|
||||
return (ConvertUInt32ToIPAddress $startIPAddress) + "/" + $prefixLength
|
||||
$addressPrefixResult = (ConvertUInt32ToIPAddress $startIPAddress) + "/" + $prefixLength
|
||||
Write-Host "Using address prefix $addressPrefixResult." -ForegroundColor Green
|
||||
return $addressPrefixResult
|
||||
}
|
||||
|
||||
function CalculateVpnClientAddressPoolPrefix
|
||||
@@ -157,12 +176,22 @@ SelectSubscriptionId -subscriptionId $subscriptionId
|
||||
|
||||
$virtualNetwork = LoadVirtualNetwork -resourceGroupName $resourceGroupName -virtualNetworkName $virtualNetworkName
|
||||
|
||||
$managementSubnetPrefix = CalculateNextAddressPrefix $virtualNetwork 28
|
||||
$subnets = $virtualNetwork.Subnets.Name
|
||||
|
||||
$virtualNetwork.AddressSpace.AddressPrefixes.Add($managementSubnetPrefix)
|
||||
Add-AzureRmVirtualNetworkSubnetConfig -Name Management -VirtualNetwork $virtualNetwork -AddressPrefix $managementSubnetPrefix | Out-Null
|
||||
If($false -eq $subnets.Contains($managementSubnetName))
|
||||
{
|
||||
Write-Host "$managementSubnetName is not one of the subnets in $subnets" -ForegroundColor Yellow
|
||||
Write-Host "Creating subnet $managementSubnetName ($managementSubnetPrefix) in the VNet..." -ForegroundColor Green
|
||||
$managementSubnetPrefix = CalculateNextAddressPrefix $virtualNetwork 28
|
||||
|
||||
SetVirtualNetwork $virtualNetwork
|
||||
$virtualNetwork.AddressSpace.AddressPrefixes.Add($managementSubnetPrefix)
|
||||
Add-AzureRmVirtualNetworkSubnetConfig -Name $managementSubnetName -VirtualNetwork $virtualNetwork -AddressPrefix $managementSubnetPrefix | Out-Null
|
||||
|
||||
SetVirtualNetwork $virtualNetwork
|
||||
Write-Host "Added subnet $managementSubnetName into VNet." -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "The subnet $managementSubnetName exists in the VNet." -ForegroundColor Green
|
||||
}
|
||||
|
||||
Write-Host
|
||||
|
||||
@@ -171,9 +200,12 @@ Write-Host "Starting deployment..."
|
||||
|
||||
$templateParameters = @{
|
||||
virtualNetworkName = $virtualNetworkName
|
||||
managementSubnetPrefix = $managementSubnetPrefix
|
||||
managementSubnetName = $managementSubnetName
|
||||
virtualMachineName = $virtualMachineName
|
||||
administratorLogin = $administratorLogin
|
||||
administratorLoginPassword = $administratorLoginPassword
|
||||
}
|
||||
|
||||
New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase+'/azuredeploy.json?t='+ [DateTime]::Now.Ticks) -TemplateParameterObject $templateParameters
|
||||
|
||||
Write-Host "Deployment completed."
|
||||
@@ -15,12 +15,6 @@
|
||||
"description": "Enter virtual network name. If you leave this field blank name will be created by the template."
|
||||
}
|
||||
},
|
||||
"managementSubnetPrefix": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "Enter management subnet address prefix."
|
||||
}
|
||||
},
|
||||
"administratorLogin": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
@@ -32,20 +26,30 @@
|
||||
"metadata": {
|
||||
"description": "Enter password."
|
||||
}
|
||||
},
|
||||
"virtualMachineName": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "VM name."
|
||||
}
|
||||
},
|
||||
"managementSubnetName": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "VM subnet name."
|
||||
}
|
||||
}
|
||||
},
|
||||
"variables": {
|
||||
"managementSubnetName": "Management",
|
||||
"virtualMachineName": "JumpBox",
|
||||
"virtualMachineSize": "Standard_B2s",
|
||||
"networkInterfaceName": "nicJumpBox",
|
||||
"publicIPAddressName": "ipJumpBox",
|
||||
"networkSecurityGroupName": "nsgJumpBox",
|
||||
"networkInterfaceName": "[concat(parameters('virtualMachineName'),'-nic0')]",
|
||||
"publicIPAddressName": "[concat(parameters('virtualMachineName'),'-pip')]",
|
||||
"networkSecurityGroupName": "[concat(parameters('virtualMachineName'),'-nsg')]",
|
||||
"scriptFileUri": "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/201-sqlmi-new-vnet-w-jumpbox/installSSMS.ps1"
|
||||
},
|
||||
"resources": [
|
||||
{
|
||||
"name": "[variables('virtualMachineName')]",
|
||||
"name": "[parameters('virtualMachineName')]",
|
||||
"type": "Microsoft.Compute/virtualMachines",
|
||||
"apiVersion": "2018-06-01",
|
||||
"location": "[parameters('location')]",
|
||||
@@ -54,7 +58,7 @@
|
||||
],
|
||||
"properties": {
|
||||
"osProfile": {
|
||||
"computerName": "[variables('virtualMachineName')]",
|
||||
"computerName": "[parameters('virtualMachineName')]",
|
||||
"adminUsername": "[parameters('administratorLogin')]",
|
||||
"adminPassword": "[parameters('administratorLoginPassword')]",
|
||||
"windowsConfiguration": {
|
||||
@@ -94,7 +98,7 @@
|
||||
"location": "[parameters('location')]",
|
||||
"apiVersion": "2018-06-01",
|
||||
"dependsOn": [
|
||||
"[concat('Microsoft.Compute/virtualMachines/', variables('virtualMachineName'))]"
|
||||
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
|
||||
],
|
||||
"tags": {
|
||||
"displayName": "SetupChocolatey"
|
||||
@@ -130,7 +134,7 @@
|
||||
"name": "ipconfig1",
|
||||
"properties": {
|
||||
"subnet": {
|
||||
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), variables('managementSubnetName'))]"
|
||||
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('managementSubnetName'))]"
|
||||
},
|
||||
"privateIPAllocationMethod": "Dynamic",
|
||||
"publicIpAddress": {
|
||||
|
||||
Reference in New Issue
Block a user