-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a01f3b3
commit 097e3be
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
See bicepdemo.ps1 in the Azure Master Class repo Part11IacandDevOps\Bicep |
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
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 :-) |
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
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 |
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
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" | ||
} | ||
} |