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

能否通过Terraform创建Azure Load Testing中的测试?

能否通过Terraform在Azure Load Testing资源下创建测试?

目前AzureRM Terraform Provider没有直接提供创建Azure Load Testing测试(对应你用Azure CLI执行的az load test create操作)的原生资源类型。

不过可以通过以下替代方案实现:

方案1:使用local-exec调用Azure CLI

在Terraform配置中,借助local-exec provisioner直接调用Azure CLI命令来创建测试,示例配置如下:

# 创建资源组
resource "azurerm_resource_group" "sample_rg" {
  name     = "sample-rg"
  location = "westus2"
}

# 创建Azure Load Testing资源
resource "azurerm_load_test" "sample_resource" {
  name                = "sample-resource"
  resource_group_name = azurerm_resource_group.sample_rg.name
  location            = azurerm_resource_group.sample_rg.location
}

# 通过local-exec调用CLI创建测试
resource "null_resource" "create_load_test" {
  depends_on = [azurerm_load_test.sample_resource]

  provisioner "local-exec" {
    command = <<EOT
az load test create --test-id sample-test-id --load-test-resource ${azurerm_load_test.sample_resource.name} --resource-group ${azurerm_resource_group.sample_rg.name} --display-name "Find IP" --description "Test description" --test-plan IPLoadTesting.jmx --engine-instances 1 --env rps=2 count=1
EOT
  }
}

注意:使用该方案需要确保Terraform执行环境已安装并配置好Azure CLI,且具备对应的Azure权限。

方案2:调用Azure REST API

如果不想依赖Azure CLI,也可以通过Terraform的http资源或local-exec调用Azure Load Testing的REST API来创建测试,不过需要自行处理身份验证和请求参数,相对复杂一些。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 17:14:58