azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Set-AzPolicySetDefinition & Set-AzureRmPolicySetDefinition fail with parameters

Open RichShillingtonMSFT opened this issue 7 years ago • 7 comments

Description

When running Set-AzPolicySetDefinition with parameters it fails every time. Assigning the same policy directly with parameter works without an issue. It only fails when adding it to an initiative using Set-AzPolicySetDefinition. The same issue occurs with Set-AzureRMPolicySetDefinition.

Steps to reproduce

Use 

Set-AzPolicySetDefinition and add any policy with parameters to an initiative.
This fails regardless of how you specify parameters.

Environment data

Name                           Value                                                                                                                                                                                                                             
----                           -----                                                                                                                                                                                                                             
PSVersion                      5.1.17763.316                                                                                                                                                                                                                     
PSEdition                      Desktop                                                                                                                                                                                                                           
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                                           
BuildVersion                   10.0.17763.316                                                                                                                                                                                                                    
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                                   
WSManStackVersion              3.0                                                                                                                                                                                                                               
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                                               
SerializationVersion           1.1.0.1   

Module versions

ModuleType Version    Name                                ExportedCommands                                                                                                                                                                                       
---------- -------    ----                                ----------------                                                                                                                                                                                       
Script     1.5.0      Az.Accounts                         {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-AzContextAutosave...}                                                                                            
Script     1.0.1      Az.Aks                              {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksCredential...}                                                                                                                                        
Script     1.1.0      Az.AnalysisServices                 {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisServicesServer, Get-AzAnalysisServicesServer, Remove-AzAnalysisServicesServer...}                                                                  
Script     1.0.0      Az.ApiManagement                    {Add-AzApiManagementRegion, Get-AzApiManagementSsoToken, New-AzApiManagementCustomHostnameConfiguration, New-AzApiManagementSystemCertificate...}                                                      
Script     1.0.0      Az.ApplicationInsights              {Get-AzApplicationInsights, New-AzApplicationInsights, Remove-AzApplicationInsights, Set-AzApplicationInsightsPricingPlan...}                                                                          
Script     1.2.1      Az.Automation                       {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHybridWorkerGroup, Get-AzAutomationJobOutputRecord, Import-AzAutomationDscNodeConfiguration...}                                                 
Script     1.0.0      Az.Batch                            {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBatchAccountKeys, New-AzBatchAccount...}                                                                                                             
Script     1.0.0      Az.Billing                          {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzEnrollmentAccount, Get-AzConsumptionBudget...}                                                                                                       
Script     1.1.0      Az.Cdn                              {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnProfile, Remove-AzCdnProfile...}                                                                                                                   
Script     1.0.1      Az.CognitiveServices                {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAccountKey, Get-AzCognitiveServicesAccountSkus, Get-AzCognitiveServicesAccountType...}                                                         
Script     1.7.0      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAvailabilitySet, Update-AzAvailabilitySet...}                                                                                                  
Script     1.0.1      Az.ContainerInstance                {New-AzContainerGroup, Get-AzContainerGroup, Remove-AzContainerGroup, Get-AzContainerInstanceLog}                                                                                                      
Script     1.0.1      Az.ContainerRegistry                {New-AzContainerRegistry, Get-AzContainerRegistry, Update-AzContainerRegistry, Remove-AzContainerRegistry...}                                                                                          
Script     1.1.0      Az.DataFactory                      {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-AzDataFactoryV2, Remove-AzDataFactoryV2...}                                                                                                          
Script     1.0.0      Az.DataLakeAnalytics                {Get-AzDataLakeAnalyticsDataSource, New-AzDataLakeAnalyticsCatalogCredential, Remove-AzDataLakeAnalyticsCatalogCredential, Set-AzDataLakeAnalyticsCatalogCredential...}                                
Script     1.1.0      Az.DataLakeStore                    {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreFirewallRule, Set-AzDataLakeStoreTrustedIdProvider...}                                           
Script     1.0.0      Az.DevTestLabs                      {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdownPolicy, Get-AzDtlAutoStartPolicy, Get-AzDtlVMsPerLabPolicy...}                                                                                    
Script     1.0.0      Az.Dns                              {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDnsRecordSet, Set-AzDnsRecordSet...}                                                                                                              
Script     1.1.0      Az.EventGrid                        {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEventGridTopic, New-AzEventGridTopicKey...}                                                                                                         
Script     1.0.1      Az.EventHub                         {New-AzEventHubNamespace, Get-AzEventHubNamespace, Set-AzEventHubNamespace, Remove-AzEventHubNamespace...}                                                                                             
Script     1.0.0      Az.HDInsight                        {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefinition, Wait-AzHDInsightJob, New-AzHDInsightStreamingMapReduceJobDefinition...}                                                                        
Script     1.0.2      Az.IotHub                           {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, Get-AzIotHubConnectionString, Get-AzIotHubJob...}                                                                                                 
Script     1.1.0      Az.KeyVault                         {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, Stop-AzKeyVaultCertificateOperation, Get-AzKeyVaultCertificateOperation...}                                                                  
Script     1.2.1      Az.LogicApp                         {Get-AzIntegrationAccountAgreement, Get-AzIntegrationAccountAssembly, Get-AzIntegrationAccountBatchConfiguration, Get-AzIntegrationAccountCallbackUrl...}                                              
Script     1.0.0      Az.MachineLearning                  {Move-AzMlCommitmentAssociation, Get-AzMlCommitmentAssociation, Get-AzMlCommitmentPlanUsageHistory, Remove-AzMlCommitmentPlan...}                                                                      
Script     1.0.0      Az.MarketplaceOrdering              {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}                                                                                                                                                       
Script     1.0.0      Az.Media                            {Sync-AzMediaServiceStorageKeys, Set-AzMediaServiceKey, Get-AzMediaServiceKeys, Get-AzMediaServiceNameAvailability...}                                                                                 
Script     1.0.1      Az.Monitor                          {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProfile, Get-AzLogProfile...}                                                                                                                       
Script     1.6.0      Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Get-AzApplicationGatewayAuthenticationCertificate, New-AzApplicationGatewayAuthenticationCertificate, Remove-AzApplicationGatewayAuthenticationC...
Script     1.0.0      Az.NotificationHubs                 {Get-AzNotificationHub, Get-AzNotificationHubAuthorizationRules, Get-AzNotificationHubListKeys, Get-AzNotificationHubPNSCredentials...}                                                                
Script     1.1.0      Az.OperationalInsights              {New-AzOperationalInsightsAzureActivityLogDataSource, New-AzOperationalInsightsCustomLogDataSource, Disable-AzOperationalInsightsLinuxCustomLogCollection, Disable-AzOperationalInsightsIISLogCollec...
Script     1.0.0      Az.PolicyInsights                   {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStateSummary, Get-AzPolicyRemediation...}                                                                                                           
Script     1.0.0      Az.PowerBIEmbedded                  {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspaceCollectionAccessKeys, Get-AzPowerBIWorkspace...}                                                         
Script     1.2.0      Az.RecoveryServices                 {Get-AzRecoveryServicesBackupProperty, Get-AzRecoveryServicesVault, Get-AzRecoveryServicesVaultSettingsFile, New-AzRecoveryServicesVault...}                                                           
Script     1.0.0      Az.RedisCache                       {Remove-AzRedisCachePatchSchedule, New-AzRedisCacheScheduleEntry, Get-AzRedisCachePatchSchedule, New-AzRedisCachePatchSchedule...}                                                                     
Script     1.0.0      Az.Relay                            {New-AzRelayNamespace, Get-AzRelayNamespace, Set-AzRelayNamespace, Remove-AzRelayNamespace...}                                                                                                         
Script     1.3.0      Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRoleAssignment, New-AzRoleAssignment...}                                                                                                      
Script     1.0.0      Az.ServiceBus                       {New-AzServiceBusNamespace, Get-AzServiceBusNamespace, Set-AzServiceBusNamespace, Remove-AzServiceBusNamespace...}                                                                                     
Script     1.0.1      Az.ServiceFabric                    {Add-AzServiceFabricApplicationCertificate, Add-AzServiceFabricClientCertificate, Add-AzServiceFabricClusterCertificate, Add-AzServiceFabricNode...}                                                   
Script     1.0.2      Az.SignalR                          {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, New-AzSignalRKey...}                                                                                                                                  
Script     1.8.0      Az.Sql                              {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseTransparentDataEncryptionActivity, Set-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseUpgradeHint...}                          
Script     1.2.0      Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStorageAccount, New-AzStorageAccountKey...}                                                                                                      
Script     1.0.0      Az.StreamAnalytics                  {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalyticsDefaultFunctionDefinition, New-AzStreamAnalyticsFunction, Remove-AzStreamAnalyticsFunction...}                                                    
Script     1.0.1      Az.TrafficManager                   {Add-AzTrafficManagerCustomHeaderToEndpoint, Remove-AzTrafficManagerCustomHeaderFromEndpoint, Add-AzTrafficManagerCustomHeaderToProfile, Remove-AzTrafficManagerCustomHeaderFromProfile...}            
Script     1.1.2      Az.Websites                         {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServicePlan, Remove-AzAppServicePlan...}                                                                                                         

