From 19a6685518afddd93371df81e3ae4860915f16e3 Mon Sep 17 00:00:00 2001 From: Gordon Byers Date: Fri, 9 Jul 2021 12:34:47 +0000 Subject: [PATCH 1/3] WhatIf now Outputs JSON --- .../functions/Set-AzOpsWhatIfOutput.ps1 | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/internal/functions/Set-AzOpsWhatIfOutput.ps1 diff --git a/src/internal/functions/Set-AzOpsWhatIfOutput.ps1 b/src/internal/functions/Set-AzOpsWhatIfOutput.ps1 new file mode 100644 index 00000000..719c7f1a --- /dev/null +++ b/src/internal/functions/Set-AzOpsWhatIfOutput.ps1 @@ -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 + } + +} \ No newline at end of file From 4ea39b432a99e298eb74872b020bf1bb49cac66a Mon Sep 17 00:00:00 2001 From: Gordon Byers Date: Fri, 9 Jul 2021 12:35:23 +0000 Subject: [PATCH 2/3] WhatIf outputs Json --- .../functions/New-AzOpsDeployment.ps1 | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/internal/functions/New-AzOpsDeployment.ps1 b/src/internal/functions/New-AzOpsDeployment.ps1 index b0d3a5cd..89e03eb4 100644 --- a/src/internal/functions/New-AzOpsDeployment.ps1 +++ b/src/internal/functions/New-AzOpsDeployment.ps1 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 From 4fea20c40c3a7bb02c3ca911831d46fd53839993 Mon Sep 17 00:00:00 2001 From: Gordon Byers Date: Mon, 12 Jul 2021 12:41:52 +0100 Subject: [PATCH 3/3] Added loc for WhatIf message --- src/localized/en-us/Strings.psd1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/localized/en-us/Strings.psd1 b/src/localized/en-us/Strings.psd1 index 35805b2d..3cbd75d9 100644 --- a/src/localized/en-us/Strings.psd1 +++ b/src/localized/en-us/Strings.psd1 @@ -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 -} \ No newline at end of file + 'Set-AzOpsWhatIfOutput.WhatIfFile' = 'Creating WhatIf markdown and json files' # +}