Azure ARM Failover group conditional association o

2019-08-23 09:42发布

I am working on an ARM template where I can conditionally control the association of one of the databases in the fail-over group. Here is my sample resource template

 {
      "condition": "[variables('Resources').IsFailover]",
      "name": "[variables('SqlServer').FailoverGroup.Name]",
      "type": "failoverGroups",
      "apiVersion": "2015-05-01-preview",
      "location": "[variables('SqlServer').Servers.Primary.ResourceLocation]",
      "tags": 
      {
        "displayName": "Failover Group"
      },
      "properties": 
      {
        "partnerServers": 
        [
          {
            ...
          }
        ],
        "readWriteEndpoint": 
        {
            ....
        },
        "readOnlyEndpoint": 
        {
          "failoverPolicy": "Disabled"
        },
        "databases": 
        [
          "[variables('SqlServer').Databases.DBOne.ResourceId]",
          "[variables('SqlServer').Databases.DBTwo.ResourceId]",
          "[variables('SqlServer').Databases.DBThree.ResourceId]"
        ]
      },
      "dependsOn": 
      [
        "[variables('SqlServer').Servers.Primary.ResourceId]",
        "[variables('SqlServer').Servers.Secondary.ResourceId]",
        "[variables('SqlServer').Databases.DBOne.ResourceId]",
        "[variables('SqlServer').Databases.DBTwo.ResourceId]",
        "[variables('SqlServer').Databases.DBThree.ResourceId]"
      ]
}

I want to achieve something like associating the DBTwo(database) with the fail-over group only if a flag(input parameter) is true and not associating if the flag is false all from the same group.

Is there a way to do this from ARM ?

Thanks in advance for any advice and suggestions.

1条回答
趁早两清
2楼-- · 2019-08-23 10:11

Yes, arm template has support for conditionals (cough, cough). you can use if() function and several others (and, not, or, etc) to create conditions.

https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions-logical

so basic example:

if(equals(parameter('x'), 'FAILOVER'), true, false)
查看更多
登录 后发表回答