diff --git a/README.md b/README.md index 865ceba..d50aac2 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,17 @@ A GitHub Action for installing and running Terragrunt Supported GitHub action inputs: -| Input Name | Description | Required | Example values | -|:---------------|:------------------------------------------------------------------|:-----------------------------------------:|:--------------:| -| tf_version | Terraform version to be used in Action execution | `true` if `tofu_version` is not supplied | 1.4.6 | -| tofu_version | OpenTofu version to be used in Action execution | `true` if `tf_version` is not supplied | 1.6.0 | -| tg_version | Terragrunt version to be user in Action execution | `true` | 0.50.8 | -| tg_dir | Directory in which Terragrunt will be invoked | `true` | work | -| tg_command | Terragrunt command to execute | `true` | plan/apply | -| tg_comment | Add comment to Pull request with execution output | `false` | 0/1 | -| tg_add_approve | Automatically add "-auto-approve" to commands, enabled by default | `false` | 0/1 | +| Input Name | Description | Required | Example values | +|:--------------------|:------------------------------------------------------------------|:-----------------------------------------:|:--------------:| +| tf_version | Terraform version to be used in Action execution | `true` if `tofu_version` is not supplied | 1.4.6 | +| tofu_version | OpenTofu version to be used in Action execution | `true` if `tf_version` is not supplied | 1.6.0 | +| tg_version | Terragrunt version to be user in Action execution | `true` | 0.50.8 | +| tg_dir | Directory in which Terragrunt will be invoked | `true` | work | +| tg_command | Terragrunt command to execute | `true` | plan/apply | +| tg_comment | Add comment to Pull request with execution output | `false` | 0/1 | +| tg_add_approve | Automatically add "-auto-approve" to commands, enabled by default | `false` | 0/1 | +| tg_install_python_3 | Installs python3 | `false` | 0/1 | +| tg_python_version | Specify which version of Python3 to install (default: 3.10) | `false` | 3.10/3.11 | ## Environment Variables diff --git a/action.yml b/action.yml index 0a2c5b4..93ce036 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,14 @@ inputs: description: 'Add -auto-approve to commands which require changes to be applied' default: '1' required: false + tg_install_python_3: + description: 'Wheteher or not to install Python 3' + default: '0' + required: false + tg_python_version: + description: 'What version of python3 to install' + default: '3.10' + required: false outputs: tg_action_output: description: 'Terragrunt execution output' diff --git a/src/main.sh b/src/main.sh index 71d43a2..701f976 100755 --- a/src/main.sh +++ b/src/main.sh @@ -144,6 +144,16 @@ function setup_post_exec { done <<< "$post_exec_vars" } +# Install python 3.10 or 3.11 +function install_python { + local -r version="$1" + sudo apt update + sudo apt install python"${version}" -y + sudo update-alternatives --install /usr/bin/python3 python /usr/bin/python"${version}" 1 + sudo update-alternatives --set python /usr/bin/python"${version}" +} + + function main { log "Starting Terragrunt Action" trap 'log "Finished Terragrunt Action execution"' EXIT @@ -154,7 +164,9 @@ function main { local -r tg_comment=${INPUT_TG_COMMENT:-0} local -r tg_add_approve=${INPUT_TG_ADD_APPROVE:-1} local -r tg_dir=${INPUT_TG_DIR:-.} - + local -r tg_install_python_3=${INPUT_TG_INSTALL_PYTHON_3} + local -r tg_python_version=${INPUT_TG_PYTHON_VERSION} + if [[ (-z "${tf_version}") && (-z "${tofu_version}")]]; then log "One of tf_version or tofu_version must be set" exit 1 @@ -174,6 +186,15 @@ function main { log "tg_command is not set" exit 1 fi + + if [[ "${tg_install_python_3}" == "1" ]]; then + if ! [[ "${tg_python_version}" == "3.10" || "${tg_python_version}" == "3.11" ]]; then + log "ERROR: Only python3.10 and python3.11 are allowed. Check https://github.com/gruntwork-io/terragrunt-action?tab=readme-ov-file#inputs" + exit 1 + fi + install_python "${tg_python_version}" + fi + setup_git # fetch the user id and group id under which the github action is running local -r uid=$(stat -c "%u" "/github/workspace")