Debug output



DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policySetDefinitions/xxxxx-baseline?api-version=2018-05-01

Headers:
User-Agent                    : PSVersion/v5.1.17763.316,AzurePowershell/v1.0.0
ParameterSetName              : IdParameterSet
CommandName                   : Set-AzPolicySetDefinition

Body:



DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
Vary                          : Accept-Encoding
x-ms-ratelimit-remaining-tenant-reads: 11999
x-ms-request-id               : canadacentral:69691002-2568-4b98-acda-438881c784a2
x-ms-correlation-request-id   : ec23bec0-86b6-4f5b-b9be-16b1b9db1700
x-ms-routing-request-id       : CANADACENTRAL:20190415T111203Z:ec23bec0-86b6-4f5b-b9be-16b1b9db1700
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Mon, 15 Apr 2019 11:12:03 GMT

Body:
{
  "properties": {
    "displayName": "XXXXXX Azure Baseline Initiative",
    "policyType": "Custom",
    "metadata": {
      "createdBy": "8653c0f2-3309-4b6b-9c07-e451e02d9888",
      "createdOn": "2019-04-15T11:09:43.0687632Z",
      "updatedBy": null,
      "updatedOn": null
    },
    "policyDefinitions": [
      {
        "policyDefinitionReferenceId": "9365598378311063819",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/deployIfNotExists-ade"
      },
      {
        "policyDefinitionReferenceId": "4589074823749662906",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Deny-NotSQLv12"
      },
      {
        "policyDefinitionReferenceId": "6391768719139925995",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Deny-sa-nose"
      },
      {
        "policyDefinitionReferenceId": "6631415745917904432",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Deny-sqltde-disable"
      },
      {
        "policyDefinitionReferenceId": "15337589121526940566",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Deny-pip-create"
      },
      {
        "policyDefinitionReferenceId": "11420589891143031388",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Deny-sqldb-basic"
      },
      {
        "policyDefinitionReferenceId": "2217020320544932411",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Audit-vm-no-managed-dsk"
      },
      {
        "policyDefinitionReferenceId": "10868640033501815215",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Deny-classic-resources"
      },
      {
        "policyDefinitionReferenceId": "13452794869598072885",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/deployIfNotExists-diag-nsg"
      },
      {
        "policyDefinitionReferenceId": "17541625085025244773",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Deny-cosmosdb-nose"
      },
      {
        "policyDefinitionReferenceId": "10491014711042333083",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Audit-sql-no-tde"
      },
      {
        "policyDefinitionReferenceId": "6270701490118955921",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Audit-sa-std-lrs"
      },
      {
        "policyDefinitionReferenceId": "6819399527029456581",
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Deny-kvault-novnet"
      }
    ]
  },
  "id": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policySetDefinitions/xxxxx-baseline",
  "type": "Microsoft.Authorization/policySetDefinitions",
  "name": "xxxxx-baseline"
}


