Свойство базы данных отказоустойчивой группы Azure ARM не принимает массив переменных - PullRequest
0 голосов
/ 28 сентября 2018

Я пытаюсь программно назначить базы данных группе аварийного переключения, используя шаблон ARM, но я получаю сообщение об ошибке «InvalidResourceIdSegment».Я нашел что-то близкое на форумах здесь , но это было только для одной базы данных, так что это не совсем ответ на мою проблему.Я в основном пытаюсь использовать переменную, которая является списком массивов resourceIds для баз данных, которые мне нужно добавить в эту группу отработки отказа.

"databases": {
  "critical": {
    "names": [
      "DB1",
      "DB2",
      "DB3",
      "DB4"
    ],
    "ids": [
      "[resourceId('Microsoft.Sql/servers/databases', variables('serverNameWest'), 'DB1')]",
      "[resourceId('Microsoft.Sql/servers/databases', variables('serverNameWest'), 'DB2')]",
      "[resourceId('Microsoft.Sql/servers/databases', variables('serverNameWest'), 'DB3')]",
      "[resourceId('Microsoft.Sql/servers/databases', variables('serverNameWest'), 'DB4')]"
    ]
  }
}

Вот фрагмент ресурса группы отработки отказа

{
    "type": "Microsoft.Sql/servers/failoverGroups",
    "name": "[concat(variables('serverNameWest'), '/', variables('failovergroups').critical)]",
    "apiVersion": "2015-05-01-preview",
    "condition": "[parameters('setRedundancy')]",
    "tags": {
      "Environment": "[parameters('Environment')]"
    },
    "properties": {
      "readWriteEndpoint": {
        "failoverPolicy": "Automatic",
        "failoverWithDataLossGracePeriodMinutes": 15
      },
      "readOnlyEndpoint": {
        "failoverPolicy": "Enabled"
      },
      "partnerServers": [
        {
          "id": "[resourceID('Microsoft.Sql/servers', variables('serverNameEast'))]"
        }
      ],
      "databases": [
       "[variables('databases').critical.ids]"
      ]
    },
    "dependsOn": [
      "[resourceID('Microsoft.Sql/servers', variables('serverNameEast'))]",
      "[resourceID('Microsoft.Sql/servers', variables('serverNameWest'))]",
      "[concat(resourceID('Microsoft.Sql/servers', variables('serverNameWest')), '/elasticpools/', variables('elasticpools').critwest)]",
      "[concat(resourceID('Microsoft.Sql/servers', variables('serverNameEast')), '/elasticpools/', variables('elasticpools').criteast)]",
      "BusinessCriticalWest",
      "BusinessCriticalEast"
    ]
  }

Передача переменной [variables('databases').critical.ids] свойству database всегда приводит к этой ошибке:

"code": "InvalidResourceIdSegment", "message": "The 'parameters.properties.databases[0]' segment in the url is invalid."

Однако, если я добавлю их по отдельности, как показано ниже, все будет работать нормально.

"[variables('databases').critical.ids[0]]"

Я попытался использовать функцию копирования как в свойстве (которое, по-видимому, не работает, поскольку функция копирования требует ввода имени и пары для ввода), так и в качестве функции копирования в качестве переменной (которая также возвращаетта же ошибка о invalidResourceIdSegment).Я сбит с толку, поэтому любая помощь будет принята с благодарностью.

1 Ответ

0 голосов
/ 25 июня 2019

@ nicklaws Я только что столкнулся с этим, когда искал что-то еще.

На первый взгляд, во-первых, мне интересно, может ли это быть проблемой:

variables('serverNameEast')

Как я могу 'Я не могу сказать, что вы видите настройки ваших переменных, но мои обычно выглядят так:

variables('serverNameEast').name 

например.

