Skip to content

Commit

Permalink
Deployment Script files
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthebrit committed May 26, 2021
1 parent a01f3b3 commit 097e3be
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions Bicep/bicepdemo.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See bicepdemo.ps1 in the Azure Master Class repo Part11IacandDevOps\Bicep
8 changes: 8 additions & 0 deletions DeploymentScripts/demoscript.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bicep -v

#RG-SCUSA is the RG of the MI am referencing
New-AzResourceGroupDeployment -TemplateFile "deployscript.bicep" -ResourceGroupName RG-BicepDemo

New-AzResourceGroupDeployment -TemplateFile "deployscript.bicep" -ResourceGroupName RG-BicepDemo -storageAccountName "sascussavilltech2"

bicep build "deploymentscript.bicep" #if wanted ARM file :-)
40 changes: 40 additions & 0 deletions DeploymentScripts/deployscript.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
param location string = resourceGroup().location
param subId string = subscription().subscriptionId // current sub
param usmiRG string = 'RG-SCUSA'
param uamiName string = 'mi-savilltech1'
param currentTime string = utcNow()
param storageAccountName string = 'sascussavilltech'

resource mngId 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' existing = {
name: 'mi-savilltech1'
scope: resourceGroup(subId,usmiRG) //if MI in different RG than template deployment target RG
}

resource dScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'scriptTest'
location: location
kind: 'AzurePowerShell'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${mngId.id}': {}
}
}
properties: {
azPowerShellVersion: '5.0'
scriptContent: '''
Param([string] $StorageAccountName)
Connect-AzAccount -Identity
$DeploymentScriptOutputs["output"] = New-AzStorageContext -UseConnectedAccount -StorageAccountName $StorageAccountName `
| Get-AzStorageBlob -Container 'images' -Blob * | Out-String
'''
arguments: concat('-StorageAccountName', ' ', storageAccountName)
cleanupPreference: 'OnSuccess' //when to cleanup the storage account and ACI instance or OnExpiration, Always
retentionInterval: 'PT4H' //keep the deployment script resource for this duration (ISO 8601 format) and ACI/SA if OnExpiration cleanuppreference
forceUpdateTag: currentTime // ensures script runs every time
}
}

// print logs from script after template is finished deploying
output scriptOutput string = dScript.properties.outputs.output
//output scriptLogs string = reference('${dScript.id}/logs/default', dScript.apiVersion, 'Full').properties.log
23 changes: 23 additions & 0 deletions PowerShellStuff/AzDiskList.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$subID = 'SubID'
$token = Get-AzAccessToken
$authHeader = @{
'Content-Type'='application/json'
'Authorization'='Bearer ' + $token.Token
}
$r = Invoke-WebRequest -Uri "https://management.azure.com/subscriptions/$subID/providers/Microsoft.Compute/skus?api-version=2019-04-01" -Method Get -Headers $authHeader

$rarray = $r.Content | ConvertFrom-Json # | ConvertTo-Json #Make it pretty

foreach ($item in $rarray.value) {
write-debug $item
if($item.resourceType -eq 'disks')
{
$MaxSize = 0
foreach ($attr in $item.capabilities) {
if($attr.name -eq 'MaxSizeGiB') {
$MaxSize = $attr.value
}
}
write-output "$($item.name) - $($item.size) - $MaxSize"
}
}

0 comments on commit 097e3be

Please sign in to comment.