小编Pet*_*ter的帖子

Terraform:将包含字符串列表的变量传递给 jsonencode 部分

我想设置一个 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)

变量.tf

# Scope of the Allowed Locations policy
variable "scope_allowedlocations" {
  description = "The scope of the allowed locations assignment."
  default     = …
Run Code Online (Sandbox Code Playgroud)

policy json variable-assignment azure terraform

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

azure ×1

json ×1

policy ×1

terraform ×1

variable-assignment ×1