Я пытаюсь заставить пользователя добавить тег и его значение, в моем примере «Среда» для имени и «Производство» для значения. Но здесь у меня есть проблема с моим кодом, ошибка, которую я не могу решить, поэтому я здесь. Ошибка касается параметра «tagValue», и он, кажется, не распознается существующей политикой, здесь «azurerm_policy_definition». Заранее благодарю за помощь.
variable "requiredTag" {
default = "environment"
}
variable "requiredValue" {
default = "production"
}
resource "azurerm_policy_assignment" "requiredTag" {
name = "Deny-RequiredTag-${var.requiredTag}"
display_name = "Tag obligatoire '${var.requiredTag}'"
description = "Affectation de la stratégie de balise requise pour '${var.requiredTag}'"
policy_definition_id = "${azurerm_policy_definition.requiredTag.id}"
scope = "/subscriptions/0000000000/resourceGroups/PolicyLab"
parameters = <<PARAMETERS
{
"tagValue": {
"value": "${var.requiredValue}"
},
"tagName": {
"value": "${var.requiredTag}"
}
}
PARAMETERS
}
resource "azurerm_policy_definition" "requiredTag" {
name = "Deny-RequiredTag-Resource"
display_name = "Deny a Required Tag on a Resource"
description = "Deny all resources for a required tag"
policy_type = "Custom"
mode = "All"
policy_rule = <<POLICY_RULE
{
"if": {
"not": {
"field": "[concat('tags[', parameters('tagName'), ']')]",
"equals": "[parameters('tagValue')]"
}
},
"then": {
"effect": "deny"
}
}
POLICY_RULE
parameters = <<PARAMETERS
{
"tagName": {
"type": "String",
"metadata": {
"displayName": "Tag Name",
"description": "Name of the tag, such as 'environment'"
}
},
"tagValue": {
"type": "String",
"metadata": {
"displayName": "Tag Value",
"description": "Value of the tag, such as 'production'"
}
}
}
PARAMETERS
}
И вот эта ошибка:
Error: policy.DefinitionsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="InvalidPolicyParameterUpdate" Message="The policy contains new parameter(s) 'tagValue' which are not present in the existing policy and have no default value. New parameters may be added to a policy only if they have a default value."
on main.tf line 34, in resource "azurerm_policy_definition" "requiredTag":
34: resource "azurerm_policy_definition" "requiredTag" {