Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move duplicated logic to scripts #3371

Merged
merged 9 commits into from
Mar 28, 2023
24 changes: 13 additions & 11 deletions .github/actions/devcontainer_run_command/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,18 @@ inputs:
runs:
using: composite
steps:
- name: Construct AZURE_ENVIRONMENT
shell: bash
run: |
azure_env="${{ (inputs.AZURE_ENVIRONMENT != '' && inputs.AZURE_ENVIRONMENT) || 'AzureCloud' }}"
echo "AZURE_ENVIRONMENT=$azure_env" >> $GITHUB_ENV

- name: Azure Login
uses: azure/login@v1
if: contains(inputs.COMMAND, 'bootstrap') != true
with:
creds: ${{ inputs.AZURE_CREDENTIALS }}
environment: ${{ (inputs.AZURE_ENVIRONMENT != '' && inputs.AZURE_ENVIRONMENT) || 'AzureCloud' }}
environment: "${{ env.AZURE_ENVIRONMENT }}"

- name: ACR Login
shell: bash
Expand All @@ -137,20 +143,16 @@ runs:
- name: Construct TRE_URL
shell: bash
run: |
declare -A cloudapp_endpoint_suffixes=( ["AzureCloud"]="cloudapp.azure.com" ["AzureUSGovernment"]="cloudapp.usgovcloudapi.net")
azure_env="${{ (inputs.AZURE_ENVIRONMENT != '' && inputs.AZURE_ENVIRONMENT) || 'AzureCloud' }}"
domain=${cloudapp_endpoint_suffixes[${azure_env}]}
tre_id="${{ inputs.TRE_ID }}"
location="${{ inputs.LOCATION }}"
tre_url=${TRE_URL:-https://${tre_id}.${location}.${domain}}
source devops/scripts/construct_tre_url.sh
tre_url=$(construct_tre_url "${{ inputs.TRE_ID }}" "${{ inputs.LOCATION }}" "${{ env.AZURE_ENVIRONMENT }}")
echo "TRE_URL=$tre_url" >> $GITHUB_ENV

- name: Construct ARM_ENVIRONMENT
shell: bash
run: |
declare -A arm_envs=( ["AzureCloud"]="public" ["AzureUSGovernment"]="usgovernment")
azure_env="${{ (inputs.AZURE_ENVIRONMENT != '' && inputs.AZURE_ENVIRONMENT) || 'AzureCloud' }}"
echo "ARM_ENVIRONMENT=${arm_envs[${azure_env}]}" >> $GITHUB_ENV
source devops/scripts/convert_azure_env_to_arm_env.sh
arm_environment=$(convert_azure_env_to_arm_env "${{ env.AZURE_ENVIRONMENT }}")
echo "ARM_ENVIRONMENT=$arm_environment" >> $GITHUB_ENV

- name: Construct ACR Domain Suffix
shell: bash
Expand All @@ -172,7 +174,7 @@ runs:
-e WORKSPACE_SERVICE_NAME="${{ inputs.WORKSPACE_SERVICE_NAME }}" \
-e ARM_ENVIRONMENT="${{ env.ARM_ENVIRONMENT }}" \
-e TF_VAR_arm_environment="${{ env.ARM_ENVIRONMENT }}" \
-e AZURE_ENVIRONMENT="${{ (inputs.AZURE_ENVIRONMENT != '' && inputs.AZURE_ENVIRONMENT) || 'AzureCloud' }}" \
-e AZURE_ENVIRONMENT="${{ env.AZURE_ENVIRONMENT }}" \
-e LOCATION="${{ inputs.LOCATION }}" \
-e TF_VAR_location="${{ inputs.LOCATION }}" \
-e RESOURCE_LOCATION="${{ inputs.LOCATION }}" \
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ auth:

show-core-output:
$(call target_title,"Display TRE core output") \
&& . ${MAKEFILE_DIR}/devops/scripts/check_dependencies.sh env \
&& pushd ${MAKEFILE_DIR}/core/terraform/ > /dev/null && terraform show && popd > /dev/null

api-healthcheck:
Expand Down
8 changes: 1 addition & 7 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
"pattern": "^[a-zA-Z 0-9\\_]*$",
"maxLength": 11
},
"arm_environment": {
"description": "The Azure environment where resources will be deployed.",
"type": "string",
"enum": ["public", "usgovernment"]
},
"management": {
"description": "Management configuration",
"type": "object",
Expand Down Expand Up @@ -163,7 +158,6 @@
},
"required": [
"location",
"tre_id",
"arm_environment"
"tre_id"
]
}
18 changes: 18 additions & 0 deletions devops/scripts/construct_tre_url.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
tamirkamara marked this conversation as resolved.
Show resolved Hide resolved