Во-вторых, вот целый шаблон ARM, который у меня естьиспользуется много раз, и это работает:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "businessOwner": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "Responsible for billing of the resource"
        }
    },
    "technicalOwner": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "Responsible for the technology decisions of the resource"
        }
    },
    "environment": {
        "type": "string",
        "metadata": {
            "description": "Provides information on the environment that the resource belongs to"
        },
        "allowedValues": [
            "prod",
            "nprd",
            "sand"
        ]
    },
    "costCode": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "Provides a charge code or cost center to attribute the bill for the resources too. This could be a project code or cost Centre"
        }
    },
    "projectName": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "Provides information on the project that the resource group and resources belong to."
        }
    },
    "primaryAdministratorLogin": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "Administrator username for the server. Once created it cannot be changed."
        }
    },
    "primaryAdministratorLoginPassword": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "The administrator login password (required for server creation)."
        }
    },
    "sqlServerSecondaryRegion": {
        "type": "string",
        "metadata": {
            "description": "The location of the secondary SQL Server."
        }
    },
    "sqlServerSecondaryAdminUsername": {
        "type": "string",
        "metadata": {
            "description": "The administrator username of the secondary SQL Server."
        }
    },
    "sqlServerSecondaryAdminPassword": {
        "type": "string",
        "metadata": {
            "description": "The administrator password of the secondary SQL Server."
        }
    },
    "requestedServiceObjectiveName": {
        "type": "string",
        "metadata": {
            "description": "The name of the configured service level objective of the database. This is the service level objective that is in the process of being applied to the database. Once successfully updated, it will match the value of serviceLevelObjective property."
        }
    },
    "sampleName": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "Indicates the name of the sample schema to apply when creating this database. If createMode is not Default, this value is ignored. Not supported for DataWarehouse edition. - AdventureWorksLT"
        }
    },
    "maxSizeBytes": {
        "type": "string",
        "defaultValue": "107374182400",
        "metadata": {
            "description": "The max size of the database expressed in bytes. If createMode is not Default, this value is ignored."
        }
    },
    "collation": {
        "type": "string",
        "defaultValue": "SQL_Latin1_General_CP1_CI_AS",
        "metadata": {
            "description": "The collation of the database. If createMode is not Default, this value is ignored."
        }
    },
    "createMode": {
        "type": "string",
        "defaultValue": "Default",
        "metadata": {
            "description": "Specifies the mode of database creation."
        }
    },
    "readScale": {
        "type": "string",
        "defaultValue": "Disabled",
        "metadata": {
            "description": "Specifies the mode of database creation."
        }
    },
    "edition": {
        "type": "string",
        "defaultValue": "Standard",
        "metadata": {
            "description": "The edition of the database."
        }
    },
    "zoneRedundant": {
        "type": "bool",
        "defaultValue": false,
        "metadata": {
            "description": "Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones."
        }
    },
    "firewallDigitalNetworkFrom": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "firewall rule"
        }
    },
    "firewallDigitalNetworkTo": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "firewall rule"
        }
    },
    "firewallMelbourneOfficeFrom": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "firewall rule"
        }
    },
    "firewallMelbourneOfficeTo": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "firewall rule"
        }
    },
    "firewallSydneyOfficeFrom": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "firewall rule"
        }
    },
    "firewallSydneyOfficeTo": {
        "type": "string",
        "defaultValue": "NOT_SET",
        "metadata": {
            "description": "firewall rule"
        }
    },     
    "failoverEnabled": {
        "type": "string",
        "defaultValue": "true",
        "metadata": {
            "description": "Whether we allow a secondary SQL server with failover. This could be used to save money"
        }
    }
},
"variables": {
    "sqlServerPrimary": {
        "name": "[toLower(concat(parameters('projectName'), '-',parameters('environment'), '-', 'sqlsvr-primary'))]",
        "requestedServiceObjectiveName": "[parameters('requestedServiceObjectiveName')]"
    },
    "sqlServerSecondary": {
        "name": "[toLower(concat(parameters('projectName'), '-',parameters('environment'), '-', 'sqlsvr-secondary'))]"
    },
    "sqlFailoverGroupName": {
        "name": "[toLower(concat(parameters('projectName'), '-',parameters('environment'), '-', 'failover-group'))]"
    }
},
"resources": [
    {
        "name": "[variables('sqlServerPrimary').name]",
        "type": "Microsoft.Sql/servers",
        "apiVersion": "2015-05-01-preview",
        "location": "[resourceGroup().location]",
        "tags": {
            "BusinessOwner": "[parameters('businessOwner')]",
            "TechnicalOwner": "[parameters('technicalOwner')]",
            "Environment": "[parameters('environment')]",
            "CostCode": "[parameters('costCode')]",
            "Project": "[parameters('projectName')]"
        },
        "properties": {
            "administratorLogin": "[parameters('primaryAdministratorLogin')]",
            "administratorLoginPassword": "[parameters('primaryAdministratorLoginPassword')]",
            "version": "12.0"
        },
        "resources": [
            {
                "apiVersion": "2015-05-01-preview",
                "condition": "[equals(parameters('failoverEnabled'),'true')]",
                "type": "failoverGroups",
                "name": "[variables('sqlFailoverGroupName').name]",
                "tags": {
                    "BusinessOwner": "[parameters('businessOwner')]",
                    "TechnicalOwner": "[parameters('technicalOwner')]",
                    "Environment": "[parameters('environment')]",
                    "CostCode": "[parameters('costCode')]",
                    "Project": "[parameters('projectName')]"
                },
                "properties": {
                    "serverName": "[variables('sqlServerPrimary').name]",
                    "partnerServers": [
                        {
                            "id": "[resourceId('Microsoft.Sql/servers/', variables('sqlServerSecondary').name)]"
                        }
                    ],
                    "readWriteEndpoint": {
                        "failoverPolicy": "Automatic",
                        "failoverWithDataLossGracePeriodMinutes": 60
                    },
                    "readOnlyEndpoint": {
                        "failoverPolicy": "Disabled"
                    },
                    "databases": [
                    ]
                },
                "dependsOn": [
                    "[variables('sqlServerPrimary').name]",
                    "[resourceId('Microsoft.Sql/servers', variables('sqlServerSecondary').name)]"
                ]
            },
            {
                "name": "AllowAllWindowsAzureIps",
                "type": "firewallRules",
                "apiVersion": "2015-05-01-preview",
                "properties": {
                    "startIpAddress": "0.0.0.0",
                    "endIpAddress": "0.0.0.0"
                },
                "dependsOn": [
                    "[concat('Microsoft.Sql/servers/', variables('sqlServerPrimary').name)]"
                  ]
            },
            {
                "name": "digitalNetwork",
                "type": "firewallRules",
                "apiVersion": "2015-05-01-preview",
                "properties": {
                    "startIpAddress": "[parameters('firewallDigitalNetworkFrom')]",
                    "endIpAddress": "[parameters('firewallDigitalNetworkTo')]"
                },
                "dependsOn": [
                    "[concat('Microsoft.Sql/servers/', variables('sqlServerPrimary').name)]"
                  ]
            },
            {
                "name": "MelbourneOffice",
                "type": "firewallRules",
                "apiVersion": "2015-05-01-preview",
                "properties": {
                    "startIpAddress": "[parameters('firewallMelbourneOfficeFrom')]",
                    "endIpAddress": "[parameters('firewallMelbourneOfficeTo')]"
                },
                "dependsOn": [
                    "[concat('Microsoft.Sql/servers/', variables('sqlServerPrimary').name)]"
                  ]
            },
            {
                "name": "SydneyOffice",
                "type": "firewallRules",
                "apiVersion": "2015-05-01-preview",
                "properties": {
                    "startIpAddress": "[parameters('firewallSydneyOfficeFrom')]",
                    "endIpAddress": "[parameters('firewallSydneyOfficeTo')]"
                },
                "dependsOn": [
                    "[concat('Microsoft.Sql/servers/', variables('sqlServerPrimary').name)]"
                  ]
            }
        ]
    },
    {
        "type": "Microsoft.Sql/servers",
        "kind": "v12.0",
        "condition": "[equals(parameters('failoverEnabled'),'true')]",
        "name": "[variables('sqlServerSecondary').name]",
        "apiVersion": "2015-05-01-preview",
        "location": "[parameters('sqlServerSecondaryRegion')]",
        "tags": {
            "BusinessOwner": "[parameters('businessOwner')]",
            "TechnicalOwner": "[parameters('technicalOwner')]",
            "Environment": "[parameters('environment')]",
            "CostCode": "[parameters('costCode')]",
            "Project": "[parameters('projectName')]"
        },
        "properties": {
            "administratorLogin": "[parameters('sqlServerSecondaryAdminUsername')]",
            "administratorLoginPassword": "[parameters('sqlServerSecondaryAdminPassword')]",
            "version": "12.0"
        },
        "resources": [
            {
                "name": "AllowAllWindowsAzureIps",
                "type": "firewallRules",
                "condition": "[equals(parameters('failoverEnabled'),'true')]",
                "apiVersion": "2015-05-01-preview",
                "properties": {
                    "startIpAddress": "0.0.0.0",
                    "endIpAddress": "0.0.0.0"
                },
                "dependsOn": [
                    "[concat('Microsoft.Sql/servers/', variables('sqlServerSecondary').name)]"
                  ]
            },
            {
                "name": "digitalNetwork",
                "type": "firewallRules",
                "condition": "[equals(parameters('failoverEnabled'),'true')]",
                "apiVersion": "2015-05-01-preview",
                "properties": {
                    "startIpAddress": "[parameters('firewallDigitalNetworkFrom')]",
                    "endIpAddress": "[parameters('firewallDigitalNetworkTo')]"
                },
                "dependsOn": [
                    "[concat('Microsoft.Sql/servers/', variables('sqlServerSecondary').name)]"
                  ]
            },
            {
                "name": "MelbourneOffice",
                "type": "firewallRules",
                "condition": "[equals(parameters('failoverEnabled'),'true')]",
                "apiVersion": "2015-05-01-preview",
                "properties": {
                    "startIpAddress": "[parameters('firewallMelbourneOfficeFrom')]",
                    "endIpAddress": "[parameters('firewallMelbourneOfficeTo')]"
                },
                "dependsOn": [
                    "[concat('Microsoft.Sql/servers/', variables('sqlServerSecondary').name)]"
                  ]
            },
            {
                "name": "SydneyOffice",
                "type": "firewallRules",
                "condition": "[equals(parameters('failoverEnabled'),'true')]",
                "apiVersion": "2015-05-01-preview",
                "properties": {
                    "startIpAddress": "[parameters('firewallSydneyOfficeFrom')]",
                    "endIpAddress": "[parameters('firewallSydneyOfficeTo')]"
                },
                "dependsOn": [
                    "[concat('Microsoft.Sql/servers/', variables('sqlServerSecondary').name)]"
                  ]
            }
        ]
    }
]

}

Надеюсь, что это поможет.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...