From 8d5e8ee0864fdc53829d0e1cafac6ad75c5bc6e2 Mon Sep 17 00:00:00 2001 From: Mostafa Kamal Date: Mon, 2 Sep 2024 19:13:57 +0600 Subject: [PATCH] github action -> doc added --- README.md | 100 ++++++++++++++++++++---------------------------------- 1 file changed, 37 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index aca4300..4657ec7 100644 --- a/README.md +++ b/README.md @@ -38,79 +38,53 @@ terrafrom-terragrunt-aws-project --- -# Terraform Terragrunt GitHub Actions Workflow - -This repository contains a GitHub Actions workflow to automate Terraform and Terragrunt operations for different environments. The workflow requires certain GitHub secrets to be configured. +# Run GitHub Action (Terragrunt Plan and Apply) ## Setting Up GitHub Secrets -To use this workflow, you'll need to configure the following secrets in your GitHub repository: - -### 1. Terraform and Terragrunt Versions - -- **`THE_TG_VERSION`**: The version of Terragrunt to use (e.g., `0.57.0`). -- **`THE_TF_VERSION`**: The version of Terraform to use (e.g., `1.8.0`). - -### 2. Terraform Cloud API Token - -- **`TF_API_TOKEN`**: A Terraform Cloud API token used for authentication. - -### 3. Environment-Specific Secrets - -These secrets should be named according to the branch they correspond to (`main`, `stage`, or `dev`): - -- **`MAIN_TF_WORKSPACE`**: The Terraform workspace for the `main` branch. -- **`MAIN_TG_WORKDIR`**: The Terragrunt working directory for the `main` branch. - -- **`STAGE_TF_WORKSPACE`**: The Terraform workspace for the `stage` branch. -- **`STAGE_TG_WORKDIR`**: The Terragrunt working directory for the `stage` branch. - -- **`DEV_TF_WORKSPACE`**: The Terraform workspace for the `dev` branch. -- **`DEV_TG_WORKDIR`**: The Terragrunt working directory for the `dev` branch. - -### How to Set Up Secrets in GitHub - -1. Navigate to your repository on GitHub. -2. Click on the **Settings** tab. -3. In the left sidebar, click on **Secrets and variables** > **Actions**. -4. Click the **New repository secret** button. -5. Add each secret by specifying its name and value, then click **Add secret**. - -### Example Secret Configuration - -For a repository that uses Terraform and Terragrunt, you would configure secrets as follows: - -- **Secret Name**: `THE_TG_VERSION` - - **Value**: `0.57.0` - -- **Secret Name**: `THE_TF_VERSION` - - **Value**: `1.8.0` - -- **Secret Name**: `TF_API_TOKEN` - - **Value**: `` +To ensure that the GitHub Action workflow runs correctly, you need to set up the following GitHub secret: -- **Secret Name**: `MAIN_TF_WORKSPACE` - - **Value**: `prod-project` +- **`TF_API_TOKEN`**: This is a Terraform Cloud API token used for authentication. -- **Secret Name**: `MAIN_TG_WORKDIR` - - **Value**: `environment/prod` + **Steps to Add the Secret**: + 1. Navigate to your GitHub repository. + 2. Click on the "Settings" tab. + 3. In the left sidebar, click on "Secrets and variables" and then "Actions". + 4. Click on the "New repository secret" button. + 5. Enter `TF_API_TOKEN` as the secret name and provide your Terraform Cloud API token as the value. + 6. Click "Add secret" to save it. -- **Secret Name**: `STAGE_TF_WORKSPACE` - - **Value**: `stage-project` +## Update Config File -- **Secret Name**: `STAGE_TG_WORKDIR` - - **Value**: `environment/stage` +The `config.json` file contains essential configurations for Terraform and Terragrunt. You should update this file to match your environment and branch-specific settings. -- **Secret Name**: `DEV_TF_WORKSPACE` - - **Value**: `dev-project` +### Config File Structure -- **Secret Name**: `DEV_TG_WORKDIR` - - **Value**: `environment/dev` +Here is the format for `config.json`: -## Usage +```json +{ + "terraform_version": "1.8.0", + "terragrunt_version": "0.57.0", + "branches": { + "main": { + "TF_WORKSPACE": "prod-project", + "TG_WORKDIR": "environment/stage" + }, + "stage": { + "TF_WORKSPACE": "stage-project", + "TG_WORKDIR": "environment/stage" + }, + "dev": { + "TF_WORKSPACE": "dev-project", + "TG_WORKDIR": "environment/dev" + }, + "default": { + "TF_WORKSPACE": "default", + "TG_WORKDIR": "environment/default" + } + } +} -Once the secrets are configured, the workflow will automatically pick them up and run Terraform and Terragrunt operations when changes are pushed to the `main`, `stage`, or `dev` branches. -## License -This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.