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

What-If to output raw Json #381

Merged
merged 3 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 7 additions & 12 deletions src/internal/functions/New-AzOpsDeployment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@
return
}
else {
Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject
Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfFile' -Target $scopeObject
$output = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, ($results.Changes | ConvertTo-Json -Depth 5)
Set-Content -Path '/tmp/OUTPUT.md' -Value $output -WhatIf:$false
Write-PSFMessage -Level Verbose -String 'Set-AzOpsWhatIfOutput.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject
Write-PSFMessage -Level Verbose -String 'Set-AzOpsWhatIfOutput.WhatIfFile' -Target $scopeObject
Set-AzOpsWhatIfOutput -results $results
}

$parameters.Name = $DeploymentName
Expand Down Expand Up @@ -148,8 +147,7 @@
else {
Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject
Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfFile' -Target $scopeObject
$output = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, ($results.Changes | ConvertTo-Json -Depth 5)
Set-Content -Path '/tmp/OUTPUT.md' -Value $output -WhatIf:$false
Set-AzOpsWhatIfOutput -results $results
}

$parameters.Name = $DeploymentName
Expand Down Expand Up @@ -197,8 +195,7 @@
else {
Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject
Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfFile' -Target $scopeObject
$output = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, ($results.Changes | ConvertTo-Json -Depth 5)
Set-Content -Path '/tmp/OUTPUT.md' -Value $output -WhatIf:$false
Set-AzOpsWhatIfOutput -results $results
}

$parameters.Name = $DeploymentName
Expand Down Expand Up @@ -242,8 +239,7 @@
else {
Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject
Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfFile' -Target $scopeObject
$output = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, ($results.Changes | ConvertTo-Json -Depth 5)
Set-Content -Path '/tmp/OUTPUT.md' -Value $output -WhatIf:$false
Set-AzOpsWhatIfOutput -results $results
}

$parameters.Name = $DeploymentName
Expand Down Expand Up @@ -283,8 +279,7 @@
else {
Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject
Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfFile' -Target $scopeObject
$output = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, ($results.Changes | ConvertTo-Json -Depth 5)
Set-Content -Path '/tmp/OUTPUT.md' -Value $output -WhatIf:$false
Set-AzOpsWhatIfOutput -results $results
}

$parameters.Name = $DeploymentName
Expand Down
30 changes: 30 additions & 0 deletions src/internal/functions/Set-AzOpsWhatIfOutput.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function Set-AzOpsWhatIfOutput {

<#
.SYNOPSIS
Logs the output from a What-If deployment
.DESCRIPTION
Logs the output from a What-If deployment
.PARAMETER results
The WhatIf result from a deployment
.EXAMPLE
> et-WhatIfOutput -results $results
#>

[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
$results
)

process {
Write-PSFMessage -Level Verbose -String 'Set-AzOpsWhatIfOutput.WhatIfFile'

$resultJson=($results.Changes | ConvertTo-Json -Depth 5)
$mdOutput = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, $resultJson

Set-Content -Path '/tmp/OUTPUT.md' -Value $mdOutput -WhatIf:$false
Set-Content -Path '/tmp/OUTPUT.json' -Value $resultJson -WhatIf:$false
}

}
3 changes: 2 additions & 1 deletion src/localized/en-us/Strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,5 @@
'Save-AzOpsManagementGroupChildren.Subscription.NotFound' = 'Unable to locate subscription: {0} within AzOpsSubscriptions object' #child.Name

'Set-AzOpsContext.Change' = 'Changing active subscription from {0} to {1} ({2})' # $context.Subscription.Name, $ScopeObject.SubscriptionDisplayName, $ScopeObject.Subscription
}
'Set-AzOpsWhatIfOutput.WhatIfFile' = 'Creating WhatIf markdown and json files' #
}