我想设置一个 Terraform 模块,根据 Terraforms策略分配示例将策略分配给 Azure 资源。
为了分配允许位置策略,我想将允许位置列表作为字符串列表从 variables.tf 文件传递到 main.tf,在那里执行分配。
#Allowed Locations Policy Assignment
resource "azurerm_policy_assignment" "allowedlocations" {
name = "allowed-locations"
scope = var.scope_allowedlocations
policy_definition_id = var.policy_allowedlocations.id
description = "This policy enables you to restrict the locations."
display_name = "Allowed Locations"
parameters = <<PARAMETERS
{
"allowedLocations": {
"value": ${var.listofallowedlocations}
}
}
PARAMETERS
}
Run Code Online (Sandbox Code Playgroud)
# Scope of the Allowed Locations policy
variable "scope_allowedlocations" {
description = "The scope of the allowed locations assignment."
default = …
Run Code Online (Sandbox Code Playgroud)