Skip to content

Commit

Permalink
Merging private-preview scripts and terraform into main in a hacky way
Browse files Browse the repository at this point in the history
  • Loading branch information
hdamecharla authored and hdamecharla committed Dec 29, 2021
1 parent e882829 commit 1efcc20
Show file tree
Hide file tree
Showing 59 changed files with 1,643 additions and 1,365 deletions.
94 changes: 51 additions & 43 deletions deploy/scripts/advanced_state_management.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ script_directory="$(dirname "${full_script_path}")"
#call stack has full scriptname when using source
source "${script_directory}/deploy_utils.sh"

#helper files
source "${script_directory}/helpers/script_helpers.sh"


function showhelp {
echo ""
echo "##################################################################################################################"
Expand Down Expand Up @@ -125,7 +129,7 @@ if [ -z "$parameterfile" ]; then
exit 2 #No such file or directory
fi

if [ ! -n "${type}" ]
if [ -z "${type}" ]
then
printf -v val %-40.40s "$type"
echo "#########################################################################################"
Expand All @@ -143,45 +147,38 @@ then
exit 64 #script usage wrong
fi

# Check that the exports ARM_SUBSCRIPTION_ID and DEPLOYMENT_REPO_PATH are defined
validate_exports
return_code=$?
if [ 0 != $return_code ]; then
exit $return_code
fi

# Checking for valid az session
az account show > stdout.az 2>&1
temp=$(grep "az login" stdout.az)
if [ -n "${temp}" ]; then
echo ""
echo "#########################################################################################"
echo "# #"
echo -e "# $boldred Please login using az login $resetformatting #"
echo "# #"
echo "#########################################################################################"
echo ""
if [ -f stdout.az ]
then
rm stdout.az
fi
exit 67 #addressee unknown
else
if [ -f stdout.az ]
then
rm stdout.az
fi

# Check that Terraform and Azure CLI is installed
validate_dependencies
return_code=$?
if [ 0 != $return_code ]; then
exit $return_code
fi

account_set=0
# Check that parameter files have environment and location defined
validate_key_parameters "$parameterfile_name"
if [ 0 != $return_code ]; then
exit $return_code
fi

cloudIDUsed=$(az account show | grep "cloudShellID")
if [ ! -z "${cloudIDUsed}" ];
then
echo ""
echo "#########################################################################################"
echo "# #"
echo -e "# $boldred Please login using your credentials or service principal credentials! $resetformatting #"
echo "# #"
echo "#########################################################################################"
echo ""
exit 67 #addressee unknown
if valid_region_name ${region} ; then
# Convert the region to the correct code
get_region_code ${region}
else
echo "Invalid region: $region"
exit 2
fi
account_set=0

automation_config_directory=~/.sap_deployment_automation/
generic_config_information="${automation_config_directory}"config
system_config_information="${automation_config_directory}""${environment}""${region_code}"


az_res=$(az resource show --ids "${resourceID}")
Expand All @@ -199,15 +196,28 @@ if [ 0 != $return_value ] ; then
exit $return_value
fi

if [ ! -z "${subscription_id}" ]
if [ -n "${subscription_id}" ]
then
$(az account set --sub "${subscription_id}")
account_set=1
az account set --sub "${subscription_id}"
else
load_config_vars "${system_config_information}" "STATE_SUBSCRIPTION"

subscription_id=$STATE_SUBSCRIPTION

if [ -n "${subscription_id}" ]
then
read -p "Subscription ID containing Terraform state storage account:" subscription_id
fi
az account set --sub "${subscription_id}"
fi

load_config_vars "${system_config_information}" "tfstate_resource_id"

tfstate_resource_id=$(az resource list --name "${storage_account_name}" --resource-type Microsoft.Storage/storageAccounts | jq --raw-output '.[0].id')
fail_if_null tfstate_resource_id
if [ -z "${tfstate_resource_id}" ]
then
tfstate_resource_id=$(az resource list --name "${storage_account_name}" --resource-type Microsoft.Storage/storageAccounts | jq --raw-output '.[0].id')
fail_if_null tfstate_resource_id
fi
resource_group_name=$(echo $tfstate_resource_id | cut -d/ -f5 | tr -d \" | xargs)

directory=$(pwd)/.terraform
Expand Down Expand Up @@ -242,9 +252,7 @@ fi


terraform -chdir=${module_dir} state list > resources.lst
shorter_name=$(echo ${moduleID} | cut -d[ -f1)
tf_resource=$(grep ${shorter_name} resources.lst)
echo $tf_resource
tf_resource=$(grep ${moduleID} resources.lst)
if [ -n "${tf_resource}" ]; then

echo "#########################################################################################"
Expand Down
5 changes: 4 additions & 1 deletion deploy/scripts/configure_deployer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ set -o pipefail
#

if [ ! -n "${TF_VERSION}" ]; then
TF_VERSION="0.14.8"
TF_VERSION="1.0.11"
fi


Expand Down Expand Up @@ -260,6 +260,7 @@ required_pkgs=(
lsb-release
gnupg
sshpass
dos2unix
)

cli_pkgs=(
Expand Down Expand Up @@ -328,6 +329,8 @@ fi

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash > /dev/null

/usr/bin/az extension add --name storage-blob-preview > /dev/null

# Ensure our package metadata cache is up to date
pkg_mgr_refresh

Expand Down
Loading

0 comments on commit 1efcc20

Please sign in to comment.