Skip to content

Commit ff8ff6f

Browse files
committed
fix: improve iac bin to toggle between opentofu/terraform images
1 parent 6334259 commit ff8ff6f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

bin/iac

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,30 @@
2323
# alias tofu="iac tofu"
2424
# alias yc="iac yc"
2525

26-
export DEVOPS_AWS_IMAGE="${DEVOPS_AWS_IMAGE:-"devopsinfra/docker-terragrunt"}"
2726
export OPENTOFU_VERSION="${OPENTOFU_VERSION:-"1.8.4"}"
28-
export TERRAGRUNT_VERSION="${TERRAGRUNT_VERSION:-"0.68.5"}"
27+
export TERRAFORM_VERSION="${TERRAFORM_VERSION:-"1.9.8"}"
28+
export TERRAGRUNT_VERSION="${TERRAGRUNT_VERSION:-"0.68.7"}"
2929
export CLOUD_API="${CLOUD_API:-"aws"}" # aws, azure, gcp, yc
30-
export CLOUD_SDK="${CLOUD_SDK:-"ot"}" # ot, tf (for OpenTofu or Terraform)
31-
export DEVOPS_AWS_VERSION="${DEVOPS_AWS_VERSION:-"${CLOUD_API}-${CLOUD_SDK}-${OPENTOFU_VERSION}-tg-${TERRAGRUNT_VERSION}"}"
3230

3331
main() {
3432
if [ "$(whoami)" == "runner" ]; then
3533
: # echo "Don't execute in GitHub Actions workflow runs."
3634
else
35+
# Image platform.
36+
_MACH="${UMACH:-${MACHTYPE:-$(uname -m 2>/dev/null)}}"
37+
_PLATFORM="linux/$_MACH"
38+
[[ "${UTYPE:-}" == "darwin"* ]] && _PLATFORM="aarch64/$_MACH"
39+
# OpenTofu (default) or Terraform.
40+
_SDK_TAG="ot-${OPENTOFU_VERSION}"
41+
[[ "${*}" == "terraform "* ]] && _SDK_TAG="tf-${TERRAFORM_VERSION}"
42+
_IMAGE_TAG="${CLOUD_API}-${_SDK_TAG}-tg-${TERRAGRUNT_VERSION}"
43+
# Build/run options.
3744
local OPTS=()
3845
OPTS+=(--rm)
3946
[[ -z "$PS1" ]] && OPTS+=(-it)
4047
OPTS+=(-u "$(id -u):$(id -g)")
4148
OPTS+=(-v "$(pwd):/data")
49+
# OPTS+=(--platform "$_PLATFORM")
4250
[[ -e ~/.gitconfig ]] && OPTS+=(-v ~/.gitconfig:/root/.gitconfig)
4351
[[ -e ~/.ssh/id_rsa_shared ]] && OPTS+=(-v ~/.ssh/id_rsa_shared:/root/.ssh/id_rsa)
4452
[[ -e ~/.aws/credentials ]] && OPTS+=(-v ~/.aws/credentials:/root/.aws/credentials)
@@ -47,7 +55,9 @@ main() {
4755
[[ -n "${AWS_ACCESS_KEY_ID:-}" ]] && OPTS+=(-e "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}")
4856
[[ -n "${AWS_SECRET_ACCESS_KEY:-}" ]] && OPTS+=(-e "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}")
4957
[[ -n "${AWS_SESSION_TOKEN:-}" ]] && OPTS+=(-e "AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}")
50-
docker run "${OPTS[@]}" "${DEVOPS_AWS_IMAGE}:${DEVOPS_AWS_VERSION}" "$@"
58+
# Uncomment to debug the final command.
59+
# echo "docker run ${OPTS[*]} devopsinfra/docker-terragrunt:${_IMAGE_TAG} ${*}"
60+
docker run "${OPTS[@]}" "devopsinfra/docker-terragrunt:${_IMAGE_TAG}" "$@"
5161
fi
5262
}
5363

0 commit comments

Comments
 (0)