Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

49 рядки
1.3 KiB

  1. #!/usr/bin/env bash
  2. # ENV Vars:
  3. # TERRAFORM_FILE - defaults to "infra.tf"
  4. # - specify state file to pass to terraform
  5. export TERRAFORM_FILE="${TERRAFORM_FILE:-infra.tf}"
  6. export TERRAFORM_ACTION="${TERRAFORM_ACTION:-apply}"
  7. run_terraform() {
  8. INOPTS=( "$@" )
  9. if [ -d "${INOPTS[-1]}" ]
  10. then
  11. DIR="${INOPTS[-1]}"
  12. unset 'INOPTS[${#}-1]'
  13. else
  14. DIR="."
  15. fi
  16. # Plaintext vault decryption key, not checked into SCM
  17. if time terraform init -get=true -get-plugins=true -reconfigure -upgrade -verify-plugins=true "${INOPTS[@]}" "${DIR}"; then
  18. time terraform fmt -list=true -check -recursive "${DIR}"
  19. fi
  20. coderun=$?
  21. if [ $coderun ]
  22. then
  23. time terraform validate "${DIR}"
  24. coderun=$?
  25. if [ $coderun ]
  26. then
  27. if [ $TERRAFORM_ACTION == "destroy" ]
  28. then
  29. time terraform plan -${TERRAFORM_ACTION} -input=false "${INOPTS[@]}" "${DIR}" \
  30. && time terraform ${TERRAFORM_ACTION} -auto-approve -input=false "${INOPTS[@]}" "${DIR}"
  31. else
  32. rm terraform.tfstate*
  33. time terraform plan -input=false "${INOPTS[@]}" "${DIR}" \
  34. && time terraform ${TERRAFORM_ACTION} -auto-approve -input=false "${INOPTS[@]}" "${DIR}"
  35. fi
  36. return $?
  37. fi
  38. else
  39. return $codefmt
  40. fi
  41. }
  42. run_terraform "$@"
  43. retcode=$?
  44. exit $retcode