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

log activities from subscriptions used in an MLZ deployment into the Operations log analytics workspace #412

Merged
merged 15 commits into from
Sep 16, 2021
Merged
60 changes: 44 additions & 16 deletions src/bicep/mlz.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -253,54 +253,82 @@ module sharedServicesVirtualNetworkPeering './modules/spokeNetworkPeering.bicep'
}

module hubPolicyAssignment './modules/policyAssignment.bicep' = {
name: '${hubResourceGroupName}-policyAssignement'
name: 'deploy-hub-policyAssignement'
shawngib marked this conversation as resolved.
Show resolved Hide resolved
scope: resourceGroup(hubSubscriptionId, hubResourceGroupName)
dependsOn: [
hubResourceGroup
logAnalyticsWorkspace
]
params: {
builtInAssignment: policy
logAnalyticsWorkspaceName: logAnalyticsWorkspace.outputs.name
logAnalyticsWorkspaceResourceGroupName: operationsResourceGroup.outputs.name
opsSubscriptionId: operationsSubscriptionId
shawngib marked this conversation as resolved.
Show resolved Hide resolved
}
}

module operationsPolicyAssignment './modules/policyAssignment.bicep' = {
name: '${operationsResourceGroupName}-policyAssignment'
name: 'deploy-operations-policyAssignment'
shawngib marked this conversation as resolved.
Show resolved Hide resolved
scope: resourceGroup(operationsSubscriptionId, operationsResourceGroupName)
params: {
builtInAssignment: policy
logAnalyticsWorkspaceName: logAnalyticsWorkspace.outputs.name
logAnalyticsWorkspaceResourceGroupName: operationsResourceGroup.outputs.name
opsSubscriptionId: operationsSubscriptionId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
opsSubscriptionId: operationsSubscriptionId
operationsSubscriptionId: operationsSubscriptionId

}
}

module sharedServicesPolicyAssignment './modules/policyAssignment.bicep' = {
name: '${sharedServicesResourceGroupName}-policyAssignement'
name: 'deploy-shareServices-policyAssignement'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same naming collision concern as the hub assignment

scope: resourceGroup(sharedServicesSubscriptionId, sharedServicesResourceGroupName)
dependsOn: [
sharedServicesResourceGroup
logAnalyticsWorkspace
]
params: {
builtInAssignment: policy
logAnalyticsWorkspaceName: logAnalyticsWorkspace.outputs.name
logAnalyticsWorkspaceResourceGroupName: operationsResourceGroup.outputs.name
opsSubscriptionId: operationsSubscriptionId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
opsSubscriptionId: operationsSubscriptionId
operationsSubscriptionId: operationsSubscriptionId

}
}

module identityPolicyAssignment './modules/policyAssignment.bicep' = {
name: '${identityResourceGroupName}-policyAssignement'
name: 'deploy-identity-policyAssignement'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same naming collision concern as the hub assignment

scope: resourceGroup(identitySubscriptionId, identityResourceGroupName)
dependsOn: [
identityResourceGroup
logAnalyticsWorkspace
]
params: {
builtInAssignment: policy
logAnalyticsWorkspaceName: logAnalyticsWorkspace.outputs.name
logAnalyticsWorkspaceResourceGroupName: operationsResourceGroup.outputs.name
opsSubscriptionId: operationsSubscriptionId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
opsSubscriptionId: operationsSubscriptionId
operationsSubscriptionId: operationsSubscriptionId

}
}

module hubSubscriptionCreateActivityLogging './modules/centralLogging.bicep' = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be consistent with the module names "<hub/identity/operations/sharedServices>Thing"

