PowerShell / PSArm

PSArm is a PowerShell module that provides a PowerShell-embedded domain-specific language (DSL) for Azure Resource Manager (ARM) templates
MIT License
78 stars 19 forks source link

publish-PSArmTemplate fails to find diagnosticSettings resource #161

Open prestonr83 opened 3 years ago

prestonr83 commented 3 years ago

The following valid ARM syntax

{
    "apiVersion": "2017-05-01-preview",
    "name": "[concat('test', '/Microsoft.Insights/diagnosticSettings')]",
    "type": "Microsoft.Network/applicationGateways/providers/diagnosticSettings",
    "location": "[resourceGroup().location]",
    "dependsOn": [
        "[concat('Microsoft.Network/ApplicationGateways/', 'test')]"
    ],
    "properties": {
        "name": "Diag",
        "workspaceId": "[concat('/subscriptions/', subscription().subscriptionId,  '/resourceGroups/', resourceGroup().name, '/providers/microsoft.operationalinsights/workspaces/', 'test')]",
        "logs": [
            {
                "category": "ApplicationGatewayAccessLog",
                "enabled": true,
                "retentionPolicy": {
                    "enabled": false,
                    "days": 0
                }
            },
            {
                "category": "ApplicationGatewayPerformanceLog",
                "enabled": true,
                "retentionPolicy": {
                    "days": 0,
                    "enabled": false
                }
            },
            {
                "category": "ApplicationGatewayFirewallLog",
                "enabled": true,
                "retentionPolicy": {
                    "days": 0,
                    "enabled": false
                }
            }
        ],
        "metrics": [
            {
                "category": "AllMetrics",
                "enabled": true,
                "retentionPolicy": {
                    "enabled": false,
                    "days": 0
                }
            }
        ]
    }
}

Written as follows in PSArm

Resource (concat 'test' '/Microsoft.Insights/diagnosticSettings') -Namespace 'Microsoft.Network' -Type 'applicationGateways/providers/diagnosticSettings' -ApiVersion '2017-05-01-preview' -Location (resourceGroup).location {
    properties {
      name 'Diag'
      workspaceId concat '/subscriptions/' (subscription).subscriptionId '/resourceGroups/' (resourceGroup).name '/providers/microsoft.operationalinsights/workspaces/' 'test'
      logs {
        category 'ApplicationGatewayAccessLog'
        enabled $true
        retentionPolicy {
          enabled $false
          days 0
        }
      }
      logs {
        category 'ApplicationGatewayPerformanceLog'
        enabled $true
        retentionPolicy {
          days 0
          enabled $false
        }
      }
      logs {
        category 'ApplicationGatewayFirewallLog'
        enabled $true
        retentionPolicy {
          days 0
          enabled $false
        }
      }
      metrics {
        category 'AllMetrics'
        enabled $true
        retentionPolicy {
          enabled $false
          days 0
        }
      }
    }
    DependsOn @(
      concat 'Microsoft.Network/ApplicationGateways/' 'test'
    )
  }

However, when you execute publish-PSArmTemplate it fails with the following error.

publish-PSArmTemplate : Unable to find resource
'Microsoft.Network/applicationGateways/providers/diagnosticSettings@2017-05-01-preview'
At line:1 char:1
+ publish-PSArmTemplate -path .\template.psarm.ps1 -outFile test2.json  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Netwo...7-05-01-preview:String) [Publish-PSArmTemplate], KeyN
   otFoundException
    + FullyQualifiedErrorId : ResourceNotFound,PSArm.Commands.PublishPSArmTemplateCommand