# This script is designed to be `source`d to create reusable helper functions

function construct_tre_url()
{
tre_id=$1
location=$2
azure_environment=$3

declare -A cloudapp_endpoint_suffixes=( ["AzureCloud"]="cloudapp.azure.com" ["AzureUSGovernment"]="cloudapp.usgovcloudapi.net" )
domain=${cloudapp_endpoint_suffixes[${azure_environment}]}

echo https://"${tre_id}"."${location}"."${domain}"
}
13 changes: 13 additions & 0 deletions devops/scripts/convert_azure_env_to_arm_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
tamirkamara marked this conversation as resolved.
Show resolved Hide resolved

# This script is designed to be `source`d to create reusable helper functions

function convert_azure_env_to_arm_env()
{
azure_environment=$1
declare -A arm_envs=( ["AzureCloud"]="public" ["AzureUSGovernment"]="usgovernment")
echo "${arm_envs[${azure_environment}]}"
}
15 changes: 13 additions & 2 deletions devops/scripts/load_and_validate_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ set -o nounset
# load_and_validate_env.sh
#

# shellcheck disable=SC1091
source "${DIR}"/construct_tre_url.sh
# shellcheck disable=SC1091
source "${DIR}"/convert_azure_env_to_arm_env.sh
yuvalyaron marked this conversation as resolved.
Show resolved Hide resolved

if [ ! -f "config.yaml" ]; then
if [ -z "${USE_ENV_VARS_NOT_FILES:-}" ]; then
echo -e "\e[31m»»» 💥 Unable to find config.yaml file, please create file and try again!\e[0m"
Expand Down Expand Up @@ -43,11 +48,17 @@ else
# shellcheck disable=SC2046
export $(yq e "$GET_LEAF_KEYS|$TF_KEYS| $FORMAT_FOR_ENV_EXPORT" config.yaml)

# Source AZURE_ENVIRONMENT and setup the ARM_ENVIRONMENT based on it
yuvalyaron marked this conversation as resolved.
Show resolved Hide resolved
AZURE_ENVIRONMENT=$(az cloud show --query name --output tsv)
export AZURE_ENVIRONMENT

declare -A cloudapp_endpoint_suffix=( ["public"]="cloudapp.azure.com" ["usgovernment"]="cloudapp.usgovcloudapi.net")
export TRE_URL=${TRE_URL:-https://${TRE_ID}.${LOCATION}.${cloudapp_endpoint_suffix[${ARM_ENVIRONMENT}]}}
# The ARM Environment is required by terrafform to indicate the destination cloud.
yuvalyaron marked this conversation as resolved.
Show resolved Hide resolved
ARM_ENVIRONMENT=$(convert_azure_env_to_arm_env "${AZURE_ENVIRONMENT}")
export ARM_ENVIRONMENT
export TF_VAR_arm_environment="${ARM_ENVIRONMENT}"

TRE_URL=$(construct_tre_url "${TRE_ID}" "${LOCATION}" "${AZURE_ENVIRONMENT}")
export TRE_URL
fi

set +o nounset