Skip to content

Clu #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 5, 2016
Merged

Clu #296

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions examples/resource-management/02-Resource.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Param(
[string]$groupName,
[string]$location,
[string]$rName,
)

Write-Host "=== Managing Resources in Azure ==="

Write-Host "1. Creating a new resource group"
New-AzureRmResourceGroup -Name $groupName -Location $location
$destinationGroupName = $groupName + "Destination"

Write-Host "2. Registering Resource Provider Namespace."
$providerNamespace="Providers.Test"
Register-AzureRmResourceProvider -ProviderNamespace $providerNamespace -Force

Write-Host "3. Creating a new Resource"
$resourceType = $providerNamespace + "/statefulResources"
$apiversion="2014-04-01"
New-AzureRmResource -Name $rName -Location $location -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $groupName -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -ApiVersion $apiversion -Force

Write-Host "4. Get information about Resource"
$resourceInfo = Get-AzureRmResource -ResourceGroupName $groupName
Write-Host "Validating Resource name"
Assert-AreEqual $rName $resourceInfo.Name

Write-Host "5. Find Resource with name"
$foundResource = Find-AzureRmResource -ResourceType $resourceType -ResourceNameContains $rName
Write-Host "Validating Resource name"
Assert-AreEqual $rName $foundResource.Name

Write-Host "6. Update Resource"
Set-AzureRmResource -ResourceGroupName $groupName -ResourceName $rName -ResourceType $resourceType -Tags @{Name = "testtagUpdated"; Value = "testvalueUpdated"} -Force

Write-Host "7. Move Resource to resource group"
New-AzureRmResourceGroup -Name $destinationGroupName -Location $location
Move-AzureRmResource -DestinationResourceGroupName $destinationGroupName -ResourceId $resourceInfo.ResourceId -Force

Write-Host "8. Removing resource"
$foundResource = Find-AzureRmResource -ResourceType $resourceType -ResourceNameContains $rName
Remove-AzureRmResource -ResourceId $foundResource.ResourceId -Force
24 changes: 24 additions & 0 deletions examples/resource-management/03-Deployments.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Param(
[string]$groupName,
[string]$location
)

Write-Host "=== Provisioning Deployments in Azure ==="

Write-Host "1. Create a new resource group"
New-AzureRmResourceGroup -Name $groupName -Location $location

Write-Host "2. Test template"
$siteName = Get-ResourceName
$list = Test-AzureResourceGroupTemplate -ResourceGroupName $groupName -TemplateFile sampleTemplate.json -siteName $siteName -hostingPlanName $siteName -siteLocation $location -sku Free -workerSize 0
Write-Host $list
# Assert
Assert-AreEqual 0 @($list).Count

Write-Host "3. Provisioning Deployment"
$deployment = New-AzureRmResourceGroupDeployment -Name $siteName -ResourceGroupName $groupName -TemplateFile sampleTemplate.json -TemplateParameterFile sampleTemplateParams.json
Write-Host $deployment
# Assert
Assert-AreEqual Succeeded $deployment.ProvisioningState


17 changes: 17 additions & 0 deletions examples/resource-management/03-Deployments.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e
printf "\n=== Provisioning Deployments in Azure ===\n"

printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
azure group create --name "$groupName" --location "$location"

printf "\n2. Test template with dynamic parameters\n"
siteName=`randomName testrn`
azure group deployment test -g "$groupName" --templatefile $BASEDIR/resource-management/sampleTemplate.json --siteName "$siteName" --hostingPlanName "$siteName" --siteLocation "$location" --sku "Standard" --workerSize "0"

printf "\n3. Test template with JSON parameter object\n"
azure group deployment test -g "$groupName" --templatefile $BASEDIR/resource-management/sampleTemplate.json --templateparameterobject "{\"siteName\":\"$siteName\",\"hostingPlanName\":\"$siteName\",\"siteLocation\":\"$location\",\"sku\":\"Standard\",\"workerSize\": 0 }"

