强制标记以使天蓝色数据块工作区

时间:2019-07-31 13:09:13

标签: azure azure-databricks

我的目的是强制开发人员在创建集群时提供标签。我在ARM模板中添加了一个策略,该策略创建了一个Azure工作区。它成功完成了验证,但是无法部署。很抱歉,我的问题不清楚。请帮助

{  
   "$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion":"1.0.0.0",
"parameters":{  
  "workspaceName":{  
   "defaultValue":"xyxy",


   "type":"String",
     "metadata":{  
        "description":"The name of the Azure Databricks workspace to create."
     }
  },
  "subscriptionName":{  
     "allowedValues":[  
        "yy",
        "xx"
     ],
     "type":"String",
     "metadata":{  
        "description":"Specifies the subscription in which to create the workspace."
     }
  },
  "resourceGroup":{  
     "defaultValue":"abc",
     "allowedValues":[  
        "dd",
        "bb",
        "abc"
     ],
     "type":"String",
     "metadata":{  
        "description":"Resource group in which to create the workspace."
     }
  },
  "pricingTier":{  
     "defaultValue":"premium",
     "allowedValues":[  
        "standard",
        "premium"
     ],
     "type":"String",
     "metadata":{  
        "description":"The pricing tier of workspace."
     }
  },
  "location":{  
     "defaultValue":"east us",
     "type":"String",
     "metadata":{  
        "description":"Location for all resources."
     }
  }
   },
"variables":{  
  "managedResourceGroupName":"[concat('databricks-rg-', parameters('workspaceName'), '-', uniqueString(parameters('workspaceName'), resourceGroup().id))]"
   },
   "resources":[  
  {  
     "type":"Microsoft.Databricks/workspaces",
     "apiVersion":"2018-04-01",
     "name":"[parameters('workspaceName')]",
     "location":"[parameters('location')]",
     "sku":{  
        "name":"[parameters('pricingTier')]"
     },
     "properties":{  
        "displayName":"Enforce tag and its value",
        "policyType":"BuiltIn",
        "ManagedResourceGroupId":"[concat(subscription().id, '/resourceGroups/', variables('managedResourceGroupName'))]",
        "description":"Enforces a required tag and its value.",
        "parameters":{  
           "tagName":{  
              "type":"String",
              "metadata":{  
                 "description":"Name of the tag, such as costCenter"
              }
           },
           "tagValue":{  
              "type":"String",
              "metadata":{  
                 "description":"Value of the tag, such as headquarter"
              }
           }
        },
        "policyRule":{  
           "if":{  
              "not":{  
                 "field":"[concat('tags[', parameters('tagName'), ']')]",
                 "equals":"[parameters('tagValue')]"
              }
           },
           "then":{  
              "effect":"deny"
           }
        }
     },
     "outputs":{  
        "workspace":{  
           "type":"Object",
           "value":"[reference(resourceId('Microsoft.Databricks/workspaces', parameters('workspaceName')))]"
        }
     }
  }
   ]
}

错误: 无法在行'73'和列'9'处处理资源'/subscriptions/04jdmgb-5642-8640-9a15-a0504248340f/resourceGroups/abc/providers/Microsoft.Databricks/workspaces/test12'的模板语言表达式。 '找不到模板参数'tagName'。有关用法的详细信息,请参见https://aka.ms/arm-template/#parameters。”点击这里了解详情 您的部署失败

1 个答案:

答案 0 :(得分:0)

注意:不幸的是,您不允许使用Azure门户/ PowerShell / CLI / ARM模板为在Azure Databricks中创建的托管资源组添加自定义标签。

原因:默认情况下,您无法在托管资源组上执行任何写操作。

如果您尝试修改托管资源组中的任何内容,则会看到此错误消息:

{"details":[{"code":"ScopeLocked","message":"The scope '/subscriptions/xxxxxxxxxxxxxxxx/resourceGroups/databricks-rg-chepra-d7ensl75cgiki' cannot perform write operation because following scope(s) are locked: '/subscriptions/xxxxxxxxxxxxxxxxxxxx/resourceGroups/databricks-rg-chepra-d7ensl75cgiki'. Please remove the lock and try again."}]}

可能的方式:您可以在创建/修改群集时将标签指定为键值对,Azure Databricks会将这些标签应用于云资源。

集群标签使您可以轻松地监视组织中各个组使用的云资源成本。创建群集时,可以将标签指定为键值对,然后Databricks将这些标签应用于VM和磁盘卷等云资源。

为方便起见,Databricks将四个默认标签应用于每个群集:供应商,创建者,ClusterName和ClusterId。创建集群时,可以添加自定义标签。要配置集群标签:

  1. 集群配置页面上,单击高级选项开关。
  2. 在页面底部,单击标签标签。

enter image description here

  1. 为每个自定义标签添加一个键值对。您最多可以添加45个自定义标签。

现在您可以在门户中看到先前添加的标签:

enter image description here

参考: Azure Databricks - Cluster Tags

希望这会有所帮助。