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

what-if ignores a module #238

Closed
flobeier opened this issue Nov 29, 2021 · 1 comment
Closed

what-if ignores a module #238

flobeier opened this issue Nov 29, 2021 · 1 comment

Comments

@flobeier
Copy link

Describe the bug
A module is ignored.

To Reproduce

  1. Create SQL Server and two databases
  2. Update parameters to fit chosen names
  3. Run az deployment sub create --subscription <subscription ID> --parameters main.parameters.json --template-file main.bicep --what-if --location <location>

main.bicep

targetScope='subscription'

param resourceGroup string
param location string = 'germanywestcentral'
param environment string
param sqlServerName string
param sqlDbNames array
param tags object

resource mainRG 'Microsoft.Resources/resourceGroups@2021-04-01' existing = {
  name: resourceGroup
}

module logAnalytics 'logAnalytics.bicep' = {
  name: 'LogAnalyticsWorkspace'
  scope: mainRG
  params: {
    workspaceName: 'law-${environment}-main'
    location: location
    tags: tags
  }
}

module sql 'sql.bicep' = {
  name: 'SQLConfiguration'
  scope: mainRG
  params: {
    dbNames: sqlDbNames
    serverName: sqlServerName
    logAnalyticsWorkspace: logAnalytics.outputs.id
  }
}

logAnalytics.bicep

param workspaceName string
param location string
param tags object

resource workspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
  name: workspaceName
  location: location
  tags: tags
}

output id string = workspace.id

sql.bicep

param dbNames array
param logAnalyticsWorkspace string
param serverName string
param dbLogCategories array = [
  'SQLInsights'
  'AutomaticTuning'
  'QueryStoreRuntimeStatistics'
  'QueryStoreWaitStatistics'
  'Errors'
  'DatabaseWaitStatistics'
  'Timeouts'
  'Blocks'
  'Deadlocks'
]

resource sqlServer 'Microsoft.Sql/servers@2021-05-01-preview' existing = {
  name: serverName
}

resource dbs 'Microsoft.Sql/servers/databases@2021-05-01-preview' existing = [for db in dbNames: {
  parent: sqlServer
  name: db
}]

resource serverAuditSetting 'Microsoft.Sql/servers/auditingSettings@2021-05-01-preview' = {
  name: 'default'
  parent: sqlServer
  properties: {
    isAzureMonitorTargetEnabled: true
    state: 'Enabled'
  }
  dependsOn: [
    serverDiagSetting
  ]
}

resource serverDiagSetting 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
  name: 'logToLogAnalytics'
  scope: sqlServer
  properties: {
    workspaceId: logAnalyticsWorkspace
  }
}

resource dbDiagSetting 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = [for (db, i) in dbNames: {
  name: 'logToLogAnalytics'
  scope: dbs[i]
  properties: {
    logs: [for category in dbLogCategories : {
      category: category
      enabled: true
    }]
    workspaceId: logAnalyticsWorkspace
  }
}]

main.parameters.json

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "sqlServerName": {
      "value": "sqlserver-prod"
    },
    "sqlDbNames": {
      "value": [
        "db1",
        "db2"
      ]
    },
    "environment": {
      "value": "prod"
    },
    "resourceGroup": {
      "value": "rg-prod"
    },
    "location": {
      "value": "germanywestcentral"
    },
    "tags": {
      "value": {
        "Name": "MyResources",
        "Environment": "prod"
      }
    }
  }
}

Expected behavior
what-if displays the actions that will be taken on the SQL server and the databases.

Actual behavior
what-if shows only actions that the module logAnalytics will perform. The module sql appears to be ignored during what-if but NOT during the actual deployment.

Client [e.g. PowerShell, CLI, API)
Azure CLI 2.30.0 (Cloud Shell)

@ghost ghost added the Needs Triage 🔍 label Nov 29, 2021
@alex-frankel
Copy link
Contributor

Closing as dup of #157

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants