【发布时间】:2022-10-21 16:27:38
【问题描述】:
我已经阅读了文档,虽然策略片段的想法似乎有利于代码重用,但系统似乎没有提供一种以自动化方式部署它们的方法。
我什至已经将 apim 的整个配置导出到 git 并且找不到我的策略片段。
【问题讨论】:
标签: fragment devops policy apim
我已经阅读了文档,虽然策略片段的想法似乎有利于代码重用,但系统似乎没有提供一种以自动化方式部署它们的方法。
我什至已经将 apim 的整个配置导出到 git 并且找不到我的策略片段。
【问题讨论】:
标签: fragment devops policy apim
似乎这是一个非常新的功能,我们遇到了同样的问题,作为第一种方法,我们决定使用 terraform 将策略片段从开发环境部署到临时和生产环境。
$computer> cat main.tf
terraform {
required_providers {
azapi = {
source = "azure/azapi"
}
}
}
provider "azapi" {
}
resource "azapi_resource" "symbolicname" {
type = "Microsoft.ApiManagement/service/policyFragments@2021-12-01-preview"
name = “fragmentpolicyname”
parent_id = "/subscriptions/[subscriptionid]/resourceGroups/[resourcegroupname]/providers/Microsoft.ApiManagement/service/[apimanagementservicename]”
body = jsonencode({
properties = {
description = “fragment policy description”
format = "xml" # it could also be rawxml
value = <<EOF
<!--
IMPORTANT:
- Policy fragment are included as-is whenever they are referenced.
- If using variables. Ensure they are setup before use.
- Copy and paste your code here or simply start coding
-->
<fragment>
//some magical code here that you will use in a lot of policies
</fragment>
EOF
}
})
}
terraform init
terraform plan
terraform apply
您可以将此部分集成到您的 azure devops 管道中。
【讨论】: