Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: (issue#48) Add option to install Python3 for projects using TF Lambda module #49

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
23 changes: 22 additions & 1 deletion src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand Down