DEBUG: [ADAL]: Information: 4/15/2019 11:12:03 AM: de1fe720-f6de-45df-9c7f-1842ef380723 - AcquireTokenHandlerBase.cs: === Token Acquisition started:
	Authority: https://login.microsoftonline.com/dee1e1fb-a70e-47bd-95cd-4394e718b1d7/
	Resource: https://management.core.windows.net/
	ClientId: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	CacheType: null
	Authentication Target: User
	

DEBUG: [ADAL]: Information: 4/15/2019 11:12:03 AM:  - TokenCache.cs: Deserialized 1 items to token cache.

DEBUG: [ADAL]: Verbose: 4/15/2019 11:12:03 AM: de1fe720-f6de-45df-9c7f-1842ef380723 - TokenCache.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 4/15/2019 11:12:03 AM: de1fe720-f6de-45df-9c7f-1842ef380723 - TokenCache.cs: An item matching the requested resource was found in the cache

DEBUG: [ADAL]: Information: 4/15/2019 11:12:03 AM: de1fe720-f6de-45df-9c7f-1842ef380723 - TokenCache.cs: 50.5701686833333 minutes left until token in cache expires

DEBUG: [ADAL]: Information: 4/15/2019 11:12:03 AM: de1fe720-f6de-45df-9c7f-1842ef380723 - TokenCache.cs: A matching item (access token or refresh token or both) was found in the cache

