Skip to content

Commit

Permalink
Merge pull request #1205 from UKHSA-Internal/task/take-name-input-as-…
Browse files Browse the repository at this point in the history
…env-name/CDD-2448

Task/take name input as env name/cdd 2448
  • Loading branch information
A-Ashiq authored Jan 28, 2025
2 parents 8f22c07 + 645f67c commit c715f98
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 41 deletions.
34 changes: 8 additions & 26 deletions .github/workflows/deploy-personal-dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
name:
description: "The name of the user on your machine e.g. janedoe"
description: "The name of the dev environment you wish to deploy to e.g. abcd1234"
required: true
type: string

Expand Down Expand Up @@ -33,16 +33,11 @@ jobs:
- uses: ./.github/actions/setup-terraform
- uses: ./.github/actions/setup-zsh

- name: Make environment name
uses: ./.github/actions/make-workspace-name
with:
name: ${{ github.event.inputs.name }}

- name: Terraform apply
run: |
source uhd.sh
uhd terraform init:layer 20-app
uhd terraform apply:layer 20-app $ENVIRONMENT_NAME
uhd terraform apply:layer 20-app ${{ inputs.name }}
shell: zsh {0}

push_docker_images:
Expand All @@ -60,15 +55,10 @@ jobs:

- uses: ./.github/actions/setup-zsh

- name: Make environment name
uses: ./.github/actions/make-workspace-name
with:
name: ${{ github.event.inputs.name }}

- name: Pull / push docker images
run: |
source uhd.sh
uhd docker update dev $ENVIRONMENT_NAME
uhd docker update dev ${{ inputs.name }}
shell: zsh {0}

restart_services:
Expand All @@ -87,21 +77,17 @@ jobs:
- uses: ./.github/actions/setup-terraform
- uses: ./.github/actions/setup-zsh

- name: Make environment name
uses: ./.github/actions/make-workspace-name
with:
name: ${{ github.event.inputs.name }}

- name: Terraform output
run: |
source uhd.sh
uhd terraform init:layer 20-app
uhd terraform output:layer 20-app $ENVIRONMENT_NAME
uhd terraform output:layer 20-app ${{ inputs.name }}
shell: zsh {0}

- name: Configure AWS credentials for dev account
uses: ./.github/actions/configure-aws-credentials
with:
account-name: "dev"
aws-region: ${{ env.AWS_REGION }}
dev-account-role: ${{ secrets.UHD_TERRAFORM_ROLE_DEV }}

Expand All @@ -118,7 +104,7 @@ jobs:
shell: zsh {0}

bootstrap_database:
name: Restart services
name: Bootstrap database
runs-on: ubuntu-latest
needs: [ "restart_services" ]
steps:
Expand All @@ -133,21 +119,17 @@ jobs:
- uses: ./.github/actions/setup-terraform
- uses: ./.github/actions/setup-zsh

- name: Make environment name
uses: ./.github/actions/make-workspace-name
with:
name: ${{ github.event.inputs.name }}

- name: Terraform output
run: |
source uhd.sh
uhd terraform init:layer 20-app
uhd terraform output:layer 20-app $ENVIRONMENT_NAME
uhd terraform output ${{ inputs.name }}
shell: zsh {0}

- name: Configure AWS credentials for dev account
uses: ./.github/actions/configure-aws-credentials
with:
account-name: "dev"
aws-region: ${{ env.AWS_REGION }}
dev-account-role: ${{ secrets.UHD_TERRAFORM_ROLE_DEV }}

Expand Down
40 changes: 25 additions & 15 deletions scripts/_terraform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -508,25 +508,35 @@ function _get_etl_sibling_aws_account_id() {

function _get_target_aws_account_name() {
local layer=$1
local workspace=$2
local workspace=$2

if [[ $layer == "10-account" ]]; then
echo $workspace
else
if [[ $workspace == "prod" ]]; then
echo "prod"
elif [[ $CI == "true" ]]; then
if [[ $branch == "env/dev/"* ]]; then
echo "dev"
elif [[ $branch == "env/uat/"* ]]; then
echo "uat"
else
echo "test"
fi
else
echo "dev"
fi
fi
# This is an app-layer change
if [[ $workspace == "prod" ]]; then
echo "prod"

elif [[ $CI == "true" ]]; then
if [[ $workspace == ci-* ]]; then
echo "test"
else
case $branch in
env/dev/*) echo "dev" ;;
env/uat/*) echo "uat" ;;
env/test/*) echo "test" ;;
*) echo "dev" ;;
# In this case, the CI is actively looking
# to deploy to the dev account not the test account
esac
fi

else
# If we don't want prod, and we're not in the CI environment
# then we're interested in deploying to the dev account
echo "dev"
fi
fi
}


Expand Down

0 comments on commit c715f98

Please sign in to comment.