Skip to content

Commit

Permalink
Merge branch 'main' into task/rollout-aurora-db-part-two/CDD-1750
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Ashiq authored May 3, 2024
2 parents af30bdb + d365597 commit 2db6e07
Show file tree
Hide file tree
Showing 41 changed files with 1,049 additions and 368 deletions.
8 changes: 8 additions & 0 deletions .github/actions/configure-aws-credentials/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ inputs:
aws-region:
description: "The AWS region to configure credentials in."
required: true
role-duration-seconds:
description: "The assumed role duration in seconds. Defaults to 1 hour."
default: "3600"

# Note that the roles are optional by default.
# When using this composite action, you must pass in the role you need
Expand Down Expand Up @@ -38,6 +41,7 @@ runs:
with:
role-to-assume: ${{ inputs.tools-account-role }}
aws-region: ${{ inputs.aws-region }}
role-duration-seconds: ${{ inputs.role-duration-seconds }}

- name: Configure AWS credentials for prod account
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -46,6 +50,7 @@ runs:
role-to-assume: ${{ inputs.prod-account-role }}
aws-region: ${{ inputs.aws-region }}
role-chaining: true
role-duration-seconds: ${{ inputs.role-duration-seconds }}

- name: Configure AWS credentials for dev account
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -54,6 +59,7 @@ runs:
role-to-assume: ${{ inputs.dev-account-role }}
aws-region: ${{ inputs.aws-region }}
role-chaining: true
role-duration-seconds: ${{ inputs.role-duration-seconds }}

- name: Configure AWS credentials for test account
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -62,6 +68,7 @@ runs:
role-to-assume: ${{ inputs.test-account-role }}
aws-region: ${{ inputs.aws-region }}
role-chaining: true
role-duration-seconds: ${{ inputs.role-duration-seconds }}

- name: Configure AWS credentials for uat account
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -70,3 +77,4 @@ runs:
role-to-assume: ${{ inputs.uat-account-role }}
aws-region: ${{ inputs.aws-region }}
role-chaining: true
role-duration-seconds: ${{ inputs.role-duration-seconds }}
2 changes: 2 additions & 0 deletions .github/workflows/cleanup-ci-test-environments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
with:
aws-region: ${{ env.AWS_REGION }}
tools-account-role: ${{ secrets.UHD_TERRAFORM_ROLE }}
# Timeout after 6 hours
role-duration-seconds: "21600"

- name: Terraform cleanup
run: |
Expand Down
17 changes: 14 additions & 3 deletions scripts/_terraform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ function _terraform_help() {
echo
echo " cleanup - destroys all CI test environments"
echo " force-unlock <layer> <lock id> - releases the lock on a workspace"
echo
echo " workspace-list - lists all terraform workspaces"
echo
return 1
}

Expand All @@ -51,6 +52,7 @@ function _terraform() {
"output-file:layer") _terraform_output_layer_file $args ;;
"destroy:layer") _terraform_destroy_layer $args ;;
"force-unlock") _terraform_force_unlock $args ;;
"workspace-list") _terraform_workspace_list $args ;;

"cleanup") _terraform_cleanup $args ;;

Expand Down Expand Up @@ -403,8 +405,17 @@ function _terraform_force_unlock() {
terraform force-unlock --force $lock_id
}

_terraform_cleanup() {

function _terraform_workspace_list() {
local envs=($(terraform -chdir=terraform/20-app workspace list))

for env in ${envs[@]}; do
if [[ ! $env == "*" ]] && [[ ! " ${files[@]} " =~ " ${env} " ]]; then
echo "-> ${env}"
fi
done
}

function _terraform_cleanup() {
local envs=($(terraform -chdir=terraform/20-app workspace list))
local files=($(echo \*))

Expand Down
Loading

0 comments on commit 2db6e07

Please sign in to comment.