DEBUG: [ADAL]: Information: 4/15/2019 11:12:03 AM: de1fe720-f6de-45df-9c7f-1842ef380723 - AcquireTokenHandlerBase.cs: === Token Acquisition finished successfully. An access token was retuned:
	Access Token Hash: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	Expiration Time: 4/15/2019 12:02:37 PM +00:00
	User Hash: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://management.azure.com/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policySetDefinitions/xxxxxxxx-baseline?api-version=2018-05-01

Headers:
User-Agent                    : PSVersion/v5.1.17763.316,AzurePowershell/v1.0.0
ParameterSetName              : IdParameterSet
CommandName                   : Set-AzPolicySetDefinition

Body:
{
  "name": "xxxxx-baseline",
  "properties": {
    "displayName": "xxxxxx Azure Baseline Initiative",
    "metadata": {
      "createdBy": "8653c0f2-3309-4b6b-9c07-e451e02d9888",
      "createdOn": "2019-04-15T11:09:43.0687632Z",
      "updatedBy": null,
      "updatedOn": null
    },
    "policyDefinitions": [
      {
        "policyDefinitionId": "/providers/Microsoft.Management/managementgroups/TenantRoot/providers/Microsoft.Authorization/policyDefinitions/Deny-allowed-resource-types"
      }
    ],
    "parameters": {
      "listOfResourceTypesAllowed": {
        "value": [
          "Microsoft.Compute/virtualMachines",
          "Microsoft.Compute/availabilitySets"
        ]
      }
    }
  }
}


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
BadRequest

Headers:
Pragma                        : no-cache
x-ms-request-id               : canadacentral:200ec217-241e-4633-96c9-16be7773030f
x-ms-ratelimit-remaining-tenant-writes: 1199
x-ms-correlation-request-id   : 268d6613-2781-4855-b1d7-a47dbabd8311
x-ms-routing-request-id       : CANADACENTRAL:20190415T111204Z:268d6613-2781-4855-b1d7-a47dbabd8311
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Mon, 15 Apr 2019 11:12:03 GMT

Body:
{
  "error": {
    "code": "InvalidRequestContent",
    "message": "The request content was invalid and could not be deserialized: 'Could not find member 'value' on object of type 'PolicyParameterDefinition'. Path 'properties.parameters.listOfResourceTypesAllowed.value', line 18, position 16.'."
  }
}


Set-AzPolicySetDefinition : InvalidRequestContent : The request content was invalid and could not be deserialized: 'Could not find member 'value' on object of type 'PolicyParameterDefinition'. Path 'properties.parameters.listOfResourceTypesAllowed.value', 
line 18, position 16.'.
At line:1 char:4
+    Set-AzPolicySetDefinition -Id $($PolicySetDefinition.PolicySetDefi ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzPolicySetDefinition], ErrorResponseMessageException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetAzurePolicySetDefinitionCmdlet
 
DEBUG: AzureQoSEvent: CommandName - Set-AzPolicySetDefinition; IsSuccess - False; Duration - 00:00:04.4251705; Exception - Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.ErrorResponses.ErrorResponseMessageException: InvalidRequestContent : The req
uest content was invalid and could not be deserialized: 'Could not find member 'value' on object of type 'PolicyParameterDefinition'. Path 'properties.parameters.listOfResourceTypesAllowed.value', line 18, position 16.'.
   at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.HandleException(ExceptionDispatchInfo capturedException)
   at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 7:12:06 AM - SetAzurePolicySetDefinitionCmdlet end processing.
