From f59e94a7b7ac1cddf0b9ec1dd55b85e0363d3300 Mon Sep 17 00:00:00 2001 From: Mostafa Kamal Date: Tue, 2 Jul 2024 01:03:45 +0600 Subject: [PATCH] action and readme --- .github/workflows/terraform-terragrunt.yml | 24 +++++++++++++++++----- README.md | 12 ++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.github/workflows/terraform-terragrunt.yml b/.github/workflows/terraform-terragrunt.yml index b1b8a00..86394ad 100644 --- a/.github/workflows/terraform-terragrunt.yml +++ b/.github/workflows/terraform-terragrunt.yml @@ -4,20 +4,34 @@ on: push: branches: - main + - stage + - dev workflow_dispatch: # Triggered manually from GitHub UI jobs: terraform: runs-on: ubuntu-latest env: - TF_WORKSPACE: terragrunt - # https://terragrunt.gruntwork.io/docs/getting-started/supported-versions/ 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 + elif [[ "$BRANCH_NAME" == "stage-project" ]]; then + echo "TF_WORKSPACE=stage" >> $GITHUB_ENV + elif [[ "$BRANCH_NAME" == "dev-project" ]]; then + echo "TF_WORKSPACE=dev" >> $GITHUB_ENV + else + echo "TF_WORKSPACE=default" >> $GITHUB_ENV + fi + - name: Set up Terraform CLI uses: hashicorp/setup-terraform@v3 with: @@ -39,14 +53,14 @@ jobs: - name: Terragrunt init run: | - cd ./environment/stage + cd ./environment/${{ env.TF_WORKSPACE }} terragrunt init --terragrunt-non-interactive echo "🔧 Terragrunt init completed!" - name: Terragrunt plan run: | - cd ./environment/stage - terragrunt plan --terragrunt-non-interactive + cd ./environment/${{ env.TF_WORKSPACE }} + terragrunt plan --terragrunt-non-interactive echo "📝 Terragrunt plan completed!" - name: Display success message diff --git a/README.md b/README.md index 3f80759..05b48a6 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,17 @@ terrafrom-terragrunt-aws-project │ ├── common │ │ └── common-resources.tf │ ├── stage -│ │ ├── modules (symlink with root modules) -│ │ ├── common-*.tf (symlink with common) +│ │ ├── modules (symlink with root modules via script) +│ │ ├── common-*.tf (symlink with common via script) │ │ ├── main.tf -│ │ └── variables.tf +│ │ ├── variables.tf +│ │ └── output.tf │ └── prod -│ ├── modules (symlink with root modules) +│ ├── modules (symlink with root modules via script) │ ├── common-*.tf (symlink with common) │ ├── main.tf -│ └── variables.tf +│ ├── variables.tf +│ └── output.tf └── environment ├── stage │ └── terragrunt.hcl