From 1eb324dfd7258d92436e2c50e0ac1b894334c1aa Mon Sep 17 00:00:00 2001 From: Mostafa Kamal Date: Tue, 10 Sep 2024 01:36:00 +0600 Subject: [PATCH] added scalr script and action --- .github/workflows/terraform-terragrunt.yml | 8 ++++--- config.json | 4 ++++ environment/stage/.terraform.lock.hcl | 25 ++++++++++++++++++++++ run.sh | 6 +++--- 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 environment/stage/.terraform.lock.hcl diff --git a/.github/workflows/terraform-terragrunt.yml b/.github/workflows/terraform-terragrunt.yml index b31e303..677c09f 100644 --- a/.github/workflows/terraform-terragrunt.yml +++ b/.github/workflows/terraform-terragrunt.yml @@ -26,22 +26,24 @@ jobs: 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 "TF_WORKSPACE=$TF_WORKSPACE" >> $GITHUB_ENV + 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 uses: hashicorp/setup-terraform@v3 with: terraform_version: ${{ env.TF_VERSION }} terraform_wrapper: true - cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + cli_config_credentials_hostname: ${{ secrets.SCALR_HOSTNAME }} + cli_config_credentials_token: ${{ secrets.SCALR_API_TOKEN }} - name: Set up Terragrunt CLI run: | diff --git a/config.json b/config.json index feeb546..bd6dd0c 100644 --- a/config.json +++ b/config.json @@ -13,6 +13,10 @@ "dev": { "TF_WORKSPACE": "terrant-dev", "TG_WORKDIR": "environment/dev" + }, + "scalr-remote-backend": { + "TF_WORKSPACE": "terrant-stage", + "TG_WORKDIR": "environment/stage" } } } diff --git a/environment/stage/.terraform.lock.hcl b/environment/stage/.terraform.lock.hcl new file mode 100644 index 0000000..c6e7247 --- /dev/null +++ b/environment/stage/.terraform.lock.hcl @@ -0,0 +1,25 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.66.0" + constraints = "~> 5.0" + hashes = [ + "h1:yGcVdhj9IKbS/b7BSHtgGjCiFnKK+81ImkK/x7UCgEI=", + "zh:071c908eb18627f4becdaf0a9fe95d7a61f69be365080aba2ef5e24f6314392b", + "zh:3dea2a474c6ad4be5b508de4e90064ec485e3fbcebb264cb6c4dec660e3ea8b5", + "zh:56c0b81e3bbf4e9ccb2efb984f8758e2bc563ce179ff3aecc1145df268b046d1", + "zh:5f34b75a9ef69cad8c79115ecc0697427d7f673143b81a28c3cf8d5decfd7f93", + "zh:65632bc2c408775ee44cb32a72e7c48376001a9a7b3adbc2c9b4d088a7d58650", + "zh:6d0550459941dfb39582fadd20bfad8816255a827bfaafb932d51d66030fcdd5", + "zh:7f1811ef179e507fdcc9776eb8dc3d650339f8b84dd084642cf7314c5ca26745", + "zh:8a793d816d7ef57e71758fe95bf830cfca70d121df70778b65cc11065ad004fd", + "zh:8c7cda08adba01b5ae8cc4e5fbf16761451f0fab01327e5f44fc47b7248ba653", + "zh:96d855f1771342771855c0fb2d47ff6a731e8f2fa5d242b18037c751fd63e6c3", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:b2a62669b72c2471820410b58d764102b11c24e326831ddcfae85c7d20795acf", + "zh:b4a6b251ac24c8f5522581f8d55238d249d0008d36f64475beefc3791f229e1d", + "zh:ca519fa7ee1cac30439c7e2d311a0ecea6a5dae2d175fe8440f30133688b6272", + "zh:fbcd54e7d65806b0038fc8a0fbdc717e1284298ff66e22aac39dcc5a22cc99e5", + ] +} diff --git a/run.sh b/run.sh index c0778d3..e2f1b18 100755 --- a/run.sh +++ b/run.sh @@ -23,14 +23,14 @@ done read -p "Select an environment: " ENVIRONMENT # Validate the selected environment -if ! jq -e ".branches.$ENVIRONMENT" "$CONFIG_FILE" > /dev/null; then +if ! jq -e ".branches.\"$ENVIRONMENT\"" "$CONFIG_FILE" > /dev/null; then echo "Error: Invalid environment '$ENVIRONMENT'. Please run the script again and choose a valid environment." exit 1 fi # Extract configurations from config.json -TF_WORKSPACE=$(get_json_value ".branches.$ENVIRONMENT.TF_WORKSPACE" "$CONFIG_FILE") -TG_WORKDIR=$(get_json_value ".branches.$ENVIRONMENT.TG_WORKDIR" "$CONFIG_FILE") +TF_WORKSPACE=$(get_json_value ".branches.\"$ENVIRONMENT\".TF_WORKSPACE" "$CONFIG_FILE") +TG_WORKDIR=$(get_json_value ".branches.\"$ENVIRONMENT\".TG_WORKDIR" "$CONFIG_FILE") TF_VERSION=$(get_json_value ".terraform_version" "$CONFIG_FILE") TG_VERSION=$(get_json_value ".terragrunt_version" "$CONFIG_FILE")