Last active
September 12, 2020 20:48
-
-
Save brucedkyle/79cf8530d8cd0456a0158083d08a93b7 to your computer and use it in GitHub Desktop.
Resource Group Lifecycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Connect-AzAccount | |
# You may have more than one subscription. | |
$SUBSCRIPTION_ID= Read-Host -p "Enter your subscription id" | |
Select-AzSubscription -Subscription $SUBSCRIPTION_ID | |
# Set environment variables | |
$LOCATION = Read-Host -p "Enter your region, such as WestUS " | |
$RESOURCE_GROUP_NAME = Read-Host -p "Enter your resource group name " | |
$RESOURCE_NAME = Read-Host -p "Enter the name for your app service plan " | |
$TAGS = @{"Environment"="dev"; "Location"=$Location; "Cost Center"="111222"} | |
# create a resource group | |
New-AzResourceGroup -Name $RESOURCE_GROUP_NAME -Location $LOCATION ` | |
-Tag $TAGS | |
# Create a resource, in this case an App Service Plan | |
New-AzAppServicePlan -Name $RESOURCE_NAME ` | |
-Location $LOCATION -ResourceGroupName $RESOURCE_GROUP_NAME ` | |
-Tag $TAGS | |
# Get the resource as a PowerShell object | |
$plan = Get-AzAppServicePlan -Name $RESOURCE_NAME -ResourceGroupName $RESOURCE_GROUP_NAME | |
Write-Host $plan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
az login | |
# set environment variables | |
read -p "Enter your subscription id: " SUBSCRIPTION_ID | |
read -p "Enter your region, such as WestUS (no spaces): " LOCATION | |
read -p "Enter your resource group name, such as 'rg-wus-testme-01': " RESOURCE_GROUP_NAME | |
read -p "Enter the name for your app service plan, such as 'plan-wus-testme-01': " RESOURCE_NAME | |
# sets the default subsciption | |
az account set $SUBSCRIPTION_ID | |
TAGS=("Cost Center = 111222" "Location=West US") | |
az group create --name $RESOURCE_GROUP_NAME --location $LOCATION --tags "${TAGS[@]}" | |
az appservice plan create --name $RESOURCE_NAME --resource-group $RESOURCE_GROUP_NAME --tags "${TAGS[@]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
az group delete --name $RESOURCE_GROUP_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Remove-AzResourceGroup -Name $RESOURCE_GROUP_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TAG="Cost Center='Account-56'" | |
az group update --name $RESOURCE_GROUP_NAME --set tags."$TAG" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment