centos 从crontab运行terraform应用

bwleehnv  于 2022-11-29  发布在  其他
关注(0)|答案(1)|浏览(94)

我正在尝试运行terraform init & plan & apply,当一个新VM启动时,我已经如下设置了crontab:
@reboot username /home/username/script/initial.sh; /home/username/script/terraform-init.sh; /home/username/script/terraform-plan.sh; /home/username/script/terraform-apply.sh

  1. initial.sh setup provider.tf file and it's worked fine.
  2. terraform-init.sh is also fine, i can see .terraform folder and .terraform.lock.hcl file under target folder.
  3. terraform-plan.sh is fine, i can see -out plan file in target folder.
    but the last one terraform-apply.sh not work. the script is like this:
#!/bin/bash
cd /path/to/terraform  
terraform apply -auto-approve

我也试过使用terraform应用"/path/to/plan/file ",但它仍然不起作用。
I can manual run ./terraform-apply.sh and it worked fine. it will output logs under TF_LOG_PATH, but when i reboot vm, no log output in TF_LOG_PATH file.
crontab是否可以触发terraform应用?
谢谢

qltillow

qltillow1#

谢谢大家,我仍然不知道为什么,但是我在我的terraform应用脚本之前添加了“@reboot ecs-user sleep 60 &&“,它成功了!

相关问题