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
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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` | 1.4.6 |
| 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 |
| Input Name | Description | Required | Example values |
|:------------------|:------------------------------------------------------------|:--------:|:--------------:|
| tf_version | Terraform version to be used in Action execution | `true` | 1.4.6 |
| 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_python | Installs python3 | `false` | 0/1 |
| tg_python_version | Specify which version of Python3 to install (default: 3.10) | `false` | 10/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 @@ -23,6 +23,14 @@ inputs:
description: 'Include execution output as comment'
default: '0'
required: false
tg_python:
description: 'Install Python 3'
default: '0'
required: false
tg_python_version:
description: 'What version of python3 to install'
default: '10'
required: false
outputs:
tg_action_output:
description: 'Terragrunt execution output'
Expand Down
24 changes: 23 additions & 1 deletion src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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 python3."${version}" -y
sudo update-alternatives --install /usr/bin/python3 python /usr/bin/python3."${version}" 1
sudo update-alternatives --set python /usr/bin/python3."${version}"
}


function main {
log "Starting Terragrunt Action"
trap 'log "Finished Terragrunt Action execution"' EXIT
Expand All @@ -126,7 +136,9 @@ function main {
local -r tg_command=${INPUT_TG_COMMAND}
local -r tg_comment=${INPUT_TG_COMMENT:-0}
local -r tg_dir=${INPUT_TG_DIR:-.}

local -r tg_python=${INPUT_TG_PYTHON}
local -r tg_python_version=${INPUT_TG_PYTHON_VERSION}

if [[ -z "${tf_version}" ]]; then
log "tf_version is not set"
exit 1
Expand All @@ -141,6 +153,16 @@ function main {
log "tg_command is not set"
exit 1
fi

if [[ "${tg_python}" == "1" ]]; then
if ! [[ "${tg_python_version}" == "10" || "${tg_python_version}" == "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}"
exit 0
fi

setup_git
setup_pre_exec

Expand Down