2017-08-15 104 views
1

我正在研究一個ARM模板,它會詢問逗號分隔的數據庫名稱列表,然後使用copyIndex函數創建它們。這方面的工作很好,但我的解決方案的下一步不是。接下來我要做的是爲每個數據庫導入一個.bacpac文件,以便它可以在完成時使用。azure SQL數據庫導入副本

驗證錯誤表明問題與導入資源dependsOn中的concat函數有關。我已經測試了它幾種不同的方式,並且看不到它出錯的地方。

我看到確切的錯誤信息是....

Unable to process template language expressions for resource '/subscriptions/xxxxxx-xxxxx-xxxxxx-xxxxx/resourceGroups/testGroup/providers/Microsoft.Sql/servers/testsql/databases/CustomersDB/extensions/import' at line '858' and column '10'. 'The provided parameters for language function 'concat' are invalid. Either all or none of the parameters must be an array.

**加入整個模板

"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
"contentVersion": "1.0.0.0", 
"parameters": { 
"location": { 
    "type": "string", 
    "defaultValue": "centralus" 
}, 
"sqlAdminUsername": { 
    "type": "string" 
}, 
"sqlAdminPassword": { 
    "type": "securestring" 
}, 
"sqlServerName": { 
    "type": "string" 
}, 
"sqlDatabaseNames": { 
    "type": "array", 
    "defaultValue": [ 
    "CustomersDB", 
    "WideWorldImporters-Standard" 
    ] 
}, 
"sqlEdition": { 
    "type": "string", 
    "defaultValue": "Standard" 
}, 
"sqlRequestedServiceObjectiveName": { 
    "type": "string", 
    "defaultValue": "S2" 
}, 
"sqlMaxSizeBytes": { 
    "type": "string", 
    "defaultValue": "268435456000" 
}, 
"publicIP": { 
    "type": "string" 
}, 
"_artifactsLocationSasToken": { 
    "type": "securestring" 
}, 
"_artifactsLocation": { 
    "type": "string" 
} 
}, 
"variables": { 
"storageKeyType": "SharedAccessKey", 
"collation": "SQL_Latin1_General_CP1_CI_AS" 
}, 
"resources": [ 
    { 
    "name": "[parameters('sqlServerName')]", 
    "type": "Microsoft.Sql/servers", 
    "apiVersion": "2014-04-01-preview", 
    "location": "[parameters('location')]", 
    "properties": { 
     "administratorLogin": "[parameters('sqlAdminUsername')]", 
     "administratorLoginPassword": "[parameters('sqlAdminPassword')]", 
     "version": "12.0" 
    }, 
    "resources": [ 
     { 
     "name": "AllowAllWindowsAzureIps", 
     "type": "firewallrules", 
     "apiVersion": "2014-04-01-preview", 
     "location": "[parameters('location')]", 
     "dependsOn": [ 
      "[concat('Microsoft.Sql/servers/', parameters('sqlServerName'))]" 
     ], 
     "properties": { 
      "endIpAddress": "0.0.0.0", 
      "startIpAddress": "0.0.0.0" 
     } 
     }, 
     { 
     "name": "Allow_Remote_SSMS", 
     "type": "firewallrules", 
     "apiVersion": "2014-04-01-preview", 
     "location": "[parameters('location')]", 
     "dependsOn": [ 
      "[concat('Microsoft.Sql/servers/', parameters('sqlServerName'))]" 
     ], 
     "properties": { 
      "startIpAddress": "[parameters('publicIP')]", 
      "endIpAddress": "[parameters('publicIP')]" 
     } 
     } 
    ] 
    }, 
    { 
    "name": "[concat(parameters('sqlServerName'), '/', parameters('sqlDatabaseNames')[copyIndex()])]", 
    "type": "Microsoft.Sql/servers/databases", 
    "location": "[parameters('location')]", 
    "apiVersion": "2014-04-01-preview", 
    "copy": { 
     "count": "[length(parameters('sqlDatabaseNames'))]", 
     "name": "sql-copy" 
    }, 
    "dependsOn": [ "[resourceId('Microsoft.Sql/servers/', parameters('sqlServerName'))]" ], 
    "properties": { 
     "collation": "[variables('collation')]", 
     "edition": "[parameters('sqlEdition')]", 
     "maxSizeBytes": "[parameters('sqlMaxSizeBytes')]", 
     "requestedServiceObjectiveName": "[parameters('sqlRequestedServiceObjectiveName')]" 
    } 
    }, 
    { 
    "name": "[concat(parameters('sqlServerName'), '/', parameters('sqlDatabaseNames')[copyIndex()],'/','import')]", 
    "type": "Microsoft.Sql/servers/databases/extensions", 
    "apiVersion": "2014-04-01-preview", 
    "dependsOn": [ "sql-copy" ], 
    "copy": { 
     "name": "sql-import", 
     "count": "[length(parameters('sqlDatabaseNames'))]" 
    }, 
    "properties": { 
     "storageKeyType": "[variables('storageKeyType')]", 
     "storageKey": "[parameters('_artifactsLocationSasToken')]", 
     "storageUri": "[concat(parameters('_artifactsLocation'), '/', 'databaseFiles', '/', parameters('sqlDatabaseNames'), '.bacpac')]", 
     "administratorLogin": "[parameters('sqlAdminUsername')]", 
     "administratorLoginPassword": "[parameters('sqlAdminPassword')]", 
     "operationMode": "Import" 
    } 
    } 
], 
} 
+0

''的問題是,在進口資源的concat函數dependsOn.''請張貼詳細的錯誤信息。 –

回答

0

據我所知,我們不能使用copyindex功能嵌套的資源。

如果你運行你的手臂模板,你將面臨這樣的錯誤:

Copying nested resources is not supported. Please see https://aka.ms/arm-copy/#looping-on-a-nested-resource for usage details.'.

因此,我建議您將嵌套的資源根資源手臂模板。然後你可以使用copyindex。

更多細節,你可以參考下面的手臂模板:

注意:請以你的數據庫名稱參數寶珠。

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { 
    "brandosqlAdminLogin": { 
     "type": "string", 
     "minLength": 1 
    }, 
    "brandosqlAdminLoginPassword": { 
     "type": "string" 
    }, 
    "org": { 
     "type": "array", 
     "defaultValue": [ 
     "contoso", 
     "fabrikam", 
     "coho" 
     ] 
    }, 
    "copydatabaseCollation": { 
     "type": "string", 
     "minLength": 1, 
     "defaultValue": "SQL_Latin1_General_CP1_CI_AS" 
    }, 
    "copydatabaseEdition": { 
     "type": "string", 
     "defaultValue": "Basic", 
     "allowedValues": [ 
     "Basic", 
     "Standard", 
     "Premium" 
     ] 
    }, 
    "copydatabaseRequestedServiceObjectiveName": { 
     "type": "string", 
     "defaultValue": "Basic", 
     "allowedValues": [ 
     "Basic", 
     "S0", 
     "S1", 
     "S2", 
     "P1", 
     "P2", 
     "P3" 
     ], 
     "metadata": { 
     "description": "Describes the performance level for Edition" 
     } 
    }, 
    "copy2StorageKeyType": { 
     "type": "string", 
     "minLength": 1 
    }, 
    "copy2StorageKey": { 
     "type": "string" 
    }, 
    "copy2StorageUri": { 
     "type": "string", 
     "minLength": 1 
    }, 
    "copy2AdministratorLogin": { 
     "type": "string", 
     "minLength": 1 
    }, 
    "copy2AdministratorLoginPassword": { 
     "type": "string" 
    }, 
    "serverDatabaseName": { 
     "type": "array", 
     "defaultValue": [ 
     "brandoimprottest/contoso", 
     "brandoimprottest/fabrikam", 
     "brandoimprottest/coho" 
     ] 
    }, 

    "copysqldatabase2Collation": { 
     "type": "string", 
     "minLength": 1, 
     "defaultValue": "SQL_Latin1_General_CP1_CI_AS" 
    }, 
    "copysqldatabase2Edition": { 
     "type": "string", 
     "defaultValue": "Basic", 
     "allowedValues": [ 
     "Basic", 
     "Standard", 
     "Premium" 
     ] 
    }, 
    "copysqldatabase2RequestedServiceObjectiveName": { 
     "type": "string", 
     "defaultValue": "Basic", 
     "allowedValues": [ 
     "Basic", 
     "S0", 
     "S1", 
     "S2", 
     "P1", 
     "P2", 
     "P3" 
     ], 
     "metadata": { 
     "description": "Describes the performance level for Edition" 
     } 
    } 

    }, 
    "variables": { 
    "brandosqlName": "brandoimprottest" 
    }, 
    "resources": [ 
    { 
     "name": "[variables('brandosqlName')]", 
     "type": "Microsoft.Sql/servers", 
     "location": "[resourceGroup().location]", 
     "apiVersion": "2014-04-01-preview", 
     "dependsOn": [], 
     "tags": { 
     "displayName": "brandosql" 
     }, 
     "properties": { 
     "administratorLogin": "[parameters('brandosqlAdminLogin')]", 
     "administratorLoginPassword": "[parameters('brandosqlAdminLoginPassword')]" 
     }, 
     "resources": [ 
     { 
      "name": "AllowAllWindowsAzureIps", 
      "type": "firewallrules", 
      "location": "[resourceGroup().location]", 
      "apiVersion": "2014-04-01-preview", 
      "dependsOn": [ 
      "[resourceId('Microsoft.Sql/servers', variables('brandosqlName'))]" 
      ], 
      "properties": { 
      "startIpAddress": "0.0.0.0", 
      "endIpAddress": "0.0.0.0" 
      } 
     } 
     ] 
    }, 
    { 
     "name": "[concat(variables('brandosqlName'), '/', parameters('org')[copyIndex()])]", 
     "type": "Microsoft.Sql/servers/databases", 
     "location": "[resourceGroup().location]", 
     "apiVersion": "2014-04-01-preview", 
     "copy": { 
     "count": 3, 
     "name": "sql-copy" 
     }, 
     "dependsOn": [ "[resourceId('Microsoft.Sql/servers', variables('brandosqlName'))]" ], 
     "tags": { 
     "displayName": "copysqldatabase2" 
     }, 
     "properties": { 
     "collation": "[parameters('copysqldatabase2Collation')]", 
     "edition": "[parameters('copysqldatabase2Edition')]", 
     "maxSizeBytes": "1073741824", 
     "requestedServiceObjectiveName": "[parameters('copysqldatabase2RequestedServiceObjectiveName')]" 
     } 
    }, 
    { 
     "name": "[concat(variables('brandosqlName'), '/', parameters('org')[copyIndex()],'/','aaaa')]", 
     "type": "Microsoft.Sql/servers/databases/extensions", 
     "apiVersion": "2014-04-01-preview", 
     "dependsOn": [ "sql-copy" ], 
     "tags": { 
     "displayName": "copy3" 
     }, 
     "copy": { 
     "name": "sql-copy2", 
     "count": 3 
     }, 
     "properties": { 
     "storageKeyType": "[parameters('copy2StorageKeyType')]", 
     "storageKey": "[parameters('copy2StorageKey')]", 
     "storageUri": "[parameters('copy2StorageUri')]", 
     "administratorLogin": "[parameters('copy2AdministratorLogin')]", 
     "administratorLoginPassword": "[parameters('copy2AdministratorLoginPassword')]", 
     "operationMode": "Import" 
     } 
    } 
    ], 
    "outputs": {} 
} 

