Skip to content

Commit 9a32781

Browse files
Merge pull request #87 from lacework-dev/via-scripts-update
Forced AZ CLI output to json
2 parents 03fb4d1 + 46880c6 commit 9a32781

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

bash/lw_azure_inventory.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function removeMap {
3535
}
3636

3737
function installResourceGraphIfNotPresent {
38-
resourceGraphPresent=$(az extension list --query "contains([].name, \`resource-graph\`)")
38+
resourceGraphPresent=$(az extension list -o json --query "contains([].name, \`resource-graph\`)")
3939
if [ "$resourceGraphPresent" != true ] ; then
4040
echo "resource-graph extension not present in Az CLI installation. Enabling..."
4141
az extension add --name "resource-graph"
@@ -58,7 +58,7 @@ AZURE_VMSS_COUNT=0
5858
installResourceGraphIfNotPresent
5959

6060
echo "Building Azure VM SKU to vCPU map..."
61-
az vm list-skus --resource-type virtualmachines |\
61+
az vm list-skus --resource-type virtualmachines -o json |\
6262
jq -r '.[] | .name as $parent | select(.capabilities != null) | .capabilities[] | select(.name == "vCPUs") | $parent+":"+.value' |\
6363
sort | uniq > ./tmp_map
6464
echo "Map built successfully."
@@ -123,12 +123,12 @@ function runSubscriptionAnalysis {
123123
function runAnalysis {
124124
local scope=$1
125125
echo Load subscriptions
126-
local expectedSubscriptions=$(az graph query -q "resourcecontainers | where type == 'microsoft.resources/subscriptions' | project name, subscriptionId" $scope)
126+
local expectedSubscriptions=$(az graph query -q "resourcecontainers | where type == 'microsoft.resources/subscriptions' | project name, subscriptionId" $scope -o json)
127127
local expectedSubscriptionIds=$(echo $expectedSubscriptions | jq -r '.data[] | .subscriptionId' | sort)
128128
echo Load VMs
129-
local vms=$(az graph query -q "Resources | where type=~'microsoft.compute/virtualmachines' | project subscriptionId, name, sku=properties.hardwareProfile.vmSize, powerState=properties.extended.instanceView.powerState.code" $scope)
129+
local vms=$(az graph query -q "Resources | where type=~'microsoft.compute/virtualmachines' | project subscriptionId, name, sku=properties.hardwareProfile.vmSize, powerState=properties.extended.instanceView.powerState.code" $scope -o json)
130130
echo Load VMSS
131-
local vmss=$(az graph query -q "Resources | where type=~ 'microsoft.compute/virtualmachinescalesets' | project subscriptionId, name, sku=sku.name, capacity = toint(sku.capacity)" $scope)
131+
local vmss=$(az graph query -q "Resources | where type=~ 'microsoft.compute/virtualmachinescalesets' | project subscriptionId, name, sku=sku.name, capacity = toint(sku.capacity)" $scope -o json)
132132

133133
local actualSubscriptionIds=$(echo $vms | jq -r '.data[] | .subscriptionId' | sort | uniq)
134134

0 commit comments

Comments
 (0)