Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a PowerShell script to delete an entire spoke deployment #158

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e3217f1
Add TODO comments for DNS zones
SvenAelterman Dec 26, 2024
07c2bce
Update output and comments
SvenAelterman Dec 27, 2024
a1319b7
Initial working version of Remove-Spoke script
SvenAelterman Dec 27, 2024
f4e0470
Wait for resource group delete jobs to finish
SvenAelterman Dec 27, 2024
57f11d4
Remove the disconnected peering on the research hub network
SvenAelterman Dec 27, 2024
ddf95de
Add TenantId parameter and use it to prevent warnings about other ten…
SvenAelterman Dec 27, 2024
71b1698
Perform error handling
SvenAelterman Dec 27, 2024
025c113
Ask for confirmation before deleting
SvenAelterman Dec 27, 2024
111f8b0
Use Invoke-AzRestMethod
SvenAelterman Dec 27, 2024
f815f4d
Fix REST method parameters for DELETE operation
SvenAelterman Dec 27, 2024
48c03de
Update required modules
SvenAelterman Dec 27, 2024
858e127
Prevent resource lock deletes from showing output
SvenAelterman Dec 27, 2024
95ec989
Update comment-based help
SvenAelterman Dec 27, 2024
111c85d
Add PowerShell module docs generated by platyPS
SvenAelterman Dec 27, 2024
51069cc
Update metadata and inline documentation
SvenAelterman Dec 27, 2024
307a90d
Add PSDocs template and auto-generated doc for research spoke template
SvenAelterman Dec 27, 2024
9c1d437
Experimental: wrapper code to generate PS and ARM template docs
SvenAelterman Dec 27, 2024
add27f5
Bug fix in document generation for PS parameters
SvenAelterman Dec 28, 2024
a085269
Bug fixes and enhancements for default value determination in ARM docs
SvenAelterman Dec 28, 2024
f8fd646
Ensure links to params work in generated documentation.
SvenAelterman Jan 6, 2025
5feaa68
Fix typo in description
SvenAelterman Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions research-spoke/ResearchSpoke.Doc.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<#
.SYNOPSIS
A function to break out parameters from an ARM template.
#>
function global:GetTemplateParameter {
param (
[Parameter(Mandatory = $True)]
[String]$Path
)
process {
$template = Get-Content $Path | ConvertFrom-Json;
foreach ($property in $template.parameters.PSObject.Properties) {
[PSCustomObject]@{
Name = $property.Name
Description = $property.Value.metadata.description
Type = $property.Value.type
Required = !("defaultValue" -in $property.Value.PSObject.Properties.Name -or $property.Value.nullable)
DefaultValue = if ("defaultValue" -in $property.Value.PSObject.Properties.Name) {
if ($property.Value.defaultValue) { $property.Value.defaultValue } else {
switch ($property.Value.type) {
'string' { '''''' }
'object' { '{ }' }
'array' { '()' }
'bool' { 'false' }
'securestring' { '''''' }
}
}
}
AllowedValues = if ($property.Value.allowedValues) {
"``$($property.Value.allowedValues -join '`, `')``"
}
MinLength = $property.Value.minLength
MaxLength = $property.Value.maxLength
}
}
}
}

<#
.SYNOPSIS
A function to import metadata from the ARM template file.
#>
function global:GetTemplateMetadata {
param (
[Parameter(Mandatory = $True)]
[String]$Path
)
process {
$template = Get-Content $Path | ConvertFrom-Json;
return $template.metadata;
}
}

<#
.SYNOPSIS
A function to import outputs from the ARM template file.
#>
function global:GetTemplateOutput {
param (
[Parameter(Mandatory = $True)]
[String]$Path
)
process {
$template = Get-Content $Path | ConvertFrom-Json;
foreach ($property in $template.outputs.PSObject.Properties) {
[PSCustomObject]@{
Name = $property.Name
Description = $property.Value.metadata.description
Type = $property.Value.type
}
}
}
}

Document Research-Spoke {
# Read the ARM template file
$metadata = GetTemplateMetadata -Path $PSScriptRoot/main.json;
$parameters = GetTemplateParameter -Path $PSScriptRoot/main.json;
$outputs = global:GetTemplateOutput -Path $PSScriptRoot/main.json;

Title $metadata.name

$metadata.description

Section 'Table of Contents' {
"[Parameters](#parameters)"
"[Outputs](#outputs)"
"[Use the template](#use-the-template)"
}

# Add each parameter to a table
Section 'Parameters' {
$parameters | Table -Property @{ Name = 'Parameter name'; Expression = { "[$($_.Name)](#$($_.Name.ToLower()))" } }, Required, Description

$parameters | ForEach-Object {
Section $_.Name {
if ($_.Required) {
"![Parameter Setting](https://img.shields.io/badge/parameter-required-orange?style=flat-square)"
}
else {
"![Parameter Setting](https://img.shields.io/badge/parameter-optional-green?style=flat-square)"
}
$_.Description

$Details = "Metadata | Value`n---- | ----`nType | $($_.Type)"
if ($_.DefaultValue) {
$Details += "`nDefault value | ``$($_.DefaultValue)``"
}
if ($_.AllowedValues) {
$Details += "`nAllowed values | $($_.AllowedValues)"
}
if ($_.MinLength) {
$Details += "`nMinimum length | $($_.MinLength)"
}
if ($_.MaxLength) {
$Details += "`nMaximum length | $($_.MaxLength)"
}
$Details
}
}
}

# Add outputs
Section 'Outputs' {
$outputs | Table -Property Name, Type, Description
}

# Add sample
Section 'Use the template' {
Section 'PowerShell' {
'`./deploy.ps1 -TemplateParameterFile ''./main.prj.bicepparam'' -TargetSubscriptionId ''00000000-0000-0000-0000-000000000000'' -Location ''eastus''`'
}
}
}
5 changes: 2 additions & 3 deletions research-spoke/deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
./deploy.ps1 '.\main.prj.bicepparam' '00000000-0000-0000-0000-000000000000' 'eastus'
#>

# LATER: Be more specific about the required modules; it will speed up the initial call
#Requires -Modules "Az"
#Requires -Modules Az.Resources
#Requires -PSEdition Core

[CmdletBinding()]
Expand Down Expand Up @@ -86,7 +85,7 @@ $DeploymentResult = New-AzDeployment @CmdLetParameters
if ($DeploymentResult.ProvisioningState -eq 'Succeeded') {
Write-Host "🔥 Deployment succeeded."

if($DeleteJsonParameterFileAfterDeployment) {
if ($DeleteJsonParameterFileAfterDeployment) {
Write-Verbose "Deleting template parameter JSON file '$TemplateParameterJsonFile'."
Remove-Item -Path $TemplateParameterJsonFile -Force
}
Expand Down
Loading
Loading