-
Notifications
You must be signed in to change notification settings - Fork 449
feat: Add diagnostics parameter #4929
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
base: main
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree company="Waternet" |
Hey @SanderNugteren, |
Hi @AlexanderSehr! I resolved the conflicts. Thanks for the help in getting this merged! |
Co-authored-by: Alexander Sehr <ASehr@hotmail.de>
Co-authored-by: Alexander Sehr <ASehr@hotmail.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your contribution!
I see some conflicts, please review and update your branch.
@description('Required. The workspace ID for log analytics.') | ||
workspaceId: string | ||
|
||
@description('Required. The workspace key for log analytics.') | ||
@secure() | ||
workspaceKey: string | ||
@description('Required. The workspace key for log analytics.') | ||
@secure() | ||
workspaceKey: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we shold make both these values optional if the resourceId
is provided. If the case, we can fetch both values via an existing
resource reference on behalf of the user, making this a lot easier to use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would by the way look something like this
@description('Optional. The log analytics diagnostic information for a container group.')
param logAnalytics logAnalyticsType?
resource law 'Microsoft.OperationalInsights/workspaces@2025-02-01' existing = if (!empty(logAnalytics.?workspaceResourceId)) {
name: last(split(logAnalytics.?workspaceResourceId!, '/'))
scope: resourceGroup(
split(logAnalytics.?workspaceResourceId!, '/')[2],
split(logAnalytics.?workspaceResourceId!, '/')[4]
)
}
resource containergroup 'Microsoft.ContainerInstance/containerGroups@2023-05-01' = {
(...)
diagnostics: !empty(logAnalytics)
? {
logAnalytics: {
logType: logAnalytics!.logType
workspaceId: logAnalytics!.?workspaceId ?? (!empty(logAnalytics.?workspaceResourceId)
? law.properties.customerId
: fail('Either the workspaceId or the workspaceResourceId must be provided.'))
#disable-next-line use-secure-value-for-secure-inputs // False-positive - Is declared as secure()
workspaceKey: logAnalytics!.?workspaceKey ?? (!empty(logAnalytics.?workspaceResourceId)
? law.listKeys().primarySharedKey
: fail('Either the workspaceKey or the workspaceResourceId must be provided.'))
#disable-next-line use-secure-value-for-secure-inputs // Not a secret
workspaceResourceId: logAnalytics!.?workspaceResourceId
metadata: logAnalytics!.?metadata
}
}
: null
(...)
}
@export()
@description('The type for the log analytics diagnostics.')
type logAnalyticsType = {
@description('Required. The log type to be used.')
logType: ('ContainerInsights' | 'ContainerInstanceLogs')
@description('Conditional. The workspace ID for log analytics. Required if `workspaceResourceId` is not provided.')
workspaceId: string?
@description('Conditional. The workspace key for log analytics. Required if `workspaceResourceId` is not provided.')
@secure()
workspaceKey: string?
@description('Conditional. The workspace resource id for log analytics. Required if `workspaceId` or `workspaceId` is not provided.')
workspaceResourceId: string?
@description('Optional. Metadata for log analytics.')
metadata: object?
}
allowing you to populate the parameter like
logAnalytics: {
logType: 'ContainerInsights'
workspaceResourceId: nestedDependencies.outputs.logAnalyticsWorkspaceResourceId
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the example! I was trying to implement your suggestion on my own but didn't think about using the fail
function to enforce either (workspaceId and workspaceKey) or (workspaceResourceId) to be set, so I kept getting warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to hear. In that case there'd only be one ask at least from my side (@JPEasier may have more as the owner) and that is to expand on the modules tests/e2e/max/main.bicep
test case by adding an LAW deployment to its dependencies.bicep
file and the parameter to the deployment on the bottom of the file main.test.bicep
, referecing e.g. the LAW resource ID output of the dependencies.bicep file (once added). Note: If you do that, you'll have to run the Set-AVMModule
script again as the deployment will be addded to the readme's 'Usage Examples'.
Finally, you ideally run the test case in your fork using the module's workflow (assuming you have set it up), or at least using the Test-ModuleLocally
script with some indicator that the test worked. We have to ensure it does before merging the change in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @AlexanderSehr ! Thanks again for all the help yesterday! I will have a look at this tomorrow!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. @JPEasier, please resolve this comment once addressed as I'll be out of office for the next 2.5 weeks
Description
I added the diagnostics parameter for Log Analytics. However, I was unable to fully test the changes due to issues with the local setup. I would appreciate it if someone with a working environment could verify and complete the testing.
Fixes #3519
-->
Pipeline Reference
Type of Change
version.json
:version.json
.version.json
.Checklist
Set-AVMModule
locally to generate the supporting module files.