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

Consolidate deploy scripts and remove unused files #4382

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ terraform-deploy:
&& . ${MAKEFILE_DIR}/devops/scripts/check_dependencies.sh env \
&& . ${MAKEFILE_DIR}/devops/scripts/load_and_validate_env.sh \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ${DIR}/.env \
&& cd ${DIR}/terraform/ && ./deploy.sh
&& ./devops/scripts/terraform_deploy.sh ${DIR}

terraform-upgrade:
$(call target_title, "Upgrading ${DIR} with Terraform") \
&& . ${MAKEFILE_DIR}/devops/scripts/check_dependencies.sh env \
&& . ${MAKEFILE_DIR}/devops/scripts/load_and_validate_env.sh \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ${DIR}/.env \
&& ./devops/scripts/upgrade.sh ${DIR}
&& ./devops/scripts/terraform_upgrade_provider.sh ${DIR}

terraform-import:
$(call target_title, "Importing ${DIR} with Terraform") \
Expand Down
1 change: 1 addition & 0 deletions core/terraform/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ LOG_FILE="${TS}-tre-core.log"
# This variables are loaded in for us
# shellcheck disable=SC2154
../../devops/scripts/terraform_wrapper.sh \
-d "${PWD}" \
-g "${TF_VAR_mgmt_resource_group_name}" \
-s "${TF_VAR_mgmt_storage_account_name}" \
-n "${TF_VAR_terraform_state_container_name}" \
Expand Down
3 changes: 2 additions & 1 deletion core/terraform/destroy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ source "../../devops/scripts/kv_add_network_exception.sh"

# These variables are loaded in for us
# shellcheck disable=SC2154
../../devops/scripts/terraform_wrapper.sh -g "${TF_VAR_mgmt_resource_group_name}" \
../../devops/scripts/terraform_wrapper.sh -d "${PWD}" \
-g "${TF_VAR_mgmt_resource_group_name}" \
-s "${TF_VAR_mgmt_storage_account_name}" \
-n "${TF_VAR_terraform_state_container_name}" \
-k "${TRE_ID}" -c "terraform destroy -auto-approve"
1 change: 1 addition & 0 deletions core/terraform/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export TF_LOG=""
# This variables are loaded in for us
# shellcheck disable=SC2154
../../devops/scripts/terraform_wrapper.sh \
-d "${PWD}" \
-g "${TF_VAR_mgmt_resource_group_name}" \
-s "${TF_VAR_mgmt_storage_account_name}" \
-n "${TF_VAR_terraform_state_container_name}" \
Expand Down
2 changes: 1 addition & 1 deletion core/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.12.5"
__version__ = "0.12.6"
63 changes: 63 additions & 0 deletions devops/scripts/terraform_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
set -e

# This script is used to deploy terraform configurations

# Usage: ./terraform_deploy.sh <directory>

DIR=$1

# Load environment variables from .env file
if [ -f "$DIR/.env" ]; then
set -a
# shellcheck source=/dev/null
. "$DIR/.env"
set +a
fi

# Ensure TF_VAR_mgmt_resource_group_name is set
if [ -z "${TF_VAR_mgmt_resource_group_name}" ]; then
echo "Error: TF_VAR_mgmt_resource_group_name is not set."
exit 1
fi

# Ensure TF_VAR_mgmt_storage_account_name is set
if [ -z "${TF_VAR_mgmt_storage_account_name}" ]; then
echo "Error: TF_VAR_mgmt_storage_account_name is not set."
exit 1
fi

# Ensure TF_VAR_terraform_state_container_name is set
if [ -z "${TF_VAR_terraform_state_container_name}" ]; then
echo "Error: TF_VAR_terraform_state_container_name is not set."
exit 1
fi

# Ensure TRE_ID is set
if [ -z "${TRE_ID}" ]; then
echo "Error: TRE_ID is not set."
exit 1
fi

# Infer the key from the directory names
PARENT_DIR=$(basename "$(dirname "$DIR")")
GRANDPARENT_DIR=$(basename "$(dirname "$(dirname "$DIR")")")

if [[ "$GRANDPARENT_DIR" == "workspaces" || "$GRANDPARENT_DIR" == "shared_services" ]]; then
KEY="${TRE_ID?}_${TF_VAR_id?}_${PARENT_DIR}"
elif [[ "$GRANDPARENT_DIR" == "workspace_services" ]]; then
KEY="${TRE_ID?}_${TF_VAR_workspace_id?}_${TF_VAR_id?}_${PARENT_DIR}"
elif [[ "$GRANDPARENT_DIR" == "user_resources" ]]; then
KEY="${TRE_ID?}_${TF_VAR_workspace_id?}_${TF_VAR_workspace_service_id?}_${TF_VAR_id?}_${PARENT_DIR}"
else
KEY="${TRE_ID?}_${PARENT_DIR}"
fi

# Call terraform_wrapper.sh to handle terraform commands
./devops/scripts/terraform_wrapper.sh \
-d "$DIR/terraform" \
-g "${TF_VAR_mgmt_resource_group_name}" \
-s "${TF_VAR_mgmt_storage_account_name}" \
-n "${TF_VAR_terraform_state_container_name}" \
-k "${KEY}" \
-c "terraform apply -auto-approve"
File renamed without changes.
19 changes: 16 additions & 3 deletions devops/scripts/terraform_wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash
set -e


function usage() {
cat <<USAGE

Usage: $0 [-g | --mgmt-resource-group-name ] [-s | --mgmt-storage-account-name] [-n | --state-container-name] [-k | --key] [-c | --cmd] [-l | --logfile]
Usage: $0 [-d | --directory] [-g | --mgmt-resource-group-name ] [-s | --mgmt-storage-account-name] [-n | --state-container-name] [-k | --key] [-c | --cmd] [-l | --logfile]

Options:
-d, --directory Directory to change to before executing commands
-g, --mgmt-resource-group-name Management resource group name
-s, --mgmt-storage-account-name Management storage account name
-n, --state-container-name State container name
Expand All @@ -25,6 +25,10 @@ fi

while [ "$1" != "" ]; do
case $1 in
-d | --directory)
shift
DIR=$1
;;
-g | --mgmt-resource-group-name)
shift
mgmt_resource_group_name=$1
Expand Down Expand Up @@ -60,6 +64,10 @@ while [ "$1" != "" ]; do
shift # remove the current value for `$1` and use the next
done

if [[ -z ${DIR+x} ]]; then
echo -e "No directory provided\n"
usage
fi

if [[ -z ${mgmt_resource_group_name+x} ]]; then
echo -e "No terraform state resource group name provided\n"
Expand Down Expand Up @@ -91,9 +99,13 @@ if [[ -z ${tf_logfile+x} ]]; then
echo -e "No logfile provided, using ${tf_logfile}\n"
fi


# shellcheck disable=SC1091
source "$(dirname "$0")/mgmtstorage_enable_public_access.sh"

# Change directory to $DIR
pushd "$DIR" > /dev/null

terraform init -input=false -backend=true -reconfigure \
-backend-config="resource_group_name=${mgmt_resource_group_name}" \
-backend-config="storage_account_name=${mgmt_storage_account_name}" \
Expand Down Expand Up @@ -130,4 +142,5 @@ do
fi
done


# Return to the original directory
popd > /dev/null
2 changes: 1 addition & 1 deletion templates/shared_services/admin-vm/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
**/.terraform/*
**/*_backend.tf
Dockerfile.tmpl
terraform/deploy.sh

terraform/destroy.sh
20 changes: 0 additions & 20 deletions templates/shared_services/admin-vm/terraform/deploy.sh

This file was deleted.

15 changes: 0 additions & 15 deletions templates/shared_services/airlock_notifier/terraform/deploy.sh

This file was deleted.

12 changes: 0 additions & 12 deletions templates/shared_services/cyclecloud/terraform/deploy.sh

This file was deleted.

2 changes: 1 addition & 1 deletion templates/shared_services/databricks-auth/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# TF backend files
**/*_backend.tf
Dockerfile.tmpl
terraform/deploy.sh

terraform/destroy.sh
22 changes: 0 additions & 22 deletions templates/shared_services/databricks-auth/terraform/deploy.sh

This file was deleted.

22 changes: 0 additions & 22 deletions templates/shared_services/deploy_from_local.sh

This file was deleted.

20 changes: 0 additions & 20 deletions templates/shared_services/gitea/terraform/deploy.sh

This file was deleted.

10 changes: 0 additions & 10 deletions templates/shared_services/sonatype-nexus-vm/terraform/deploy.sh

This file was deleted.

15 changes: 0 additions & 15 deletions templates/workspace_services/azureml/terraform/deploy.sh

This file was deleted.

13 changes: 0 additions & 13 deletions templates/workspace_services/azureml/terraform/upgrade.sh

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions templates/workspace_services/azuresql/terraform/upgrade.sh

This file was deleted.

2 changes: 1 addition & 1 deletion templates/workspace_services/databricks/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# TF backend files
**/*_backend.tf
Dockerfile.tmpl
terraform/deploy.sh

terraform/destroy.sh
Loading
Loading