Skip to content

Commit 8ae3c77

Browse files
committed
Merge pull request Azure#1473 from stankovski/clu
added bash and posh examples for resource group management
2 parents 42fa8a9 + 8582ae1 commit 8ae3c77

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

examples/lib/helper.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
randomName() {
2+
echo "$1$RANDOM"
3+
}
4+
5+
export -f randomName

examples/lib/setup.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# Login
4+
echo "Executing Login..."
5+
export CmdletSessionId=1010
6+
azure account add --username $azureuser --password $azurepassword

examples/lib/testrunner.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
. setup.sh
3+
. helper.sh
4+
export resourceGroupName=`randomName testrg`
5+
export resourceGroupLocation="westus"
6+
7+
for d in $( ls .. --ignore=lib ); do
8+
for f in $( ls ../$d/*.sh ); do
9+
echo "running: $f"
10+
. $f
11+
done
12+
done
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Param(
2+
[string]$resourceGroupName,
3+
[string]$resourceGroupLocation
4+
)
5+
6+
Write-Host "=== Managing Resource Groups in Azure ==="
7+
8+
Write-Host "1. Create a new resource group"
9+
New-AzureRmResourceGroup -Name $resourceGroupName -Location $resourceGroupLocation
10+
11+
Write-Host "2. Update group tags"
12+
Set-AzureRmResourceGroup -Name $resourceGroupName -Tags @{Name = "testtag"; Value = "testval"}
13+
14+
Write-Host "3. Get information about resource group"
15+
$resourceGroup = Get-AzureRmResourceGroup -Name $resourceGroupName
16+
Write-Host $resourceGroup
17+
18+
Write-Host "4. List all resource groups in the subscription"
19+
Get-AzureRmResourceGroup
20+
21+
Write-Host "5. Remove resource group"
22+
Remove-AzureRmResourceGroup -Name $resourceGroupName -Force
23+
24+
Write-Host "6. Validations"
25+
Assert-AreEqual $resourceGroup.ResourceGroupName $resourceGroupName
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
printf "\n=== Managing Resource Groups in Azure ===\n"
4+
5+
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$resourceGroupName" "$resourceGroupLocation"
6+
azure resource group new --name "$resourceGroupName" --location "$resourceGroupLocation"
7+
8+
printf "\n2. Updating the group %s with tags.\n" "$resourceGroupName"
9+
azure resource group set --name "$resourceGroupName" --tags "[{\"Value\":\"testval\",\"Name\":\"testtag\"}]"
10+
11+
printf "\n3. Get information about resource group : %s.\n" "$resourceGroupName"
12+
resourceGroupInfo=`azure resource group get --name $resourceGroupName`
13+
printf "\nThe resource group info is: \n %s\n" "$resourceGroupInfo"
14+
15+
printf "\n4. Listing all resource groups in the subscription.\n"
16+
azure resource group get
17+
18+
printf "\n5. Removing resource group: %s.\n" "$resourceGroupName"
19+
azure resource group remove --name "$resourceGroupName" --force

0 commit comments

Comments
 (0)