-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get Azure image id (part of CB-22440)
- Loading branch information
Gabor Solya
committed
Aug 4, 2023
1 parent
ddfea34
commit 4402147
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
|
||
: ${AZURE_IMAGE_PUBLISHER?= required} | ||
: ${AZURE_IMAGE_OFFER?= required} | ||
: ${AZURE_IMAGE_SKU?= required} | ||
: ${AZURE_IMAGE_VERSION?= required} | ||
#AZURE_IMAGE_PUBLISHER="RedHat" | ||
#AZURE_IMAGE_OFFER="rhel-byos" | ||
#AZURE_IMAGE_SKU="rhel-lvm88" | ||
#AZURE_IMAGE_VERSION="8.8" | ||
#SKIP_IF_CONTAINS_STRING="gen2" Where the souruce image id contains this substring will be skipped. | ||
|
||
debug() { | ||
[[ "$DEBUG" ]] && echo "-----> $*" 1>&2 | ||
} | ||
|
||
alias r="source $BASH_SOURCE" | ||
|
||
azure_login() { | ||
if [[ "$ARM_CLIENT_ID" ]] && [[ "$ARM_CLIENT_SECRET" ]]; then | ||
az login --username $ARM_CLIENT_ID --password $ARM_CLIENT_SECRET --service-principal --tenant $ARM_TENANT_ID | ||
fi | ||
} | ||
|
||
azure_get_rhel8_source_image_id() { | ||
if [[ "$SKIP_IF_CONTAINS_STRING" ]]; then | ||
az vm image list --publisher $AZURE_IMAGE_PUBLISHER --offer $AZURE_IMAGE_OFFER --all | jq -r --arg version $AZURE_IMAGE_VERSION --arg offer $AZURE_IMAGE_OFFER --arg skipthis $SKIP_IF_CONTAINS_STRING '.[] | select(.version | startswith($version)) | select(.urn | contains($offer)) | select(.urn | contains($skipthis) | not) | .urn' | ||
else | ||
az vm image list --publisher $AZURE_IMAGE_PUBLISHER --offer $AZURE_IMAGE_OFFER --all | jq -r --arg version $AZURE_IMAGE_VERSION --arg offer $AZURE_IMAGE_OFFER '.[] | select(.version | startswith($version)) | select(.urn | contains($offer)) | .urn' | ||
fi | ||
} | ||
|
||
main() { | ||
: ${DEBUG:=1} | ||
azure_login | ||
azure_get_rhel8_source_image_id > rhel8_base_image_id.out | ||
} | ||
|
||
[[ "$0" == "$BASH_SOURCE" ]] && main "$@" |