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

New-AzRemediationTasks failes when the -WhatIf option is used #817

Open
edr-vlk opened this issue Nov 7, 2024 · 3 comments
Open

New-AzRemediationTasks failes when the -WhatIf option is used #817

edr-vlk opened this issue Nov 7, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@edr-vlk
Copy link

edr-vlk commented Nov 7, 2024

Describe the bug
The cmdlet New-AzRemediationTasks failes when the -WhatIf option is used

To Reproduce
I did try to execute the following statement in pwsh:
New-AzRemediationTasks -PacEnvironmentSelector ${pacEnvironmentSelector} -DefinitionsRootFolder $PAC_DEFINITIONS_FOLDER -OnlyCheckManagedAssignments -PolicyDefinitionFilter $PolicyDefinition -WhatIf

Expected behavior
As describe din the documentation, but not failing the request

Output

Retrieve Policy Compliance List

Az Graph Query: 'policyresources | where type == "microsoft.policyinsights/policystates" and properties.complianceState == "NonCompliant" and (properties.policyDefinitionAction == "deployifnotexists" or properties.policyDefinitionAction == "modify")'
What if: Performing the operation "POST" on target "/providers/Microsoft.ResourceGraph/resources?api-version=2022-10-01".
Invoke-AzRestMethod: C:\Program Files\PowerShell\Modules\EnterprisePolicyAsCode\10.7.1\internal\functions\Search-AzGraphAllItems.ps1:33
Line |
33 | $response = Invoke-AzRestMethod -Method POST `
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Object reference not set to an instance of an object.
Write-Error: C:\Program Files\PowerShell\Modules\EnterprisePolicyAsCode\10.7.1\internal\functions\Find-AzNonCompliantResources.ps1:63
Line |
63 | … lt = @() + (Search-AzGraphAllItems -Query $query -ProgressItemName "P …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Search-AzGraph REST error for '' --

EPAC Version
Version of EPAC module you are using.
10.7.1

@edr-vlk edr-vlk added the bug Something isn't working label Nov 7, 2024
@apybar apybar self-assigned this Nov 7, 2024
@apybar
Copy link
Collaborator

apybar commented Nov 23, 2024

So looks like the WhatIf flag will prevent a POST from taking place - this is going to take rework to somehow not run the "WhatIf" until the end of the script. Either that or it may not be possible altogether.

I'll work with some of the internal team and discuss and comment when I have a solution.

@apybar
Copy link
Collaborator

apybar commented Nov 25, 2024

Will change the flag to something else and will behave as originally intended in which it will output to the CLI the remediation tasks that would take place if you were to run it without the flag.

Will link the release to this ticket and closed once its been released.

@apybar
Copy link
Collaborator

apybar commented Dec 6, 2024

Resolved issue by changing the flag to "TestRun"

This will be available in the next release and this ticket will be closed upon the release being published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants