You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform创建Azure API Management默认用stv1?如何指定Azure Rest API版本?

关于Azure API Management stv2平台与Terraform AzureRM Provider API版本的问题

1. 2022年年中创建的APIM实例默认未采用stv2的原因

微软是分阶段向stv2平台切换默认配置的,不同Azure区域启用stv2作为新APIM实例默认平台的时间节点不同。2022年年中时,多数区域仍以stv1为默认创建平台,stv2的默认推广是逐步完成的,后续才在全球范围内将stv2设为新实例的默认选项。

2. 能否指定AzureRM Provider使用的Azure REST API版本

可以通过两种方式控制:

  • 锁定AzureRM Provider版本:每个Terraform AzureRM Provider版本都绑定了固定的Azure REST API版本集,在required_providers块中指定具体的Provider版本,即可间接控制使用的API版本。例如:
    terraform {
      required_providers {
        azurerm = {
          source  = "hashicorp/azurerm"
          version = "3.0.0" # 该版本对应特定的Azure API版本集
        }
      }
    }
    
  • 针对特定资源指定API版本:部分AzureRM资源支持直接在资源块中设置api_version参数,强制该资源使用指定版本的Azure REST API。以APIM资源为例:
    resource "azurerm_api_management" "example" {
      name                = "example-apim"
      location            = azurerm_resource_group.example.location
      resource_group_name = azurerm_resource_group.example.name
      publisher_name      = "Example Publisher"
      publisher_email     = "publisher@example.com"
      api_version         = "2023-03-01-preview" # 指定API版本
    }
    
    注意:并非所有资源都支持该参数,具体需参考对应资源的Terraform文档。

迁移到stv2平台的操作指南

如何迁移到stv2平台?

你可以通过Azure门户、Azure PowerShell、Azure CLI或REST API将API管理实例从stv1迁移到stv2平台。迁移过程不会造成中断,无需停机。

注意

  • 仅支持Premium、Standard、Basic和Developer层的API管理实例进行迁移。消费层实例已运行在stv2平台上。
  • 不支持从stv2迁回stv1。
  • 迁移期间,无法缩放实例或更改其层级。
  • 迁移可能需要长达30分钟才能完成。

Azure门户

  1. 在Azure门户中,导航到你的API管理实例。
  2. 在“设置”下选择“缩放”。
  3. 在“缩放”页面,点击“迁移到stv2”按钮。
  4. 查看迁移详情,然后选择“迁移”。

Azure PowerShell

使用Update-AzApiManagement cmdlet,将-PlatformVersion参数设置为stv2。

Update-AzApiManagement -ResourceGroupName "myResourceGroup" -Name "myApiManagement" -PlatformVersion "stv2"

Azure CLI

使用az apim update命令,将--platform-version参数设置为stv2。

az apim update --resource-group myResourceGroup --name myApiManagement --platform-version stv2

REST API

使用API管理的更新REST API操作,将properties.platformVersion属性设置为stv2。

PATCH https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}?api-version=2021-08-01
Content-Type: application/json

{
  "properties": {
    "platformVersion": "stv2"
  }
}

内容的提问来源于stack exchange,提问作者djflocko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 03:23:30