mysqlazureterraformterraform-provider-azureazure-mysql-database

Azure ARM Template for flexible mysql server gives "Internal Server Error"


I am trying to deploy a MySQL Flexible server cluster using ARM Templates and terraform (since terraform doesn't have any resource for mysql_flexible) but it gives me the following "Internal Server Error" without any meaningful information.

Please provide string value for 'version' (? for help): 5.7 {"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"Conflict","message":"{\r\n "status": "Failed",\r\n "error": {\r\n "code": "ResourceDeploymentFailure",\r\n "message": "The resource operation completed with terminal provisioning state 'Failed'.",\r\n "details": [\r\n {\r\n "code": "InternalServerError",\r\n "message": "An unexpected error occured while processing the request. Tracking ID: 'b8ab3a01-d4f2-40d5-92cf-2c9a239bdac3'"\r\n }\r\n ]\r\n }\r\n}"}]}}

There's not much information when I paste this tracking ID in Azure Activity Log. Here's my sample template.json file which I am using.

{
   "$schema" : "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
   "contentVersion" : "1.0.0.0",
   "parameters" : {
      "administratorLogin" : {
         "type" : "String"
      },
      "administratorLoginPassword" : {
         "type" : "SecureString"
      },
      "availabilityZone" : {
         "type" : "String"
      },
      "location" : {
         "type" : "String"
      },
      "name" : {
         "type" : "String"
      },
      "version" : {
         "type" : "String"
      }
   },
   "resources" : [
      {
         "apiVersion" : "2021-05-01-preview",
         "identity" : {
            "type" : "SystemAssigned"
         },
         "location" : "eastus",
         "name" : "mysql-abcd-eastus",
         "properties" : {
            "administratorLogin" : "randomuser",
            "administratorLoginPassword" : "randompasswd",
            "availabilityZone" : "1",
            "backup" : {
               "backupRetentionDays" : "7",
               "geoRedundantBackup" : "Disabled"
            },
            "createMode" : "Default",
            "highAvailability" : {
               "mode" : "Enabled",
               "standbyAvailabilityZone" : "2"
            },
            "network" : {
               "delegatedSubnetResourceId" : "myactualsubnetid",
               "privateDnsZoneResourceId" : "myactualprivatednszoneid"
            },
            "version" : "[parameters('version')]"
         },
         "sku" : {
            "name" : "Standard_E4ds_v4",
            "tier" : "MemoryOptimized"
         },
         "type" : "Microsoft.DBforMySQL/flexibleServers"
      }
   ]
}

Solution

  • I tested your code and faced the same issue . So, as a solution you can try with below Code :

    provider "azurerm" {
      features {}
    }
    data "azurerm_resource_group" "example" {
      name     = "yourresourcegroup"
    }
    resource "azurerm_resource_group_template_deployment" "example" {
      name                = "acctesttemplate-01"
      resource_group_name = data.azurerm_resource_group.example.name
        parameters_content = jsonencode({
            "administratorLogin"= {
          "value"= "sqladmin"
        },
        "administratorLoginPassword"= {
          "value": "password"
        },
        "location"= {
          "value": "eastus"
        },
        "serverName"= {
          "value"= "ansumantestsql1234"
        },
        "serverEdition"= {
          "value"= "GeneralPurpose"
        },
        "vCores"= {
          "value"= 2
        },
        "storageSizeGB"= {
          "value"= 64
        },
        "haEnabled"= {
          "value"= "ZoneRedundant"
        },
        "availabilityZone"= {
          "value"= "1"
        },
        "standbyAvailabilityZone"= {
          "value"= "2"
        },
        "version"= {
          "value"= "5.7"
        },
        "tags"= {
          "value"= {}
        },
        "firewallRules"= {
          "value"= {
            "rules"= []
          }
        },
        "backupRetentionDays"= {
          "value"= 7
        },
        "geoRedundantBackup"= {
          "value"= "Disabled"
        },
        "vmName"= {
          "value"= "Standard_D2ds_v4"
        },
        "publicNetworkAccess"= {
          "value"= "Enabled"
        },
        "storageIops"= {
          "value": 1000
        },
        "storageAutogrow"= {
          "value"= "Enabled"
        },
        "vnetData"= {
          "value"= {
            "virtualNetworkName"= "testVnet",
            "subnetName"= "testSubnet",
            "virtualNetworkAddressPrefix"= "10.0.0.0/16",
            "virtualNetworkResourceGroupName"= "[resourceGroup().name]",
            "location"= "eastus2",
            "subscriptionId"= "[subscription().subscriptionId]",
            "subnetProperties"= {},
            "isNewVnet"= false,
            "subnetNeedsUpdate"= false,
            "Network"= {}
          }
        },
        "infrastructureEncryption"= {
          "value"= "Disabled"
        }
    })
    
      template_content = <<DEPLOY
    {
        "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "administratorLogin": {
                "type": "string"
            },
            "administratorLoginPassword": {
                "type": "securestring"
            },
            "location": {
                "type": "string"
            },
            "serverName": {
                "type": "string"
            },
            "serverEdition": {
                "type": "string"
            },
            "vCores": {
                "type": "int",
                "defaultValue": 4
            },
            "storageSizeGB": {
                "type": "int"
            },
            "haEnabled": {
                "type": "string",
                "defaultValue": "Disabled"
            },
            "availabilityZone": {
                "type": "string"
            },
            "standbyAvailabilityZone": {
                "type": "string"
            },
            "version": {
                "type": "string"
            },
            "tags": {
                "type": "object",
                "defaultValue": {}
            },
            "firewallRules": {
                "type": "object",
                "defaultValue": {}
            },
            "backupRetentionDays": {
                "type": "int"
            },
            "geoRedundantBackup": {
                "type": "string"
            },
            "vmName": {
                "type": "string",
                "defaultValue": "Standard_B1ms"
            },
            "publicNetworkAccess": {
                "type": "string",
                "metadata": {
                    "description": "Value should be either Enabled or Disabled"
                }
            },
            "storageIops": {
                "type": "int"
            },
            "storageAutogrow": {
                "type": "string",
                "defaultValue": "Enabled"
            },
            "vnetData": {
                "type": "object",
                "metadata": {
                    "description": "Vnet data is an object which contains all parameters pertaining to vnet and subnet"
                },
                "defaultValue": {
                    "virtualNetworkName": "testVnet",
                    "subnetName": "testSubnet",
                    "virtualNetworkAddressPrefix": "10.0.0.0/16",
                    "virtualNetworkResourceGroupName": "[resourceGroup().name]",
                    "location": "westus2",
                    "subscriptionId": "[subscription().subscriptionId]",
                    "subnetProperties": {},
                    "isNewVnet": false,
                    "subnetNeedsUpdate": false,
                    "Network": {}
                }
            },
            "infrastructureEncryption": {
                "type": "string"
            }
        },
        "variables": {
            "api": "2021-05-01-preview",
            "firewallRules": "[parameters('firewallRules').rules]"
        },
        "resources": [
            {
                "apiVersion": "[variables('api')]",
                "location": "[parameters('location')]",
                "name": "[parameters('serverName')]",
                "properties": {
                    "version": "[parameters('version')]",
                    "administratorLogin": "[parameters('administratorLogin')]",
                    "administratorLoginPassword": "[parameters('administratorLoginPassword')]",
                    "publicNetworkAccess": "[parameters('publicNetworkAccess')]",
                    "Network": "[if(empty(parameters('vnetData').Network), json('null'), parameters('vnetData').Network)]",
                    "Storage": {
                        "StorageSizeGB": "[parameters('storageSizeGB')]",
                        "Iops": "[parameters('storageIops')]",
                        "Autogrow": "[parameters('storageAutogrow')]"
                    },
                    "Backup": {
                        "backupRetentionDays": "[parameters('backupRetentionDays')]",
                        "geoRedundantBackup": "[parameters('geoRedundantBackup')]"
                    },
                    "availabilityZone": "[parameters('availabilityZone')]",
                    "highAvailability": {
                        "mode": "[parameters('haEnabled')]",
                        "standbyAvailabilityZone": "[parameters('standbyAvailabilityZone')]"
                    },
                    "dataencryption": {
                        "infrastructureEncryption": "[parameters('infrastructureEncryption')]"
                    }
                },
                "sku": {
                    "name": "[parameters('vmName')]",
                    "tier": "[parameters('serverEdition')]",
                    "capacity": "[parameters('vCores')]"
                },
                "tags": "[parameters('tags')]",
                "type": "Microsoft.DBforMySQL/flexibleServers"
            },
            {
                "condition": "[greater(length(variables('firewallRules')), 0)]",
                "type": "Microsoft.Resources/deployments",
                "apiVersion": "2019-08-01",
                "name": "[concat('firewallRules-', copyIndex())]",
                "copy": {
                    "count": "[if(greater(length(variables('firewallRules')), 0), length(variables('firewallRules')), 1)]",
                    "mode": "Serial",
                    "name": "firewallRulesIterator"
                }
            }
        ]
    }
    DEPLOY
      deployment_mode = "Incremental"
    }
    

    Output:

    enter image description here

    enter image description here

    enter image description here