DEBUG: 7:12:06 AM - SetAzurePolicySetDefinitionCmdlet end processing.

Error output

   HistoryId: 16


Message        : InvalidRequestContent : The request content was invalid and could not be deserialized: 'Could not find member 'value' on object of type 'PolicyParameterDefinition'. Path 
                 'properties.parameters.listOfResourceTypesAllowed.value', line 18, position 16.'.
StackTrace     :    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.HandleException(ExceptionDispatchInfo capturedException)
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.ErrorResponses.ErrorResponseMessageException
InvocationInfo : {Set-AzPolicySetDefinition}
Line           :    Set-AzPolicySetDefinition -Id $($PolicySetDefinition.PolicySetDefinitionId) -PolicyDefinition "`[`{`"policyDefinitionId`": 
                 `"$($AzurePolicyDefinition.PolicyDefinitionID)`"`}`]" -Parameter $($AzurePolicyDefinition.ParametersSettingsFilePath) -Debug
Position       : At line:1 char:4
                 +    Set-AzPolicySetDefinition -Id $($PolicySetDefinition.PolicySetDefi ...
                 +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 16

Deny-allowed-resource-types-Parameters-Settings.json.txt Deny-allowed-resource-types.json.txt Deny-allowed-resource-types-Parameters.json.txt

RichShillingtonMSFT avatar Apr 15 '19 11:04 RichShillingtonMSFT

Update: This also fails when setting this directly using Rest API. So the module may be ok, but it cannot be processed.

RichShillingtonMSFT avatar Apr 15 '19 11:04 RichShillingtonMSFT

@cormacpayne Hey Cormac, can you take a look at this issue and direct to the Resources team if appropriate?

maddieclayton avatar Apr 15 '19 18:04 maddieclayton

@mentat9 Hey Chris, would you mind taking a look at this issue?

cormacpayne avatar Apr 15 '19 18:04 cormacpayne

The parameters of the policy set are determined at the time it is created. You cannot add or remove parameters to/from it afterward, which is effectively what is happening when adding another policy that has parameters. This is the behavior of the policy backend by design, not related to Powershell. You will see the same thing if you try from the portal.

mentat9 avatar Apr 15 '19 19:04 mentat9

Closing as by design.

maddieclayton avatar Apr 15 '19 20:04 maddieclayton

@mentat9 I am adding a policy to an initiative not adding parameters to the policy. This is allowed in the portal. It just doesn't work with PowerShell. I don't think this is an issue with the cmdlet. The issue appears to be that the portal sends and resource manager accepts an invalid JSON.

The portal submits this with a single pair of quotes surrounding both resources: "parameters": {"listOfResourceTypesAllowed": {"value": ["Microsoft.Compute/virtualMachines,Microsoft.Compute/availabilitySets"]}}

It should be formated like this with a pair of quotes surrounding each resource: "parameters": {"listOfResourceTypesAllowed": {"value": ["Microsoft.Compute/availabilitySets","Microsoft.Compute/virtualMachines"]}}

I cannot send the invalid JSON using PowerShell as the JSON reader will reject it.

RichShillingtonMSFT avatar Apr 16 '19 10:04 RichShillingtonMSFT

@RichShillingtonMSFT

Set-AzPolicySetDefinition does not add a policy definition to an initiative. It updates the whole initiative. The -Parameters flag on Set-AzPolicySetDefinition is used to define parameters for the whole initiative, not for setting the parameter values for an individual definition in the initiative. This is why you're seeing the error Could not find member 'value' on object of type 'PolicyParameterDefinition. Values aren't expected here!

In order to set parameter values for a definition you need to include them in the definition reference (i.e. in the -PolicyDefinition parameter). See example 1 in New-AzPolicySetDefinition for the format.


Can you open the portal JSON issue separately here? That does look like a bug. Please include the name of the blade and the steps to reproduce. Thanks!

camillemarie avatar Apr 16 '19 18:04 camillemarie