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

Handling null valued quotaId #256

Merged
merged 3 commits into from
Sep 19, 2024
Merged

Conversation

mthreer
Copy link
Contributor

@mthreer mthreer commented Sep 17, 2024

In a recent deployment of AzGovWiz we discovered that the setup wouldn't carry on when it stumbled upon a subscription with a null-valued .quotaId. There wasn't much detail provided in the output regarding this, it simply stopped at "Subscription picking" with the error "You cannot call a method on a null-valued expression."

After extensive debugging, we discovered a way forward by excluding a subscription we believed to be causing troubles. We began excluding the erroneous subscription in an ugly way, by implementing a check against the subscription name "Free Trial". We found out afterwards that the real reason it failed was due to the .quotaId being null.

The error comes from the .startsWith() method that is validating if the property value .quotaId starts with AAD_, but against a null-valued .quotaId.

Example:
$null.startsWith('xyz')

Will give you the output of:
InvalidOperation: You cannot call a method on a null-valued expression.

This PR simply evaluates if .quotaId is null first, and then puts these subscriptions with the null-valued .quotaId out of scope.

Azure Governance Visualizer (6.5.3) run identifier: D4038018B71F6625F4C78177872EF6140EFFF16F9D5439D4487EE760A7F50458F7DE1C17D3DD0460B4182C8E1610BE9F9C0BB3A1BDDDE2916BD8079B8E468B63

Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
if ($sub.subDetails.subscriptionPolicies.quotaId -eq $null) {

Check warning

Code scanning / PSScriptAnalyzer

$null should be on the left side of equality comparisons. Warning

$null should be on the left side of equality comparisons.
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
if ($sub.subDetails.subscriptionPolicies.quotaId -eq $null) {

Check warning

Code scanning / PSScriptAnalyzer

$null should be on the left side of equality comparisons. Warning

$null should be on the left side of equality comparisons.
@JulianHayward JulianHayward merged commit 42618ac into JulianHayward:master Sep 19, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants