Adding Azure Demo (#1922)
This commit is contained in:
parent
c829d9e915
commit
1d1bf1942c
65
demos/Azure/Azure-Demo.ps1
Normal file
65
demos/Azure/Azure-Demo.ps1
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
### The techniques used in this demo are documented at
|
||||||
|
### https://azure.microsoft.com/en-us/documentation/articles/powershell-azure-resource-manager/
|
||||||
|
|
||||||
|
### Import AzureRM.Profile.NetCore.Preview and AzureRM.Resources.NetCore.Preview modules.
|
||||||
|
### AzureRM.NetCore.Preview is a wrapper module that pulls in these modules
|
||||||
|
###
|
||||||
|
### Because of issue https://github.com/PowerShell/PowerShell/issues/1618,
|
||||||
|
### currently you will not be able to use "Install-Module AzureRM.NetCore.Preview" from
|
||||||
|
### PowerShellGallery. You can use the following workaround until the issue is fixed:
|
||||||
|
###
|
||||||
|
### Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2 -ProviderName NuGet -ExcludeVersion -Destination <Folder you want this to be installed>
|
||||||
|
###
|
||||||
|
### Ensure $ENV:PSMODULEPATH is updated with the location you used to install.
|
||||||
|
Import-Module AzureRM.NetCore.Preview
|
||||||
|
|
||||||
|
### Supply your Azure Credentials
|
||||||
|
Login-AzureRMAccount
|
||||||
|
|
||||||
|
### Get a name for Azure Resource Group
|
||||||
|
$resourceGroupName = "PSAzDemo" + (new-guid | % guid) -replace "-",""
|
||||||
|
$resourceGroupName
|
||||||
|
|
||||||
|
### Creating a New Azure Resource Group
|
||||||
|
New-AzureRMResourceGroup -Name $resourceGroupName -Location "West US"
|
||||||
|
|
||||||
|
### Deploy an Ubuntu 14.04 VM using Resource Manager cmdlets
|
||||||
|
### Template is available is at
|
||||||
|
### http://armviz.io/#/?load=https:%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-vm-simple-linux%2Fazuredeploy.json
|
||||||
|
$dnsLabelPrefix = $resourceGroupName | % tolower
|
||||||
|
$dnsLabelPrefix
|
||||||
|
$password = Convertto-Securestring -String "PowerShellRocks!" -AsPlainText -Force
|
||||||
|
New-AzureRMResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile ./Compute-Linux.json -adminUserName psuser -adminPassword $password -dnsLabelPrefix $dnsLabelPrefix
|
||||||
|
|
||||||
|
### Monitor the status of the deployment
|
||||||
|
Get-AzureRMResourceGroupDeployment -ResourceGroupName $resourceGroupName
|
||||||
|
|
||||||
|
### Discover the resources we created by the previous deployment
|
||||||
|
Find-AzureRMResource -ResourceGroupName $resourceGroupName | select Name,ResourceType,Location
|
||||||
|
|
||||||
|
### Get the state of the VM we created
|
||||||
|
### Notice: The VM is in running state
|
||||||
|
Get-AzureRMResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName -ODataQuery '$expand=instanceView' | % properties | % instanceview | % statuses
|
||||||
|
|
||||||
|
### Discover the Operations we can perform on the compute resource
|
||||||
|
### Notice: Operations like "Power Off Virtual Machine", "Start Virtual Machine", "Create Snapshot", "Delete Snapshot", "Delete Virtual Machine"
|
||||||
|
Get-AzureRMProviderOperation -OperationSearchString Microsoft.Compute/* | select OperationName,Operation
|
||||||
|
|
||||||
|
### Power Off the Virtual Machine we created
|
||||||
|
Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Compute/virtualMachines -ResourceName MyUbuntuVM -Action poweroff
|
||||||
|
|
||||||
|
### Check the VM State again. It should be stopped now.
|
||||||
|
Get-AzureRMResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName -ODataQuery '$expand=instanceView' | % properties | % instanceview | % statuses
|
||||||
|
|
||||||
|
### As you know, you may still be incurring charges even if the VM is in stopped state
|
||||||
|
### Deallocate the resource to avoid this charge
|
||||||
|
Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Compute/virtualMachines -ResourceName MyUbuntuVM -Action deallocate
|
||||||
|
|
||||||
|
### The following command removes the Virtual Machine
|
||||||
|
Remove-AzureRmResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName
|
||||||
|
|
||||||
|
### Look at the resources that still exists
|
||||||
|
Find-AzureRMResource -ResourceGroupName $resourceGroupName | select Name,ResourceType,Location
|
||||||
|
|
||||||
|
### Remove the ResourceGroup which removes all the resources in the ResourceGroup
|
||||||
|
Remove-AzureRmResourceGroup -Name $resourceGroupName
|
200
demos/Azure/Compute-Linux.json
Normal file
200
demos/Azure/Compute-Linux.json
Normal file
|
@ -0,0 +1,200 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
|
||||||
|
"contentVersion": "1.0.0.0",
|
||||||
|
"parameters": {
|
||||||
|
"adminUsername": {
|
||||||
|
"type": "string",
|
||||||
|
"metadata": {
|
||||||
|
"description": "User name for the Virtual Machine."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"adminPassword": {
|
||||||
|
"type": "securestring",
|
||||||
|
"metadata": {
|
||||||
|
"description": "Password for the Virtual Machine."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dnsLabelPrefix": {
|
||||||
|
"type": "string",
|
||||||
|
"metadata": {
|
||||||
|
"description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ubuntuOSVersion": {
|
||||||
|
"type": "string",
|
||||||
|
"defaultValue": "14.04.2-LTS",
|
||||||
|
"allowedValues": [
|
||||||
|
"12.04.5-LTS",
|
||||||
|
"14.04.2-LTS",
|
||||||
|
"15.10",
|
||||||
|
"16.04.0-LTS"
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"description": "The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version. Allowed values: 12.04.5-LTS, 14.04.2-LTS, 15.10, 16.04.0-LTS."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"variables": {
|
||||||
|
"storageAccountName": "[concat(uniquestring(resourceGroup().id), 'salinuxvm')]",
|
||||||
|
"dataDisk1VhdName": "datadisk1",
|
||||||
|
"imagePublisher": "Canonical",
|
||||||
|
"imageOffer": "UbuntuServer",
|
||||||
|
"OSDiskName": "osdiskforlinuxsimple",
|
||||||
|
"nicName": "myVMNic",
|
||||||
|
"addressPrefix": "10.0.0.0/16",
|
||||||
|
"subnetName": "Subnet",
|
||||||
|
"subnetPrefix": "10.0.0.0/24",
|
||||||
|
"storageAccountType": "Standard_LRS",
|
||||||
|
"publicIPAddressName": "myPublicIP",
|
||||||
|
"publicIPAddressType": "Dynamic",
|
||||||
|
"vmStorageAccountContainerName": "vhds",
|
||||||
|
"vmName": "MyUbuntuVM",
|
||||||
|
"vmSize": "Standard_D1",
|
||||||
|
"virtualNetworkName": "MyVNET",
|
||||||
|
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]",
|
||||||
|
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
|
||||||
|
"apiVersion": "2015-06-15"
|
||||||
|
},
|
||||||
|
"resources": [
|
||||||
|
{
|
||||||
|
"type": "Microsoft.Storage/storageAccounts",
|
||||||
|
"name": "[variables('storageAccountName')]",
|
||||||
|
"apiVersion": "2016-01-01",
|
||||||
|
"location": "[resourceGroup().location]",
|
||||||
|
"sku": {
|
||||||
|
"name": "[variables('storageAccountType')]"
|
||||||
|
},
|
||||||
|
"kind": "Storage",
|
||||||
|
"properties": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"apiVersion": "[variables('apiVersion')]",
|
||||||
|
"type": "Microsoft.Network/publicIPAddresses",
|
||||||
|
"name": "[variables('publicIPAddressName')]",
|
||||||
|
"location": "[resourceGroup().location]",
|
||||||
|
"properties": {
|
||||||
|
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
|
||||||
|
"dnsSettings": {
|
||||||
|
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"apiVersion": "[variables('apiVersion')]",
|
||||||
|
"type": "Microsoft.Network/virtualNetworks",
|
||||||
|
"name": "[variables('virtualNetworkName')]",
|
||||||
|
"location": "[resourceGroup().location]",
|
||||||
|
"properties": {
|
||||||
|
"addressSpace": {
|
||||||
|
"addressPrefixes": [
|
||||||
|
"[variables('addressPrefix')]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"subnets": [
|
||||||
|
{
|
||||||
|
"name": "[variables('subnetName')]",
|
||||||
|
"properties": {
|
||||||
|
"addressPrefix": "[variables('subnetPrefix')]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"apiVersion": "[variables('apiVersion')]",
|
||||||
|
"type": "Microsoft.Network/networkInterfaces",
|
||||||
|
"name": "[variables('nicName')]",
|
||||||
|
"location": "[resourceGroup().location]",
|
||||||
|
"dependsOn": [
|
||||||
|
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
|
||||||
|
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"ipConfigurations": [
|
||||||
|
{
|
||||||
|
"name": "ipconfig1",
|
||||||
|
"properties": {
|
||||||
|
"privateIPAllocationMethod": "Dynamic",
|
||||||
|
"publicIPAddress": {
|
||||||
|
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
|
||||||
|
},
|
||||||
|
"subnet": {
|
||||||
|
"id": "[variables('subnetRef')]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"apiVersion": "[variables('apiVersion')]",
|
||||||
|
"type": "Microsoft.Compute/virtualMachines",
|
||||||
|
"name": "[variables('vmName')]",
|
||||||
|
"location": "[resourceGroup().location]",
|
||||||
|
"dependsOn": [
|
||||||
|
"[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
|
||||||
|
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"hardwareProfile": {
|
||||||
|
"vmSize": "[variables('vmSize')]"
|
||||||
|
},
|
||||||
|
"osProfile": {
|
||||||
|
"computerName": "[variables('vmName')]",
|
||||||
|
"adminUsername": "[parameters('adminUsername')]",
|
||||||
|
"adminPassword": "[parameters('adminPassword')]"
|
||||||
|
},
|
||||||
|
"storageProfile": {
|
||||||
|
"imageReference": {
|
||||||
|
"publisher": "[variables('imagePublisher')]",
|
||||||
|
"offer": "[variables('imageOffer')]",
|
||||||
|
"sku": "[parameters('ubuntuOSVersion')]",
|
||||||
|
"version": "latest"
|
||||||
|
},
|
||||||
|
"osDisk": {
|
||||||
|
"name": "osdisk",
|
||||||
|
"vhd": {
|
||||||
|
"uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), variables('apiVersion')).primaryEndpoints.blob, variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]"
|
||||||
|
},
|
||||||
|
"caching": "ReadWrite",
|
||||||
|
"createOption": "FromImage"
|
||||||
|
},
|
||||||
|
"dataDisks": [
|
||||||
|
{
|
||||||
|
"name": "datadisk1",
|
||||||
|
"diskSizeGB": "100",
|
||||||
|
"lun": 0,
|
||||||
|
"vhd": {
|
||||||
|
"uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), variables('apiVersion')).primaryEndpoints.blob, variables('vmStorageAccountContainerName'),'/',variables('dataDisk1VhdName'),'.vhd')]"
|
||||||
|
},
|
||||||
|
"createOption": "Empty"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"networkProfile": {
|
||||||
|
"networkInterfaces": [
|
||||||
|
{
|
||||||
|
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"diagnosticsProfile": {
|
||||||
|
"bootDiagnostics": {
|
||||||
|
"enabled": "true",
|
||||||
|
"storageUri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), variables('apiVersion')).primaryEndpoints.blob)]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": {
|
||||||
|
"hostname": {
|
||||||
|
"type": "string",
|
||||||
|
"value": "[concat(parameters('dnsLabelPrefix'), '.', resourceGroup().location, '.cloudapp.azure.com')]"
|
||||||
|
},
|
||||||
|
"sshCommand": {
|
||||||
|
"type": "string",
|
||||||
|
"value": "[concat('ssh ', parameters('adminUsername'), '@', parameters('dnsLabelPrefix'), '.', resourceGroup().location, '.cloudapp.azure.com')]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
demos/Azure/readme.md
Normal file
11
demos/Azure/readme.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
## Demo: Managing Azure using PowerShell
|
||||||
|
|
||||||
|
This demo (Azure-Demo.ps1) shows management of Azure Compute resource using Azure Resource Management (ARM) cmdlets.
|
||||||
|
|
||||||
|
## Prerequisites ##
|
||||||
|
- Install PowerShell 6.0.0-alpha.9
|
||||||
|
- Install AzureRM.NetCore.Preview, AzureRM.Profile.NetCore.Preview and AzureRM.Resources.NetCore.Preview modules to a local directory.
|
||||||
|
- The instructions for downloading these modules are in Azure-Demo.ps1 file.
|
||||||
|
- You have to use the command "Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2 -ProviderName NuGet -ExcludeVersion -Destination <Local Directory>"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue