Skip to content

Terraform Terragrunt Action #38

Terraform Terragrunt Action

Terraform Terragrunt Action #38

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: ${{ secrets.THE_TG_VERSION }}
THE_TF_VERSION: ${{ secrets.THE_TF_VERSION }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Print Terraform and Terragrunt versions
run: |

Check failure on line 22 in .github/workflows/terraform-terragrunt.yml

View workflow run for this annotation

GitHub Actions / Terraform Terragrunt Action

Invalid workflow file

The workflow is not valid. .github/workflows/terraform-terragrunt.yml (Line: 22, Col: 14): Unexpected symbol: 'THE_TF_VERSION:0:1'. Located at position 5 within expression: env.THE_TF_VERSION:0:1 .github/workflows/terraform-terragrunt.yml (Line: 28, Col: 14): Unrecognized named-value: 'UPPER_BRANCH_NAME'. Located at position 9 within expression: secrets[UPPER_BRANCH_NAME + '_TF_WORKSPACE']
echo "Terraform Version: ${{ env.THE_TF_VERSION:0:1 }}***"
echo "Terragrunt Version: ${{ env.THE_TG_VERSION:0:1 }}***"
- name: Set Terraform workspace based on branch
id: set-workspace
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
UPPER_BRANCH_NAME=${BRANCH_NAME^^}
echo "TF_WORKSPACE=${{ secrets[UPPER_BRANCH_NAME + '_TF_WORKSPACE'] }}" >> $GITHUB_ENV
echo "TG_WORKDIR=${{ secrets[UPPER_BRANCH_NAME + '_TG_WORKDIR'] }}" >> $GITHUB_ENV
- 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 }}/${{ env.TG_WORKDIR }}
terragrunt init --terragrunt-non-interactive
echo "🔧 Terragrunt init completed!"
- name: Terragrunt plan
run: |
cd ${{ github.workspace }}/${{ env.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!"