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

Error: Code=ResourceGroupNotFound in EnterprisePolicyOperations.ps1 #590

Open
RobGANA opened this issue May 22, 2024 · 4 comments
Open

Error: Code=ResourceGroupNotFound in EnterprisePolicyOperations.ps1 #590

RobGANA opened this issue May 22, 2024 · 4 comments

Comments

@RobGANA
Copy link

RobGANA commented May 22, 2024

$policy = New-AzResourceGroupDeployment -DeploymentName "EPDeployment" -ResourceGroupName $resourceGroup -TemplateFile $tmp.FullName

When running the CreateSubnetInjectionEnterprisePolicy.ps1 script, I got an error on line 32 stating the resource group wasn't found. After confirming I had input the correct name, I reviewed the code and found that the context appears to be incorrect. I believe the issue is that my default subscription is different than the one I'm running this script against, and the call to the New-AzResourceGroupDeployment commandlet on line 32 of this included script is running against the wrong subscription. To confirm this, I added Set-AzContext -Subscription $subscriptionId just before line 32, added $subscriptionId as an additional parameter to this function, and changed line 86 of CreateSubnetInjectionEnterprisePolicy.ps1 to $result = PutEnterprisePolicy $subscriptionId $resourceGroup $body. This resulted in the policy getting created and the script completing without errors.

Here's an example of what the execution, with errors, looks like:
`PS C:\PowerApps-Samples\powershell\enterprisePolicies\SubnetInjection> .\CreateSubnetInjectionEnterprisePolicy.ps1

cmdlet CreateSubnetInjectionEnterprisePolicy at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
subscriptionId: abcd1234-ab12-ab12-ab12-abcdef123456
resourceGroup: Networking-RG
enterprisePolicyName: PowerPlatformSubnetInjection
enterprisePolicylocation: unitedstates
primaryVnetId: /subscriptions/abcd1234-ab12-ab12-ab12-abcdef123456/resourceGroups/Networking-RG/providers/Microsoft.Network/virtualNetworks/vNet-Primary
primarySubnetName: PowerPlatformIntegration
secondaryVnetId: /subscriptions/abcd1234-ab12-ab12-ab12-abcdef123456/resourceGroups/Networking-RG/providers/Microsoft.Network/virtualNetworks/vNet-Secondary
secondarySubnetName: PowerPlatformIntegration
Logging In...
Logged In...
Creating Enterprise policy...
New-AzResourceGroupDeployment: C:\PowerApps-Samples\powershell\enterprisePolicies\Common\EnterprisePolicyOperations.ps1:32
Line |
32 | … $policy = New-AzResourceGroupDeployment -DeploymentName "EPDeployme …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 11:31:22 AM - Error: Code=ResourceGroupNotFound; Message=Resource group 'Networking-RG' could not be found.
New-AzResourceGroupDeployment: C:\PowerApps-Samples\powershell\enterprisePolicies\Common\EnterprisePolicyOperations.ps1:32
Line |
32 | … $policy = New-AzResourceGroupDeployment -DeploymentName "EPDeployme …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The deployment validation failed
InvalidOperation: C:\PowerApps-Samples\powershell\enterprisePolicies\Common\EnterprisePolicyOperations.ps1:35
Line |
35 | if ($policy.ProvisioningState.Equals("Succeeded"))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| You cannot call a method on a null-valued expression.
Error creating/updating Enterprise policy

Subnet Injection Enterprise policy not created`

@robjdav
Copy link

robjdav commented Aug 5, 2024

Hi there - I got the same issue but am having trouble implementing your fix. Can you provide the code for your updated EnterprisePolicyOperations.ps1?

thanks

@RyC67
Copy link

RyC67 commented Aug 28, 2024

@RobGANA I have the same problem, I've updated the script but I'm still running into the same problem as mentioned in this issue (#624). Do you have the updated script so I can try that?

@RobGANA
Copy link
Author

RobGANA commented Aug 28, 2024

@robjdav and @RyC67,

In EnterprisePolicyOperations.ps1, I altered line 27
function PutEnterprisePolicy($subscriptionId, $resourceGroup, $body)
and I added a new line before line 32
Set-AzContext -Subscription $subscriptionId

In CreateSubnetInjectionPolicy.ps1, I altered line 86
$result = PutEnterprisePolicy $subscriptionId $resourceGroup $body

That's all there was to it. The subscription ID was already a parameter of the CreateSubnetInjectionPolicy script. It just needed to be passed to and used in the EnterprisePolicyOperations script.

@robjdav
Copy link

robjdav commented Sep 5, 2024

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants