Skip to content

Instantly share code, notes, and snippets.

View MertSenel's full-sized avatar

Mert Senel MertSenel

View GitHub Profile
#region Service Constants
$ProjectName = 'mert'
$Stage = 'dev'
$ServiceType = 'fnc'
#$Region = "wus"
$Regions = "wus", "aue" ,"neu"
foreach($Region in $Regions) {
# The rest of the Deployment code logic goes here.
}
param (
[Parameter()][switch]$WhatIf,
[Parameter()][switch]$Test,
[Parameter()][switch]$Force,
[Parameter()][securestring]$mySecretValue
)
$ARGS = @{
ResourceGroupName = $ResourceGroupName
TemplateFile = $TemplateFile
@MertSenel
MertSenel / Deploy-AzARMTemplate-region5.ps1
Created August 22, 2020 03:41
Deploy-AzARMTemplate-region5.ps1
#region Deployment ("Validate & Deploy" or "Forced" Deployment)
try {
$PromptForConfirmation = (($Force) ? $false : $true)
Write-Host "Deploying $Region"
$Deployment = New-AzResourceGroupDeployment @ARGS `
-Name "$(New-Guid)" `
-Confirm:$PromptForConfirmation `
-WhatIfResultFormat FullResourcePayloads
}
catch {
@MertSenel
MertSenel / Deploy-AzARMTemplate-region4.ps1
Created August 22, 2020 03:40
Deploy-AzARMTemplate-region4.ps1
#region Deployment Helpers
$ErrorActionPreference = "Stop"
if ($Test) {
Test-AzResourceGroupDeployment @ARGS
exit $LASTEXITCODE
}
if ($WhatIf) {
$WhatIfResult = Get-AzResourceGroupDeploymentWhatIfResult @ARGS `
-ResultFormat FullResourcePayloads
$WhatIfResult
@MertSenel
MertSenel / Deploy-AzARMTemplate-region3.ps1
Created August 22, 2020 03:38
Deploy-AzARMTemplate-region3.ps1
#region Service Constants
$ProjectName = 'mert'
$Stage = 'dev'
$ServiceType = 'fnc'
$Region = "wus"
#endregion
#region Service Curated Parameters
$ResourceGroupName = $ProjectName + $Stage + $ServiceType + $Region + '01'
$TemplateFile = "$ArmArtifactsPath\template.json"
@MertSenel
MertSenel / Deploy-AzARMTemplate-region2.ps1
Created August 22, 2020 03:37
Deploy-AzARMTemplate-region2.ps1
#region Connect to Correct Tenant and Subscription
$CurrentContext = Get-AzContext
#If there is no AzContext found connect to desired Subscription and Tenant
if (!$CurrentContext) {
Connect-AzAccount -Tenant $TenantId -Subscription $SubscriptionId -UseDeviceAuthentication
$CurrentContext = Get-AzContext
}
#If subscription ID doesnt match, call the Set-AzContext with
#SubscriptionId and TenantId to allow switch between tenants as well.
if ($CurrentContext.Subscription.Id -ne $SubscriptionId) {
@MertSenel
MertSenel / Deploy-AzARMTemplate-region1.ps1
Created August 22, 2020 03:36
Deploy-AzARMTemplate-region1.ps1
#Requires -Module @{ ModuleName = 'Az'; ModuleVersion = '4.2' }
[CmdletBinding()]
param (
[Parameter()][switch]$WhatIf,
[Parameter()][switch]$Test,
[Parameter()][switch]$Force
)
#region Configuration
#Deployment Assets Configuration
@MertSenel
MertSenel / Deploy-AzARMTemplate.ps1
Created August 22, 2020 03:35
A local development PowerShell script for making ARM template testing easier with the new WhatIf Operation
<#
.DESCRIPTION
Tests, Validates or Deploys Azure Resource Manager Template
.PARAMETER Test
Switch for only running the Offline Template Validation
.PARAMETER WhatIf
Switch for only running the What-If Validation, that simulates a deployment via the Azure ARM REST API
@MertSenel
MertSenel / sample-savings-vm-auto-start-stop.md
Created August 22, 2020 03:23
sample-savings-vm-auto-start-stop.md
Virtual Machine Daily Availability Requirement Automated Start Stop Solution Implemented Hours Saved Number of Hours Running/Month Monthly Total Hours Billed Savings
Always Running - 24 Hours None 0 720 720 0
Only Needed During WeekDays - 24 hours Stop on Friday UTC 08:00 and Start on Monday UTC 22:00 248 472 472 %34.5
Only Needed During Weekdays for 10 hours Monday to Friday --> Start at UTC 22:00 , Stop at UTC 08:00 472 248 248 %65.5
@MertSenel
MertSenel / sample-az-sub-structure.md
Created August 22, 2020 03:22
sample-az-sub-structure.md
Subscription No Subscription Name
1 IT Operations
2 Project 1 - Development
3 Project 1 - Test
4 Project 1- Staging
5 Project 1 - Production
6 Project 2 - Development
7 ....
8 ....