Arm 模板不会部署。说缺少 NSG 资源,但它包含在模板中

Arm template will not deploy. Says missing NSG resource, but it's included in the template

问题:这是用 Azure 管道部署的,并且已通过本地验证和 vscode ide 验证。我已经尝试了在 MSFT 文档中找到的所有解决方案,以及在 SOF 中找到的多个解决方案。我无法部署这个东西。

我遇到的错误:


    ##[error]Deployment template validation failed: 'The resource 'Microsoft.Network/networkSecurityGroups/UnityServer-NSG-XXXXXXXX-XXXXXXXX' is not defined in the template.
    ##[warning]Validation errors were found in the Azure Resource Manager template. 
    Starting Deployment.
    Deployment name is XXXXXXX-XXXXXXXX-unityserver-deploy
    There were errors in your deployment. Error code: DeploymentFailed.
    ##[error]At least one resource deployment operation failed. Please list deployment 
        "code": "InvalidTemplate",
        "message": "Deployment template validation failed: 'The resource 'Microsoft.Network/networkSecurityGroups/UnityServer-NSG-XXXXXXX-XXXXXXX' is not defined in the template. 
    ##[error]Task failed while creating or updating the template deployment.

有问题的模板:


    {
        "$schema": "X",
        "contentVersion": "1.0.0.0",
        "parameters": {
          "Subscription-Id": {
            "defaultValue": "XXXXXXXXX",
            "type": "string"
          },
          "Environment": {
            "defaultValue": "XXXXXXX",
            "type": "String"
          },
          "Location": {
            "defaultValue": "XXXXXXX",
            "type": "String"
          },
          "IsThisProduction": {
            "defaultValue": "false",
            "allowedValues": [
              "false",
              "true"
            ],
            "type": "String"
          },
          "Unity-Server-Resource-Group-Name": {
            "type": "String",
            "defaultValue": "UnityServer-RG-Env-Location"
          },
          "UberMgmt-Resource-Group-Name-For-Region": {
            "type": "String",
            "defaultValue": "andrew_blue-green_mgmt"
          },
          "UberMgmt-VNET-Name-For-Region": {
            "type": "String",
            "defaultValue": "XXXXXXXXX"
          },
          "UberMgmt-VNET-Subnet-Name-For-Region": {
            "type": "string",
            "defaultValue": "XXXXXXXXXXX"
          },
          "Unity-Server-VM-Name": {
            "defaultValue": "XXXXXXXXXXX",
            "type": "String"
          },
          "Unity-Server-NIC-Name": {
            "defaultValue": "XXXXXXXXXXXX",
            "type": "String"
          },
          "Unity-Server-PublicIp-Reservation-Name": {
            "defaultValue": "XXXXXXXXXXXX",
            "type": "String"
          },
          "Unity-Server-Storage-Account-Name": {
            "defaultValue": "XXXXXXXXXXXX",
            "type": "String"
          },
          "Unity-Server-NSG-Name": {
            "defaultValue": "UnityServer-NSG-Env-Location",
            "type": "String"
          },
          "Unity-Server-Backup-Services-Vault-Name": {
            "defaultValue": "XXXXXXXXXXXX",
            "type": "String"
          },
          "XXXXXXXXXXXXBaseImageGallery-External-Id": {
            "defaultValue": "galleryID string here",
            "type": "String"
          }
        },
        "variables": {
          "Prod-Or-Non-Prod": "[if(equals(parameters('IsThisProduction'), 'true'), 'Prod', 'Non-Prod')]",
          "Deployment-Name": "[concat('XXXXXXXXXXXX-Deploy-', parameters('Environment'), '-', parameters('Location'))]"
        },
        "resources": [
          {
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2021-04-01",
            "location": "[parameters('Location')]",
            "name": "[parameters('Unity-Server-Resource-Group-Name')]",
            "properties": {},
            "tags": {
              "VantaDescription": "[concat('UnityServer-', parameters('Environment'), '-', parameters('Location'), '-RG-', string(variables('Prod-Or-Non-Prod')))]",
              "VantaNonProd": "parameters('IsThisProduction')",
              "VantaContainsUserData": "false",
              "VantaUserDataStored": "n/a",
              "VantaOwner": "Devops"
            }
          },
          {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2020-10-01",
            "name": "[string(variables('Deployment-Name'))]",
            "resourceGroup": "[parameters('Unity-Server-Resource-Group-Name')]",
            "dependsOn": [
              "[resourceId('Microsoft.Resources/resourceGroups', parameters('Unity-Server-Resource-Group-Name'))]"
            ],
            "properties": {
              "mode": "Incremental",
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {},
                "variables": {},
                "resources": [
                  {
                    "type": "Microsoft.Network/networkSecurityGroups",
                    "apiVersion": "2020-11-01",
                    "name": "[parameters('Unity-Server-NSG-Name')]",
                    "location": "[parameters('Location')]",
                    "tags": {
                      "VantaDescription": "[concat('UnityServer-', parameters('Environment'), '-', parameters('Location'), '-NSG-', string(variables('Prod-Or-Non-Prod')))]",
                      "VantaNonProd": "parameters('IsThisProduction')",
                      "VantaContainsUserData": "false",
                      "VantaUserDataStored": "n/a",
                      "VantaOwner": "Devops"
                    },
                    "properties": {}
                  },
                  {
                    "type": "Microsoft.Network/publicIPAddresses",
                    "apiVersion": "2020-11-01",
                    "name": "[parameters('Unity-Server-PublicIp-Reservation-Name')]",
                    "location": "eastus",
                    "tags": {tagshere},
                    "sku": {
                      "name": "Standard",
                      "tier": "Regional"
                    },
                    "zones": [
                      "1"
                    ],
                    "properties": {
                      "ipAddress": "XXXXXXXXXXXX",
                      "publicIPAddressVersion": "IPv4",
                      "publicIPAllocationMethod": "Static",
                      "idleTimeoutInMinutes": 4,
                      "ipTags": []
                    }
                  },
                  {
                    "type": "Microsoft.RecoveryServices/vaults",
                    "apiVersion": "2021-03-01",
                    "name": "[parameters('Unity-Server-Backup-Services-Vault-Name')]",
                    "location": "eastus",
                    "tags": {
                      "VantaDescription": "[concat('UnityServer-', parameters('Environment'), '-', parameters('Location'), '-Backup-Services-Vault-', string(variables('Prod-Or-Non-Prod')))]",
                      "VantaNonProd": "parameters('IsThisProduction')",
                      "VantaContainsUserData": "false",
                      "VantaUserDataStored": "n/a",
                      "VantaOwner": "Devops"
                    },
                    "sku": {
                      "name": "RS0",
                      "tier": "Standard"
                    },
                    "properties": {}
                  },
                  {
                    "type": "Microsoft.Storage/storageAccounts",
                    "apiVersion": "2021-04-01",
                    "name": "[parameters('Unity-Server-Storage-Account-Name')]",
                    "location": "eastus",
                    "tags": {
                      "VantaDescription": "[concat('UnityServer-', parameters('Environment'), '-', parameters('Location'), '-Diag-Storage-Account-', string(variables('Prod-Or-Non-Prod')))]",
                      "VantaNonProd": "parameters('IsThisProduction')",
                      "VantaContainsUserData": "false",
                      "VantaUserDataStored": "n/a",
                      "VantaOwner": "Devops"
                    },
                    "sku": {
                      "name": "Standard_GRS",
                      "tier": "Standard"
                    },
                    "kind": "StorageV2",
                    "properties": {
                      "minimumTlsVersion": "TLS1_2",
                      "networkAcls": {
                        "bypass": "AzureServices",
                        "virtualNetworkRules": [],
                        "ipRules": [],
                        "defaultAction": "Allow"
                      },
                      "supportsHttpsTrafficOnly": true,
                      "encryption": {
                        "services": {
                          "file": {
                            "keyType": "Account",
                            "enabled": true
                          },
                          "blob": {
                            "keyType": "Account",
                            "enabled": true
                          }
                        },
                        "keySource": "Microsoft.Storage"
                      },
                      "accessTier": "Hot"
                    }
                  },
                  {
                    "type": "Microsoft.Compute/virtualMachines",
                    "apiVersion": "2021-03-01",
                    "name": "[parameters('Unity-Server-VM-Name')]",
                    "location": "eastus",
                    "dependsOn": [],
                    "tags": {
                      "VantaDescription": "[concat('UnityServer-', parameters('Environment'), '-', parameters('Location'), '-Virtual-Machine-', string(variables('Prod-Or-Non-Prod')))]",
                      "VantaNonProd": "parameters('IsThisProduction')",
                      "VantaContainsUserData": true,
                      "VantaUserDataStored": "XXXXXXXXXXXX",
                      "VantaOwner": "Devops"
                    },
                    "zones": [
                      "1"
                    ],
                    "properties": {
                      "hardwareProfile": {
                        "vmSize": "Standard_B2s"
                      },
                      "storageProfile": {
                        "imageReference": {
                          "id": "[concat(parameters('XXXXXXXXXXXXBaseImageGallery-External-Id'), '/images/XXXXXXXXXXXXBaseImage-Centos8.3-gen2')]"
                        },
                        "osDisk": {
                          "osType": "Linux",
                          "name": "[concat(parameters('Unity-Server-VM-Name'), '_OsDisk')]",
                          "createOption": "FromImage",
                          "caching": "ReadWrite",
                          "managedDisk": {
                            "storageAccountType": "Premium_LRS"
                          },
                          "diskSizeGB": 30
                        },
                        "dataDisks": []
                      },
                      "networkProfile": {
                        "networkInterfaces": [
                          {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('Unity-Server-NIC-Name'))]"
                          }
                        ]
                      },
                      "diagnosticsProfile": {
                        "bootDiagnostics": {
                          "enabled": true
                        }
                      }
                    }
                  },
                  {
                    "type": "Microsoft.Network/networkSecurityGroups/securityRules",
                    "apiVersion": "2020-11-01",
                    "name": "[concat(parameters('Unity-Server-NSG-Name'), '/SSH')]",
                    "dependsOn": [
                      "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('Unity-Server-NSG-Name'))]"
                    ],
                    "properties": {
                      "protocol": "TCP",
                      "sourcePortRange": "*",
                      "destinationPortRange": "22",
                      "sourceAddressPrefix": "*",
                      "destinationAddressPrefix": "*",
                      "access": "Allow",
                      "priority": 300,
                      "direction": "Inbound",
                      "sourcePortRanges": [],
                      "destinationPortRanges": [],
                      "sourceAddressPrefixes": [],
                      "destinationAddressPrefixes": []
                    }
                  },
                  {
                    "type": "Microsoft.RecoveryServices/vaults/backupPolicies",
                    "apiVersion": "2021-03-01",
                    "name": "[concat(parameters('Unity-Server-Backup-Services-Vault-Name'), '/DefaultPolicy')]",
                    "tags": {
                      "VantaDescription": "[concat('UnityServer-', parameters('Environment'), '-', parameters('Location'), '-Backup-Policy-Default-Policy-', string(variables('Prod-Or-Non-Prod')))]",
                      "VantaNonProd": "parameters('IsThisProduction')",
                      "VantaContainsUserData": "false",
                      "VantaUserDataStored": "n/a",
                      "VantaOwner": "Devops"
                    },
                    "dependsOn": [
                      "[resourceId('Microsoft.RecoveryServices/vaults', parameters('Unity-Server-Backup-Services-Vault-Name'))]"
                    ],
                    "properties": {
                      "backupManagementType": "AzureIaasVM",
                      "instantRPDetails": {},
                      "schedulePolicy": {
                        "schedulePolicyType": "SimpleSchedulePolicy",
                        "scheduleRunFrequency": "Daily",
                        "scheduleRunTimes": [
                          "2021-06-15T01:00:00Z"
                        ],
                        "scheduleWeeklyFrequency": 0
                      },
                      "retentionPolicy": {
                        "retentionPolicyType": "LongTermRetentionPolicy",
                        "dailySchedule": {
                          "retentionTimes": [
                            "2021-06-15T01:00:00Z"
                          ],
                          "retentionDuration": {
                            "count": 30,
                            "durationType": "Days"
                          }
                        }
                      },
                      "instantRpRetentionRangeInDays": 2,
                      "timeZone": "UTC",
                      "protectedItemsCount": 0
                    }
                  },
                  {
                    "type": "Microsoft.RecoveryServices/vaults/backupPolicies",
                    "apiVersion": "2021-03-01",
                    "name": "[concat(parameters('Unity-Server-Backup-Services-Vault-Name'), '/HourlyLogBackup')]",
                    "tags": {
                      "VantaDescription": "[concat('UnityServer-', parameters('Environment'), '-', parameters('Location'), '-Backup-Policy-Hourly-Log-Backup-', string(variables('Prod-Or-Non-Prod')))]",
                      "VantaNonProd": "parameters('IsThisProduction')",
                      "VantaContainsUserData": "false",
                      "VantaUserDataStored": "n/a",
                      "VantaOwner": "Devops"
                    },
                    "dependsOn": [
                      "[resourceId('Microsoft.RecoveryServices/vaults', parameters('Unity-Server-Backup-Services-Vault-Name'))]"
                    ],
                    "properties": {
                      "backupManagementType": "AzureWorkload",
                      "workLoadType": "SQLDataBase",
                      "settings": {
                        "timeZone": "UTC",
                        "issqlcompression": false,
                        "isCompression": false
                      },
                      "subProtectionPolicy": [
                        {
                          "policyType": "Full",
                          "schedulePolicy": {
                            "schedulePolicyType": "SimpleSchedulePolicy",
                            "scheduleRunFrequency": "Daily",
                            "scheduleRunTimes": [
                              "2021-06-15T01:00:00Z"
                            ],
                            "scheduleWeeklyFrequency": 0
                          },
                          "retentionPolicy": {
                            "retentionPolicyType": "LongTermRetentionPolicy",
                            "dailySchedule": {
                              "retentionTimes": [
                                "2021-06-15T01:00:00Z"
                              ],
                              "retentionDuration": {
                                "count": 30,
                                "durationType": "Days"
                              }
                            }
                          }
                        },
                        {
                          "policyType": "Log",
                          "schedulePolicy": {
                            "schedulePolicyType": "LogSchedulePolicy",
                            "scheduleFrequencyInMins": 60
                          },
                          "retentionPolicy": {
                            "retentionPolicyType": "SimpleRetentionPolicy",
                            "retentionDuration": {
                              "count": 30,
                              "durationType": "Days"
                            }
                          }
                        }
                      ],
                      "protectedItemsCount": 0
                    }
                  },
                  {
                    "type": "Microsoft.RecoveryServices/vaults/backupPolicies",
                    "apiVersion": "2021-03-01",
                    "name": "[concat(parameters('Unity-Server-Backup-Services-Vault-Name'), '/UnityServerEastusBackupPolicy')]",
                    "tags": {
                      "VantaDescription": "[concat('UnityServer-', parameters('Environment'), '-', parameters('Location'), '-Backup-Policy-Unity-Server-', string(variables('Prod-Or-Non-Prod')))]",
                      "VantaNonProd": "parameters('IsThisProduction')",
                      "VantaContainsUserData": "false",
                      "VantaUserDataStored": "n/a",
                      "VantaOwner": "Devops"
                    },
                    "dependsOn": [
                      "[resourceId('Microsoft.RecoveryServices/vaults', parameters('Unity-Server-Backup-Services-Vault-Name'))]"
                    ],
                    "properties": {
                      "backupManagementType": "AzureIaasVM",
                      "instantRPDetails": {
                        "azureBackupRGNamePrefix": "[concat(parameters('Unity-Server-Resource-Group-Name'), 'backup')]",
                        "azureBackupRGNameSuffix": "[concat(parameters('Unity-Server-Resource-Group-Name'), 'unityserver')]"
                      },
                      "schedulePolicy": {
                        "schedulePolicyType": "SimpleSchedulePolicy",
                        "scheduleRunFrequency": "Daily",
                        "scheduleRunTimes": [
                          "2021-06-14T08:00:00Z"
                        ],
                        "scheduleWeeklyFrequency": 0
                      },
                      "retentionPolicy": {
                        "retentionPolicyType": "LongTermRetentionPolicy",
                        "dailySchedule": {
                          "retentionTimes": [
                            "2021-06-14T08:00:00Z"
                          ],
                          "retentionDuration": {
                            "count": 30,
                            "durationType": "Days"
                          }
                        },
                        "weeklySchedule": {
                          "daysOfTheWeek": [
                            "Sunday"
                          ],
                          "retentionTimes": [
                            "2021-06-14T08:00:00Z"
                          ],
                          "retentionDuration": {
                            "count": 4,
                            "durationType": "Weeks"
                          }
                        },
                        "monthlySchedule": {
                          "retentionScheduleFormatType": "Weekly",
                          "retentionScheduleWeekly": {
                            "daysOfTheWeek": [
                              "Sunday"
                            ],
                            "weeksOfTheMonth": [
                              "First"
                            ]
                          },
                          "retentionTimes": [
                            "2021-06-14T08:00:00Z"
                          ],
                          "retentionDuration": {
                            "count": 12,
                            "durationType": "Months"
                          }
                        },
                        "yearlySchedule": {
                          "retentionScheduleFormatType": "Weekly",
                          "monthsOfYear": [
                            "January"
                          ],
                          "retentionScheduleWeekly": {
                            "daysOfTheWeek": [
                              "Sunday"
                            ],
                            "weeksOfTheMonth": [
                              "First"
                            ]
                          },
                          "retentionTimes": [
                            "2021-06-14T08:00:00Z"
                          ],
                          "retentionDuration": {
                            "count": 3,
                            "durationType": "Years"
                          }
                        }
                      },
                      "instantRpRetentionRangeInDays": 3,
                      "timeZone": "UTC",
                      "protectedItemsCount": 0
                    }
                  },
                  {
                    "type": "Microsoft.RecoveryServices/vaults/replicationAlertSettings",
                    "apiVersion": "2021-03-01",
                    "name": "[concat(parameters('Unity-Server-Backup-Services-Vault-Name'), '/defaultAlertSetting')]",
                    "dependsOn": [
                      "[resourceId('Microsoft.RecoveryServices/vaults', parameters('Unity-Server-Backup-Services-Vault-Name'))]"
                    ],
                    "properties": {
                      "sendToOwners": "DoNotSend",
                      "customEmailAddresses": []
                    }
                  },
                  {
                    "type": "Microsoft.RecoveryServices/vaults/replicationVaultSettings",
                    "apiVersion": "2021-03-01",
                    "name": "[concat(parameters('Unity-Server-Backup-Services-Vault-Name'), '/default')]",
                    "dependsOn": [
                      "[resourceId('Microsoft.RecoveryServices/vaults', parameters('Unity-Server-Backup-Services-Vault-Name'))]"
                    ],
                    "properties": {}
                  },
                  {
                    "type": "Microsoft.Storage/storageAccounts/blobServices",
                    "apiVersion": "2021-04-01",
                    "name": "[concat(parameters('Unity-Server-Storage-Account-Name'), '/default')]",
                    "dependsOn": [
                      "[resourceId('Microsoft.Storage/storageAccounts', parameters('Unity-Server-Storage-Account-Name'))]"
                    ],
                    "sku": {
                      "name": "Standard_GRS",
                      "tier": "Standard"
                    },
                    "properties": {
                      "cors": {
                        "corsRules": []
                      },
                      "deleteRetentionPolicy": {
                        "enabled": false
                      }
                    }
                  },
                  {
                    "type": "Microsoft.Storage/storageAccounts/fileServices",
                    "apiVersion": "2021-04-01",
                    "name": "[concat(parameters('Unity-Server-Storage-Account-Name'), '/default')]",
                    "dependsOn": [
                      "[resourceId('Microsoft.Storage/storageAccounts', parameters('Unity-Server-Storage-Account-Name'))]"
                    ],
                    "sku": {
                      "name": "Standard_GRS",
                      "tier": "Standard"
                    },
                    "properties": {
                      "protocolSettings": {
                        "smb": {}
                      },
                      "cors": {
                        "corsRules": []
                      },
                      "shareDeleteRetentionPolicy": {
                        "enabled": true,
                        "days": 7
                      }
                    }
                  },
                  {
                    "type": "Microsoft.Storage/storageAccounts/queueServices",
                    "apiVersion": "2021-04-01",
                    "name": "[concat(parameters('Unity-Server-Storage-Account-Name'), '/default')]",
                    "dependsOn": [
                      "[resourceId('Microsoft.Storage/storageAccounts', parameters('Unity-Server-Storage-Account-Name'))]"
                    ],
                    "properties": {
                      "cors": {
                        "corsRules": []
                      }
                    }
                  },
                  {
                    "type": "Microsoft.Storage/storageAccounts/tableServices",
                    "apiVersion": "2021-04-01",
                    "name": "[concat(parameters('Unity-Server-Storage-Account-Name'), '/default')]",
                    "dependsOn": [
                      "[resourceId('Microsoft.Storage/storageAccounts', parameters('Unity-Server-Storage-Account-Name'))]"
                    ],
                    "properties": {
                      "cors": {
                        "corsRules": []
                      }
                    }
                  },
                  {
                    "type": "Microsoft.Network/networkInterfaces",
                    "apiVersion": "2020-11-01",
                    "name": "[parameters('Unity-Server-NIC-Name')]",
                    "location": "eastus",
                    "dependsOn": [
                      "[resourceId('Microsoft.Network/publicIPAddresses', parameters('Unity-Server-PublicIp-Reservation-Name'))]",
                      "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('Unity-Server-NSG-Name'))]"
                    ],
                    "tags": {
                      "VantaDescription": "[concat('UnityServer-', parameters('Environment'), '-', parameters('Location'), '-NIC-', string(variables('Prod-Or-Non-Prod')))]",
                      "VantaNonProd": "parameters('IsThisProduction')",
                      "VantaContainsUserData": "false",
                      "VantaUserDataStored": "n/a",
                      "VantaOwner": "Devops"
                    },
                    "properties": {
                      "ipConfigurations": [
                        {
                          "name": "ipconfig1",
                          "properties": {
                            "privateIPAllocationMethod": "Dynamic",
                            "publicIPAddress": {
                              "id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('Unity-Server-PublicIp-Reservation-Name'))]"
                            },
                            "subnet": {
                              "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('UberMgmt-VNET-Name-For-Region'), parameters('UberMgmt-VNET-Subnet-Name-For-Region'))]"
                            },
                            "primary": true,
                            "privateIPAddressVersion": "IPv4"
                          }
                        }
                      ],
                      "dnsSettings": {
                        "dnsServers": []
                      },
                      "enableAcceleratedNetworking": false,
                      "enableIPForwarding": false,
                      "networkSecurityGroup": {
                        "id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('Unity-Server-NSG-Name'))]"
                      }
                    }
                  }
                ],
                "outputs": {}
              }
            }
          }
        ]
      }

我之前遇到过包含网络组件的 ARM 模板的计时问题。我在 ARM 模板中创建了一个包含 VNET 组件的网站,问题是它将开始 VNET 部署,然后该网站将尝试部署,但 VNET 尚未创建,它正在进行中。我最终编写了两个 ARM 模板,一个创建 RSG 和网络组件,然后第二个将在网络端完成部署后创建网站。