Skip to content

Commit

Permalink
added scalr script and action
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa6765 committed Sep 9, 2024
1 parent b833718 commit 1eb324d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/terraform-terragrunt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"dev": {
"TF_WORKSPACE": "terrant-dev",
"TG_WORKDIR": "environment/dev"
},
"scalr-remote-backend": {
"TF_WORKSPACE": "terrant-stage",
"TG_WORKDIR": "environment/stage"
}
}
}
25 changes: 25 additions & 0 deletions environment/stage/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 1eb324d

Please sign in to comment.