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

Terraform local-exec执行耗时过长问题求助

Terraform null_resource执行Docker镜像构建推送长时间卡住

配置代码

resource "null_resource" "example" {
  provisioner "local-exec" {
    command = <<EOT
      docker build -t imagename -f devops/Dockerfile .
      aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin xxxxx.dkr.ecr.us-east-2.amazonaws.com
      docker tag imagename:latest xxxxx.dkr.ecr.us-east-2.amazonaws.com/imagename:latest
      docker push xxxxx.dkr.ecr.us-east-2.amazonaws.com/imagename:latest
    EOT
    working_dir = "${path.module}/.."
  }
  depends_on = [
    aws_ecr_repository.example
  ]
}

resource "aws_instance" "example" {
  # ... instance configuration ...
  
  depends_on = [
    null_resource.example
  ]
}

需求说明

需先执行Docker镜像构建并推送至AWS ECR仓库,AWS实例需在null_resource执行完成后再创建。

当前问题

该null_resource已运行17分钟仍未结束,执行日志如下:

null_resource.example: Still creating... [30s elapsed]
null_resource.example: Still creating... [40s elapsed]
null_resource.example: Still creating... [50s elapsed]
null_resource.example: Still creating... [1m50s elapsed]
null_resource.example: Still creating... [2m50s elapsed]
null_resource.example: Still creating... [3m0s elapsed]
null_resource.example: Still creating... [4m0s elapsed]
null_resource.example: Still creating... [5m0s elapsed]
null_resource.example: Still creating... [6m0s elapsed]
null_resource.example: Still creating... [16m51s elapsed]
null_resource.example: Still creating... [17m1s elapsed]
null_resource.example: Still creating... [17m11s elapsed]

排查信息

  • 在Windows10的Cmder中手动执行相同命令可正常完成,2.85GB的镜像仅需3分钟构建完成。
  • null_resource已配置依赖ECR仓库,确保仓库创建完成后才执行推送。
  • 移除null_resource后,Terraform可正常创建EC2实例和ECR仓库。

内容的提问来源于stack exchange,提问作者KD.S.T.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 04:13:10