-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathARM - Resource Group.ps1
113 lines (60 loc) · 2.59 KB
/
ARM - Resource Group.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
## To Set Verbose output
$PSDefaultParameterValues['*:Verbose'] = $true
# Variables - Common
$location = "eastus2"
$tags = New-Object 'System.Collections.Generic.Dictionary[String,object]'
$tags.Add("environment", "Production") # Production, Staging, QA
$tags.Add("projectName", "Demo Project")
$tags.Add("projectVersion", "1.0.0")
$tags.Add("managedBy", "[email protected]")
$tags.Add("billTo", "Ashish Patel")
$tags.Add("tier", "Front End") # Front End, Back End, Data
$tags.Add("dataProfile", "Public") # Public, Confidential, Restricted, Internal
<# Resource Group #>
# Variables - Resource Group
$rgShortName = "qweasdzxc"
$rgSuffix = "-rg"
$rgName = "${rgShortName}${rgSuffix}"
<# Create Resource Group, if it does not exist #>
Get-AzureRmResourceGroup -Name $rgName -ErrorVariable isRGExist -ErrorAction SilentlyContinue `
If ($isRGExist)
{
Write-Output "Resource Group does not exist"
Write-Verbose "Creating new Resource Group: {$rgName}"
$rg = New-AzureRmResourceGroup `
-Name $rgName `
-Location $location `
-Tag $tags
}
Else
{
Write-Output "Resource Group exist"
Write-Verbose "Fetching Resource Group: {$rgName}"
$rg = Get-AzureRmResourceGroup -Name $rgName
}
Write-Verbose "Get list of Resource Groups"
Write-Output "Resource Groups"
Get-AzureRmResourceGroup `
| Select-Object ResourceGroupName, Location `
| Format-Table -AutoSize -Wrap -GroupBy Location
<#
## Remove Resource Group
$rgShortName = "qweasdzxc"
$rgSuffix = "-rg"
$rgName = "${rgShortName}${rgSuffix}"
Write-Verbose "Delete Resource Group: {$rgName}"
Remove-AzureRmResourceGroup -Name $rgName -Force
#>
<#
## References
https://docs.microsoft.com/en-us/powershell/module/azurerm.resources/new-azurermresourcegroup?view=azurermps-6.13.0
https://docs.microsoft.com/en-us/powershell/module/azurerm.resources/get-azurermresourcegroup?view=azurermps-6.13.0
https://docs.microsoft.com/en-us/powershell/module/azurerm.resources/remove-azurermresourcegroup?view=azurermps-6.13.0
# Naming Conventions
https://docs.microsoft.com/en-us/azure/architecture/best-practices/naming-conventions
# Format table
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/format-table?view=powershell-6
# PowerShell style guide
https://github.com/PoshCode/PowerShellPracticeAndStyle
https://poshcode.gitbooks.io/powershell-practice-and-style/Style-Guide/Introduction.html
#>