printf "\n4. Provisioning Deployment\n"
deploymentInfo=`azure group deployment create --Name "$siteName" --ResourceGroupName "$groupName" --TemplateFile $BASEDIR/resource-management/sampleTemplate.json --TemplateParameterFile $BASEDIR/resource-management/sampleTemplateParams.json`
echo $deploymentInfo
48 changes: 48 additions & 0 deletions examples/resource-management/sampleTemplate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"siteName": {
"type": "string"
},
"hostingPlanName": {
"type": "string"
},
"siteLocation": {
"type": "string"
},
"sku": {
"type": "string",
"allowedValues": [
"Free",
"Shared",
"Basic",
"Standard"
],
"defaultValue": "Free"
},
"workerSize": {
"type": "int",
"allowedValues": [
0,
1,
2
],
"defaultValue": 0
}
},
"resources": [
{
"apiVersion": "2014-04-01",
"name": "[parameters('hostingPlanName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[parameters('siteLocation')]",
"properties": {
"name": "[parameters('hostingPlanName')]",
"sku": "[parameters('sku')]",
"workerSize": "[parameters('workerSize')]",
"numberOfWorkers": 1
}
}
]
}
17 changes: 17 additions & 0 deletions examples/resource-management/sampleTemplateParams.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"siteName": {
"value": "hao"
},
"hostingPlanName": {
"value": "xDeploymentTestHost26668"
},
"siteLocation": {
"value": "West US"
},
"sku": {
"value": "Standard"
},
"workerSize": {
"value": 0
}
}
2 changes: 1 addition & 1 deletion src/CLU/Commands.Common.ScenarioTest/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Commands.Common.Authentication": "",
"Commands.ResourceManager.Common": "",
"Microsoft.Azure.Commands.Profile": "",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Commands.ResourceManager.Cmdlets/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"System.Threading": "4.0.11-beta-23516",
"System.Threading.Tasks": "4.0.11-beta-23516",
"System.Threading.Thread": "4.0.0-beta-23516",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
"Microsoft.Extensions.Caching.Memory": "1.0.0-rc1-final"
},
"compilationOptions": {"emitEntryPoint": true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"Commands.Common": "",
"Commands.Common.Authentication": "",
"Commands.ResourceManager.Common": "",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
Expand Down
6 changes: 3 additions & 3 deletions src/CLU/Microsoft.Azure.Commands.Network/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"Microsoft.CLU": "1.0.0",
"Commands.Common.Authentication": "",
"Commands.Common": "",
"Microsoft.Azure.Graph.RBAC": "2.1.0-preview",
"Microsoft.Azure.Management.Authorization": "2.1.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Azure.Graph.RBAC": "2.1.1-preview",
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
"Microsoft.Azure.Management.Network": "3.0.3-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.8.2",
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Microsoft.Azure.Commands.Profile.Test/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Commands.ResourceManager.Common": "",
"Commands.ScenarioTests.ResourceManager.Common": "",
"Microsoft.Azure.Commands.Profile": "",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Microsoft.Azure.Commands.Profile/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"Commands.Common": "",
"Commands.Common.Authentication": "",
"Commands.ResourceManager.Common": "",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Microsoft.Azure.Commands.Resources": "",
"Microsoft.Azure.Graph.RBAC": "2.1.1-preview",
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.Rest.Azure;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -328,7 +329,9 @@ private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParame
}
else
{
deployment.Properties.Template = DataStore.ReadFileAsText(parameters.TemplateFile);
var textData = DataStore.ReadFileAsText(parameters.TemplateFile);
deployment.Properties.Template = string.IsNullOrEmpty(textData) ?
(object)textData : JObject.Parse(DataStore.ReadFileAsText(parameters.TemplateFile));
}

if (Uri.IsWellFormedUriString(parameters.ParameterUri, UriKind.Absolute))
Expand All @@ -340,7 +343,9 @@ private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParame
}
else
{
deployment.Properties.Parameters = GetDeploymentParameters(parameters.TemplateParameterObject);
var deploymentParameters = GetDeploymentParameters(parameters.TemplateParameterObject);
deployment.Properties.Parameters = string.IsNullOrEmpty(deploymentParameters) ?
(object) deploymentParameters : JObject.Parse(deploymentParameters);
}

return deployment;
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Microsoft.Azure.Commands.Resources/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"Commands.ResourceManager.Cmdlets": "",
"Microsoft.Azure.Graph.RBAC": "2.1.1-preview",
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Microsoft.Azure.Commands.Profile": "",
"Microsoft.Azure.Commands.Websites": "",
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
"Microsoft.Azure.Management.Websites": "1.0.0-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.8.2",
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Microsoft.Azure.Commands.Websites/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"Microsoft.Azure.Commands.Profile": "",
"Microsoft.Azure.Graph.RBAC": "2.1.1-preview",
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
"Microsoft.Azure.Management.Websites": "1.0.0-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.8.2",
Expand Down