gpt4 book ai didi

azure - '在类型 'type' 的对象上找不到成员 'PolicyParameter'

转载 作者:行者123 更新时间:2023-12-03 02:43:11 25 4
gpt4 key购买 nike

我很难通过 Azure Pipelines 处理这些策略和部署。现在,当它已经定义时,它期待定义的type

我使用 Azure 策略部署模板(创建和分配任务都有版本 3)错误信息:

InvalidRequestContent : The request content was invalid and could not be deserialized: 'Could not find member 'type' on object of type 'PolicyParameter'. Path 'properties.parameters.envValue.type', line 9, position 15.'.

教授 enter image description here

我的参数文件有什么问题?

{
"envValue": {
"type": "String",
"metadata": {
"displayName": "Tag Value",
"description": "Deployment Environment of the resource"
},
"defaultValue": "Dev",
"allowedValues": [
"Dev",
"Qas",
"prd"
]
}
}

我的作业任务:

# Input variables: set these values in the variables section of the release pipeline

# AssignmentName - [required] Policy assignment name
# AssignmentDisplayName - [optional] Policy assignment display name
# AssignmentDescription - [optional] Policy assignment description
# PolicyName - [optional] Name of policy definition to assign
# PolicySetName - [optional] Name of policy set definition to assign
# ResourceGroupName - [optional] Name of resource group the policy [set] definition will be applied to
# SubscriptionId - [optional] Id of subscription the policy [set] definition will be applied to
# ManagementGroupName - [optional] Name of management group the policy [set] definition will be applied to
# PolicyParameters - [optional] Policy parameter values in JSON string format

# Notes:
# Refer to https://learn.microsoft.com/en-us/azure/azure-policy/ for documentation on the Powershell cmdlets and the JSON input formats

$assignmentName = "$(AssignmentName)"
$assignmentDisplayName = "$(AssignmentDisplayName)"
$assignmentDescription = "$(AssignmentDescription)"
$policyName = "$(PolicyName)"
$policySetName = "$(PolicySetName)"
$resourceGroupName = "$(ResourceGroupName)"
$subscriptionId = "$(SubscriptionId)"
$managementGroupName = "$(managementGroupName)"
$policyParameters = "$(PolicyParameters)"

if (!$assignmentName)
{
throw "Unable to create policy assignment: required input variable value `$(AssignmentName) was not provided"
}

if (!$policyName -and !$policySetName)
{
throw "Unable to create policy assignment: neither `$(PolicyName) nor `$(PolicySetName) was provided. One or the other must be provided."
}

if ($policyName -and $policySetName)
{
throw "Unable to create policy assignment: `$(PolicyName) '$policyName' and `$(PolicySetName) '$policySetName' were both provided. Either may be provided, but not both."
}

if ($subscriptionId -and $managementGroupName)
{
throw "Unable to create policy assignment: `$(SubscriptionId) '$subscriptionId' and `$(ManagementGroupName) '$managementGroupName' were both provided. Either may be provided, but not both."
}

if ($managementGroupName -and $resourceGroupName)
{
throw "Unable to create policy assignment: `$(ManagementGroupName) '$managementGroupName' and `$(ResourceGroupName) '$resourceGroupName' were both provided. Either may be provided, but not both."
}

if ($managementGroupName)
{
$scope = "/providers/Microsoft.Management/managementGroups/$managementGroupName"
$searchParameters = @{ManagementGroupName=$managementGroupName}
}
else
{
if (!$subscriptionId)
{
$subscription = Get-AzureRmContext | Select-Object -Property Subscription
$subscriptionId = $subscription.Id
}

$scope = "/subscriptions/$subscriptionId"
$searchParameters = @{SubscriptionId=$subscriptionId}

if ($resourceGroupName)
{
$scope += "/resourceGroups/$resourceGroupName"
}
}

$cmdletParameters = @{Name=$assignmentName; Scope=$scope}
if ($assignmentDisplayName)
{
$cmdletParameters += @{DisplayName=$assignmentDisplayName}
}

if ($assignmentDescription)
{
$cmdletParameters += @{Description=$assignmentDescription}
}

if ($policyName)
{
$policyDefinition = Get-AzureRmPolicyDefinition @searchParameters | Where-Object { $_.Name -eq $policyName }
if (!$policyDefinition)
{
throw "Unable to create policy assignment: policy definition $policyName does not exist"
}

$cmdletParameters += @{PolicyDefinition=$policyDefinition}
}

if ($policySetName)
{
$policySetDefinition = Get-AzureRmPolicySetDefinition @searchParameters | Where-Object { $_.Name -eq $policySetName }
if (!$policySetDefinition)
{
throw "Unable to create policy assignment: policy set definition $policySetName does not exist"
}

$cmdletParameters += @{PolicySetDefinition=$policySetDefinition}
}

if ($policyParameters)
{
$cmdletParameters += @{PolicyParameter=$policyParameters}
}

&New-AzureRmPolicyAssignment @cmdletParameters

最佳答案

有点晚了,但我今天遇到了这个。您的分配参数文件应如下所示:

{
"envValue":{
"value": "Dev"
}
}

您传递的是参数定义,而不是实际参数。遵循与 ARM 模板相同的模式。

关于azure - '在类型 'type' 的对象上找不到成员 'PolicyParameter',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60092383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com