Azure / PSRule.Rules.Azure

Rules to validate Azure resources and infrastructure as code (IaC) using PSRule.
https://azure.github.io/PSRule.Rules.Azure/
MIT License
383 stars 83 forks source link

Automatically export offers for Linux VMs #1705

Open BernieWhite opened 1 year ago

BernieWhite commented 1 year ago

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

VeraBE commented 1 year ago

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 "(`"`",`"`"))"