結果:

enter image description here


我也測試你的模板,我發現有什麼毛病進口擴展存儲網址。我使用主存儲密鑰和網址對其進行了更改。它運作良好。

模板:

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { 
    "location": { 
     "type": "string", 
     "defaultValue": "eastasia" 
    }, 
    "sqlAdminUsername": { 
     "type": "string" 
    }, 
    "sqlAdminPassword": { 
     "type": "string" 
    }, 
    "sqlServerName": { 
     "type": "string" 
    }, 
    "sqlDatabaseNames": { 
     "type": "array", 
     "defaultValue": [ 
     "CustomersDB", 
     "WideWorldImporters-Standard" 
     ] 
    }, 
    "sqlEdition": { 
     "type": "string", 
     "defaultValue": "Standard" 
    }, 
    "sqlRequestedServiceObjectiveName": { 
     "type": "string", 
     "defaultValue": "S2" 
    }, 
    "sqlMaxSizeBytes": { 
     "type": "string", 
     "defaultValue": "268435456000" 
    }, 
    "publicIP": { 
     "type": "string" 
    }, 
    "copy2StorageKeyType": { 
     "type": "string", 
     "minLength": 1 
    }, 
    "copy2StorageKey": { 
     "type": "string" 
    }, 
    "copy2StorageUri": { 
     "type": "string", 
     "minLength": 1 
    } 

    }, 
    "variables": { 
    "storageKeyType": "SharedAccessKey", 
    "collation": "SQL_Latin1_General_CP1_CI_AS" 
    }, 
    "resources": [ 
    { 
     "name": "[parameters('sqlServerName')]", 
     "type": "Microsoft.Sql/servers", 
     "apiVersion": "2014-04-01-preview", 
     "location": "[parameters('location')]", 
     "properties": { 
     "administratorLogin": "[parameters('sqlAdminUsername')]", 
     "administratorLoginPassword": "[parameters('sqlAdminPassword')]", 
     "version": "12.0" 
     }, 
     "resources": [ 
     { 
      "name": "AllowAllWindowsAzureIps", 
      "type": "firewallrules", 
      "apiVersion": "2014-04-01-preview", 
      "location": "[parameters('location')]", 
      "dependsOn": [ 
      "[concat('Microsoft.Sql/servers/', parameters('sqlServerName'))]" 
      ], 
      "properties": { 
      "endIpAddress": "0.0.0.0", 
      "startIpAddress": "0.0.0.0" 
      } 
     }, 
     { 
      "name": "Allow_Remote_SSMS", 
      "type": "firewallrules", 
      "apiVersion": "2014-04-01-preview", 
      "location": "[parameters('location')]", 
      "dependsOn": [ 
      "[concat('Microsoft.Sql/servers/', parameters('sqlServerName'))]" 
      ], 
      "properties": { 
      "startIpAddress": "[parameters('publicIP')]", 
      "endIpAddress": "[parameters('publicIP')]" 
      } 
     } 
     ] 
    }, 
    { 
     "name": "[concat(parameters('sqlServerName'), '/', parameters('sqlDatabaseNames')[copyIndex()])]", 
     "type": "Microsoft.Sql/servers/databases", 
     "location": "[parameters('location')]", 
     "apiVersion": "2014-04-01-preview", 
     "copy": { 
     "count": "[length(parameters('sqlDatabaseNames'))]", 
     "name": "sql-copy" 
     }, 
     "dependsOn": [ "[resourceId('Microsoft.Sql/servers/', parameters('sqlServerName'))]" ], 
     "properties": { 
     "collation": "[variables('collation')]", 
     "edition": "[parameters('sqlEdition')]", 
     "maxSizeBytes": "[parameters('sqlMaxSizeBytes')]", 
     "requestedServiceObjectiveName": "[parameters('sqlRequestedServiceObjectiveName')]" 
     } 
    }, 
    { 
     "name": "[concat(parameters('sqlServerName'), '/', parameters('sqlDatabaseNames')[copyIndex()],'/','import')]", 
     "type": "Microsoft.Sql/servers/databases/extensions", 
     "apiVersion": "2014-04-01-preview", 
     "dependsOn": [ "sql-copy" ], 
     "copy": { 
     "name": "sql-import", 
     "count": "[length(parameters('sqlDatabaseNames'))]" 
     }, 
     "properties": { 
     "storageKeyType": "[parameters('copy2StorageKeyType')]", 
     "storageKey": "[parameters('copy2StorageKey')]", 
     "storageUri": "[parameters('copy2StorageUri')]", 
     "administratorLogin": "[parameters('sqlAdminUsername')]", 
     "administratorLoginPassword": "[parameters('sqlAdminPassword')]", 
     "operationMode": "Import" 
     } 
    } 
    ] 
} 

結果:

enter image description here

+0

我測試了你的例子,但它似乎仍然在sql導入操作期間拋出錯誤。我在原始文章中包含了確切的錯誤。 – ronaldSwanson

+0

錯誤消息表示您無法在聯繫人功能中使用copyindex。你可以請張貼整個手臂模板嗎?我們很容易找到並解決您的所有問題。 –

+0

已添加模板 – ronaldSwanson

相關問題