Created
September 10, 2024 21:16
-
-
Save JustinGrote/b132f7eaf58a9491c11ea75033bba8f9 to your computer and use it in GitHub Desktop.
Create Azure Deploy Links and Buttons Easily
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
function New-AzureDeploy { | |
<# | |
.SYNOPSIS | |
Creates an Azure Deploy Button link for a given ARM template. | |
#> | |
param( | |
#Path to the ARM json template file that is publicly hosted and accessible. This cannot be a bicep template. | |
[string]$Uri, | |
#Path to a UI Definition JSON file. https://aka.ms/masandbox to create one. | |
[string]$FormDefinitionUri | |
) | |
$Uri, $FormDefinitionUri | Foreach-Object { | |
if ($Uri.EndsWith('.bicep')) { | |
Write-Warning 'Bicep templates are not supported. Please provide a link to an ARM template.' | |
} | |
if (-not $Uri.EndsWith('.json')) { | |
Write-Warning "The provided Uri does not end with '.json'. You should be pointing to a valid ARM template. You can disregard if you are using a custom redirect link" | |
} | |
} | |
$uriEncoded = [Web.HttpUtility]::UrlEncode($Uri) | |
if ($FormDefinitionUri) { | |
$FormDefinitionUriEncoded = [Web.HttpUtility]::UrlEncode($FormDefinitionUri) | |
} | |
$deploymentUri = "https://portal.azure.com/#create/Microsoft.Template/uri/$uriEncoded" | |
if ($FormDefinitionUriEncoded) { | |
$deploymentUri += "/createUIDefinitionUri/$FormDefinitionUriEncoded" | |
} | |
$deploymentStackUri = "https://portal.azure.com/#view/Microsoft_Azure_CreateUIDef/DeploymentStackBlade/uri/$uriEncoded" | |
if ($FormDefinitionUriEncoded) { | |
$deploymentStackUri += "/createUIDefinitionUri/$FormDefinitionUriEncoded" | |
} | |
[PSCustomObject]@{ | |
DeploymentUri = $deploymentUri | |
DeploymentButtonMarkdown = "![Deploy to Azure](https://aka.ms/deploytoazurebutton)($deploymentUri)" | |
DeploymentButtonHtml = "<a href='$deploymentUri' target='_blank'><img src='https://aka.ms/deploytoazurebutton' alt='Deploy to Azure' /></a>" | |
DeploymentStackUri = $deploymentStackUri | |
DeploymentStackButtonMarkdown = "![Deploy to Azure](https://aka.ms/deploytoazurebutton)($deploymentStackUri)" | |
DeploymentStackButtonHtml = "<a href='$deploymentStackUri' target='_blank'><img src='https://aka.ms/deploytoazurebutton' alt='Deploy to Azure' /></a>" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment