如何在 terraform 中为 Azure APIM Azure Devops 提供 swagger/policy lik

How to provide swagger/policy lik in terraform for Azure APIM Azure Devops

我正在努力通过 Terraform 添加新的 API 并向 Azure APIM 添加新策略。 当我在本地进行测试时(直接打开终端并 运行 terraform plan and apply),我能够创建它。但是当我通过 Azure devops 管道时,我无法跟踪文件。我收到错误消息“文件不存在”。

因为我使用的是文件命令,我想我必须发布到工件中并尝试一下,但仍然是相同的响应。我是否必须将它放入存储帐户才能通过 SAS 访问它,这是唯一的选择还是我可以使用管道 artifacts.

这是TF代码-注释掉的是我试过的多个版本。

resource "azurerm_api_management_api" "example" {
  name                = "example-api1"
  resource_group_name = data.azurerm_api_management.example.resource_group_name
  api_management_name = data.azurerm_api_management.example.name
  revision            = "1"
  display_name        = "Example API1"
  path                = "example1"
  protocols           = ["https"]
  service_url         = "http://123.0.0.0:8000"
  subscription_required  = true

  import {
    content_format = "openapi+json"
    # content_value  = file("$(Pipeline.Workspace)/Artifacts/swagger/sample_swagger.json")
    # content_value  = file("/Artifacts/swagger/sample_swagger.json")  -- **this works in local**
    xml_link   = "$(Pipeline.Workspace)/Artifacts/swagger/sample_swagger.json"
  }
}

流水线任务:

- task: ms-devlabs.custom-terraform-tasks.custom-terraform-release-task.TerraformTaskV2@2
  displayName: 'Terraform : plan'
  inputs:
    command: plan
    workingDirectory: '$(System.DefaultWorkingDirectory)/TerraForm'
    environmentServiceNameAzureRM: 'ps-vs-sc'
    backendAzureRmResourceGroupName: '$(rgName)'
    backendAzureRmStorageAccountName: $(strName)
    backendAzureRmContainerName: $(containerName)
    backendAzureRmKey: '$(storagekey)'

我能够使脚本工作的唯一方法是,将 swagger json 上传到存储帐户并使用 SAS 生成 link。用这种方法效果很好。