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

use arguments for build scripts #141

Merged
merged 2 commits into from
Apr 1, 2021
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ For more on workflows: <https://docs.github.com/en/actions/reference/workflow-sy
Secret Name | Value
------------ | -------------
MLZTENANTID | The Tenant to deploy MLZ into
MLZCLIENTID | The Service Principal Authorized to deploy resources into MLZ Terraform Subscriptions
MLZCLIENTSECRET | The credential for the Service Principal above
STORAGEACCOUNT | The Azure Storage Account for the files in the previous step
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/apply-and-destroy-terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ jobs:
- name: get vars
run : |
cd src/build
./get_vars.sh
./get_vars.sh "$STORAGEACCOUNT" "$STORAGETOKEN" "$STORAGECONTAINER"
- name: login
run : |
cd src/build
./login_azcli.sh vars/mlz_tf_cfg.var
./login_azcli.sh "$MLZTENANTID" "$MLZCLIENTID" "$MLZCLIENTSECRET"
- name: apply terraform
run : |
Expand Down
24 changes: 21 additions & 3 deletions src/build/get_vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,33 @@

set -e

error_log() {
echo "${1}" 1>&2;
}

usage() {
echo "get_vars.sh: login using known Service Principal credentials into a given tenant"
error_log "usage: get_vars.sh.sh <storage account name> <storage account token> <storage account container>"
}

if [[ "$#" -lt 3 ]]; then
usage
exit 1
fi

sa_name=$1
sa_token=$2
sa_container=$3

# create some place to hold the configuration and TF vars
rm -rf "vars"
mkdir "vars"

# download everything in the container to that place
az storage blob download-batch \
--account-name "${STORAGEACCOUNT}" \
--sas-token "${STORAGETOKEN}" \
--source "${STORAGECONTAINER}" \
--account-name "${sa_name}" \
--sas-token "${sa_token}" \
--source "${sa_container}" \
--pattern "*" \
--destination "vars" \
--output "none" \
Expand Down
18 changes: 7 additions & 11 deletions src/build/login_azcli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,23 @@ error_log() {
}

usage() {
echo "login_azcli.sh: Get the tenant ID from some MLZ configuration file and login using known Service Principal credentials"
error_log "usage: login_azcli.sh <mlz config> <SP_ID> <SP_PW>"
echo "login_azcli.sh: login using known Service Principal credentials into a given tenant"
error_log "usage: login_azcli.sh <tenant ID> <service principal ID> <service principal password>"
}

if [[ "$#" -lt 1 ]]; then
if [[ "$#" -lt 3 ]]; then
usage
exit 1
fi

mlz_config=$1

# source the variables from MLZ config
source "${mlz_config}"

sp_id=${2:-$MLZCLIENTID}
sp_pw=${3:-$MLZCLIENTSECRET}
tenant_id=$1
sp_id=$2
sp_pw=$3

# login with known credentials
az login --service-principal \
--user "${sp_id}" \
--password="${sp_pw}" \
--tenant "${mlz_tenantid}" \
--tenant "${tenant_id}" \
--allow-no-subscriptions \
--output json