PSRule.Rules.Azure icon indicating copy to clipboard operation
PSRule.Rules.Azure copied to clipboard

Automatically export offers for Linux VMs

Open BernieWhite opened this issue 3 years ago • 1 comments

As PR #1701 calls out. We will need to get a list of offers for Linux VMs to better scope/ configure some Linux specific rules.

Let's look for ways to include update of offers as a CI process, similar to what we do with provider data.

https://github.com/Azure/PSRule.Rules.Azure/blob/main/scripts/providers.psm1 https://github.com/Azure/PSRule.Rules.Azure/blob/main/.github/workflows/providers.yml

BernieWhite avatar Sep 23 '22 02:09 BernieWhite

In case it helps, this is the messy and inefficient script I used for the current version:

az login

$linuxOfferingsFilePath = "LinuxOfferings.ps1"
New-Item $linuxOfferingsFilePath

$allOfferingsRaw = Get-Content "allOfferings.txt" # Info obtained with: az vm image list --all (takes a while)
$allOfferings = $allOfferingsRaw | ConvertFrom-Json

$processedOffers = New-Object System.Collections.Generic.HashSet[string]

Add-Content $linuxOfferingsFilePath "`$global:LinuxOffers = @("

foreach ($offering in $allOfferings)
{
    $newOffer = "(`"$($offering.publisher)`", `"$($offering.offer)`"),"

    if (!$processedOffers.Contains($newOffer)) {
        $processedOffers.Add($newOffer)

        $offeringInfo = $(az vm image show --urn $offering.urn) | ConvertFrom-Json
    
        if($offeringInfo.osDiskImage.operatingSystem -eq "Linux") {    
            Add-Content $linuxOfferingsFilePath $newOffer
        }
    }
}

Add-Content $linuxOfferingsFilePath "(`"`",`"`"))"

VeraBE avatar Sep 23 '22 02:09 VeraBE