Skip to content

workdir tg

workdir tg #35

name: Terraform Terragrunt Action
on:
push:
branches:
- main
- stage
- dev
workflow_dispatch: # Triggered manually from GitHub UI
jobs:
terraform:
runs-on: ubuntu-latest
env:
THE_TG_VERSION: 0.57.0
THE_TF_VERSION: 1.8.0
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set Terraform workspace based on branch
id: set-workspace
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
if [[ "$BRANCH_NAME" == "main" ]]; then
echo "TF_WORKSPACE=prod-project" >> $GITHUB_ENV
echo "TG_WORKDIR=environment/stage" >> $GITHUB_ENV
elif [[ "$BRANCH_NAME" == "stage" ]]; then
echo "TF_WORKSPACE=stage-project" >> $GITHUB_ENV
echo "TG_WORKDIR=environment/stage" >> $GITHUB_ENV
elif [[ "$BRANCH_NAME" == "dev" ]]; then
echo "TF_WORKSPACE=dev-project" >> $GITHUB_ENV
echo "TG_WORKDIR=environment/dev" >> $GITHUB_ENV
else
echo "TF_WORKSPACE=default" >> $GITHUB_ENV
echo "TG_WORKDIR=environment/default" >> $GITHUB_ENV
fi
- name: Set up Terraform CLI
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.THE_TF_VERSION }}
terraform_wrapper: true
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Set up Terragrunt CLI
run: |
wget -qO /tmp/terragrunt https://github.com/gruntwork-io/terragrunt/releases/download/v${{ env.THE_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!"