Skip to content

Terraform Terragrunt Action #61

Terraform Terragrunt Action

Terraform Terragrunt Action #61

name: Terraform Terragrunt Action
on:
# push:
# branches:
# - main
# - stage
# - dev
workflow_dispatch:
jobs:
terraform:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up jq
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: Load configuration from config.json
id: load-config
run: |
CONFIG_FILE="${GITHUB_WORKSPACE}/config.json"
TF_VERSION=$(jq -r '.terraform_version' $CONFIG_FILE)
TG_VERSION=$(jq -r '.terragrunt_version' $CONFIG_FILE)
BRANCH_NAME=${GITHUB_REF#refs/heads/}
BRANCH_CONFIG=$(jq -r --arg branch "$BRANCH_NAME" '.branches[$branch] // .branches.default' $CONFIG_FILE)
TF_WORKSPACE=$(echo $BRANCH_CONFIG | jq -r '.TF_WORKSPACE')
TG_WORKDIR=$(echo $BRANCH_CONFIG | jq -r '.TG_WORKDIR')
echo "TG_WORKDIR=$TG_WORKDIR" >> $GITHUB_ENV
echo "TF_VERSION=$TF_VERSION" >> $GITHUB_ENV
echo "TG_VERSION=$TG_VERSION" >> $GITHUB_ENV
echo "THE_TF_WORKSPACE=$TF_WORKSPACE" >> $GITHUB_ENV
- name: Set up Terraform CLI with scalr
uses: Scalr/scalr-action@v1
with:
iac_platform: "terraform"
binary_version: ${{ env.TF_VERSION }}
scalr_hostname: ${{ secrets.SCALR_HOSTNAME }}
scalr_token: ${{ secrets.SCALR_API_TOKEN }}
scalr_workspace: ${{ env.THE_TF_WORKSPACE }}
binary_wrapper: true
- name: Set up Terraform CLI
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
terraform_wrapper: true
cli_config_credentials_hostname: ${{ secrets.SCALR_HOSTNAME }}
cli_config_credentials_token: ${{ secrets.SCALR_API_TOKEN }}
- name: Set up Terragrunt CLI
run: |
wget -qO /tmp/terragrunt https://github.com/gruntwork-io/terragrunt/releases/download/v${{ env.TG_VERSION }}/terragrunt_linux_amd64
sudo chmod +x /tmp/terragrunt
sudo mv /tmp/terragrunt /usr/local/bin/terragrunt
echo "✅ Terragrunt CLI setup completed!"
- name: Run symlink-modules.sh
run: |
./symlink-modules.sh
echo "🔗 Symlink modules completed!"
- name: Terragrunt init
run: |
cd ${{ github.workspace }}/$TG_WORKDIR
terragrunt init --terragrunt-non-interactive
echo "🔧 Terragrunt init completed!"
- name: Terragrunt plan
run: |
cd ${{ github.workspace }}/$TG_WORKDIR
terragrunt plan --terragrunt-non-interactive
echo "📝 Terragrunt plan completed!"
- name: Display success message
if: github.event_name == 'workflow_dispatch'
run: |
echo "🚀 Terraform Terragrunt Action triggered manually!"