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

使用azurerm_container_registry_task_schedule_run_now致Terraform崩溃但Azure任务成功

Terraform创建ACR任务并触发即时运行时崩溃,但任务实际执行成功

问题描述

我正在开发一个需要在Azure容器注册表(ACR)中构建镜像的项目,使用Terraform创建容器注册表、构建任务并触发即时运行。目前出现Terraform崩溃的问题,但登录Azure控制台查看时,任务已正常运行并执行成功。

当前临时解决方案是拆分两个Terraform项目,其中一个仅包含azurerm_container_registry_task_schedule_run_now资源,并通过Shell脚本运行该项目时忽略错误,但此方案并不理想。

崩溃错误信息

╷
│ Error: Plugin did not respond
│
│   with module.microservice.azurerm_container_registry_task_schedule_run_now.run-build[3],
│   on microservice/acr.tf line 29, in resource "azurerm_container_registry_task_schedule_run_now" "run-build":
│   29: resource "azurerm_container_registry_task_schedule_run_now" "run-build" {
│
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵

Stack trace from the terraform-provider-azurerm_v3.67.0_x5 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x4ffaf9e]

goroutine 1622 [running]:
github.com/hashicorp/terraform-provider-azurerm/internal/services/containers.ContainerRegistryTaskScheduleResource.Create.func1({0x7713d48, 0xc002deb3b0}, {0xc002fb6000, {0x77145d0, 0xc000401c20}, 0xc002b4de80, 0x0, {0x7715750, 0xbe5a248}})
        github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/container_registry_task_schedule_run_now_resource.go:107 +0x83e
github.com/hashicorp/terraform-provider-azurerm/internal/sdk.(*ResourceWrapper).Resource.func2({0x7713d48, 0xc002deb3b0}, 0x7713d80?, {0x62b4360?, 0xc002fb6000?})
        github.com/hashicorp/terraform-provider-azurerm/internal/sdk/wrapper_resource.go:55 +0x163
github.com/hashicorp/terraform-provider-azurerm/internal/sdk.diagnosticsWrapper.func1({0x7713d48, 0xc002deb3b0}, 0x0?, {0x62b4360, 0xc002fb6000})
        github.com/hashicorp/terraform-provider-azurerm/internal/sdk/wrapper_resource.go:188 +0xb8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc000317960, {0x7713d80, 0xc002dea930}, 0xd?, {0x62b4360, 0xc002fb6000})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:707 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000317960, {0x7713d80, 0xc002dea930}, 0xc00284d110, 0xc002b4db80, {0x62b4360, 0xc002fb6000})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:837 +0xa85
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0013f1a70, {0x7713d80?, 0xc002dea810?}, 0xc002f29e50)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/grpc_provider.go:1021 +0xe8d
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc00061d7c0, {0x7713d80?, 0xc002dea000?}, 0xc002dd28c0)
        github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:818 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x6b08bc0?, 0xc00061d7c0}, {0x7713d80, 0xc002dea000}, 0xc002dd2850, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001d41e0, {0x7724700, 0xc0019809c0}, 0xc0031b8ea0, 0xc0017683c0, 0xbe1a620, 0x0)
        google.golang.org/grpc@v1.53.0/server.go:1336 +0xd33
google.golang.org/grpc.(*Server).handleStream(0xc0001d41e0, {0x7724700, 0xc0019809c0}, 0xc0031b8ea0, 0x0)
        google.golang.org/grpc@v1.53.0/server.go:1704 +0xa36
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.53.0/server.go:965 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.53.0/server.go:963 +0x28a

Error: The terraform-provider-azurerm_v3.67.0_x5 plugin crashed!

触发错误的Terraform代码

resource "azurerm_container_registry" "registry" {
  name                = "${var.acr_name}${var.random}"
  resource_group_name = azurerm_resource_group.rg.name
  location            = azurerm_resource_group.rg.location
  admin_enabled       = var.acr_admin_enabled
  sku                 = var.acr_sku

  depends_on = [azurerm_resource_group.rg]
}

resource "azurerm_container_registry_task" "build" {
  count                 = length(var.images_url)
  name                  = "build-${var.images[count.index]}"
  container_registry_id = azurerm_container_registry.registry.id
  platform {
    os = "Linux"
  }

  docker_step {
    dockerfile_path      = "Dockerfile"
    context_path         = var.images_url[count.index]
    context_access_token = var.GITLAB_ACCESS_TOKEN
    image_names          = ["${azurerm_container_registry.registry.login_server}/${var.images[count.index]}:latest"]
  }

  depends_on = [azurerm_container_registry.registry]
}

resource "azurerm_container_registry_task_schedule_run_now" "run-build" {
  count                      = length(var.images)
  container_registry_task_id = azurerm_container_registry_task.build[count.index].id

  depends_on = [azurerm_container_registry_task.build]
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 13:44:58