英文:
why is terraform local-exec is taking forever to finish
问题
以下是您提供的Terraform配置文件的翻译部分:
资源 "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
]
}
资源 "aws_instance" "example" {
# ... 实例配置 ...
depends_on = [
null_resource.example
]
}
这是您的Terraform配置文件的一部分,用于构建Docker镜像并将其推送到ECR。AWS实例将在null_resource完成后创建。
如果您移除null_resource,它将运行得很完美,创建EC2实例和ECR仓库。
英文:
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
]
}
This is a fraction of my terraform. So basically I need to run docker build then docker push to ecr.
The aws_instance will be created after null_resource is done.
it has been running for 17mins
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]
I run the commands in my cmder, in windows10. It works perfect. The size of image is 2.85GB it took only 3mins to build the image.
My null_resource is also depending on ecr, so when ecr is done creating the repo, its possible to docker push
if i remove null_resource, it runs perfectly, it creates ec2 and ecr.
答案1
得分: 1
去掉EOT后面的空格对我有效。检查以下更新后的资源块:
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
]
}
英文:
Remove the white space in front of the closing EOT works for me.
Check the updated resource block as below:
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
]
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论