Suggested change
module hubSubscriptionCreateActivityLogging './modules/centralLogging.bicep' = {
module hubLogging './modules/centralLogging.bicep' = {

name: 'deploy-hub-sub-activity-logging'
scope: subscription(hubSubscriptionId)
params: {
logAnalyticsWorkspaceId: logAnalyticsWorkspace.outputs.id
deploymentName: resourcePrefix
}
}

module opsSubscriptionCreateActivityLogging './modules/centralLogging.bicep' = if(!(hubSubscriptionId == operationsSubscriptionId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be consistent with the module names "<hub/identity/operations/sharedServices>Thing"

Also, could these comparisons could be simplified as if(value1 != value2)?

Suggested change
module opsSubscriptionCreateActivityLogging './modules/centralLogging.bicep' = if(!(hubSubscriptionId == operationsSubscriptionId)) {
module operationsLogging './modules/centralLogging.bicep' = if(operationsSubscriptionId != hubSubscriptionId) {

name: 'deploy-ops-sub-activity-logging'
shawngib marked this conversation as resolved.
Show resolved Hide resolved
shawngib marked this conversation as resolved.
Show resolved Hide resolved
scope: subscription(operationsSubscriptionId)
params: {
logAnalyticsWorkspaceId: logAnalyticsWorkspace.outputs.id
deploymentName: resourcePrefix
}
}

module identSubscriptionCreateActivityLogging './modules/centralLogging.bicep' = if(!(hubSubscriptionId == identitySubscriptionId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be consistent with the module names "<hub/identity/operations/sharedServices>Thing"

Also, could these comparisons could be simplified as if(value1 != value2)?

Suggested change
module identSubscriptionCreateActivityLogging './modules/centralLogging.bicep' = if(!(hubSubscriptionId == identitySubscriptionId)) {
module identityLogging './modules/centralLogging.bicep' = if(identitySubscriptionId != hubSubscriptionId) {

name: 'deploy-ident-sub-activity-logging'
shawngib marked this conversation as resolved.
Show resolved Hide resolved
shawngib marked this conversation as resolved.
Show resolved Hide resolved
scope: subscription(identitySubscriptionId)
params: {
logAnalyticsWorkspaceId: logAnalyticsWorkspace.outputs.id
deploymentName: resourcePrefix
}
}

module sharedSubscriptionCreateActivityLogging './modules/centralLogging.bicep' = if(!(hubSubscriptionId == sharedServicesSubscriptionId)) {
shawngib marked this conversation as resolved.
Show resolved Hide resolved
name: 'deploy-shared-sub-activity-logging'
shawngib marked this conversation as resolved.
Show resolved Hide resolved
shawngib marked this conversation as resolved.
Show resolved Hide resolved
scope: subscription(sharedServicesSubscriptionId)
params: {
logAnalyticsWorkspaceId: logAnalyticsWorkspace.outputs.id
deploymentName: resourcePrefix
}
}

Expand Down
48 changes: 48 additions & 0 deletions src/bicep/modules/centralLogging.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// scope
targetScope = 'subscription'

param logAnalyticsWorkspaceId string
param deploymentName string

//// Central activity logging to LAWS
resource somethingNew 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
shawngib marked this conversation as resolved.
Show resolved Hide resolved
name: 'LoggingToLA-${deploymentName}'
properties: {
workspaceId: logAnalyticsWorkspaceId
logs: [
{
category: 'Administrative'
enabled: true
}
{
category: 'Security'
enabled: true
}
{
category: 'ServiceHealth'
enabled: true
}
{
category: 'Alert'
enabled: true
}
{
category: 'Recommendation'
enabled: true
}
{
category: 'Policy'
enabled: true
}
{
category: 'Autoscale'
enabled: true
}
{
category: 'ResourceHealth'
enabled: true
}
]
}

}
3 changes: 2 additions & 1 deletion src/bicep/modules/policyAssignment.bicep
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
param builtInAssignment string = ''
param logAnalyticsWorkspaceName string
param logAnalyticsWorkspaceResourceGroupName string
param opsSubscriptionId string
shawngib marked this conversation as resolved.
Show resolved Hide resolved

// Creating a symbolic name for an existing resource
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' existing = {
name: logAnalyticsWorkspaceName
scope: resourceGroup(logAnalyticsWorkspaceResourceGroupName)
scope: resourceGroup(opsSubscriptionId, logAnalyticsWorkspaceResourceGroupName)
shawngib marked this conversation as resolved.
Show resolved Hide resolved
}

var policyDefinitionID = {
Expand Down