0
votes

I have this template I created:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "variables": {
    "name": "sxp",
    "slotName": "develop",
    "identityWebAppName": "sxp-identity",
    "identityDevelopWebAppName": "[concat(variables('identityWebAppName'), '-', variables('slotName'))]",
    "sendGridPassword": "[concat('P', uniqueString(resourceGroup().id, '994ED2DD-1363-49E5-AC6E-61E878EEE357'), 'x', '!')]",
    "sxpWebAppName": "[concat(variables('name'), '-website')]",
    "sxpDevelopWebAppName": "[concat(variables('sxpWebAppName'), '-', variables('slotName'))]",
    "sxpApiWebAppName": "[concat(variables('name'), '-api')]",
    "sxpApiDevelopWebAppName": "[concat(variables('sxpApiWebAppName'), '-', variables('slotName'))]",
    "sxpAdminWebAppName": "[concat(variables('name'), '-admin')]",
    "sxpAdminDevelopWebAppName": "[concat(variables('sxpAdminWebAppName'), '-', variables('slotName'))]",
    "authorityName": "[concat(variables('name'), '-identity')]",
    "sku": "F1",
    "sqlServerName": "[variables('name')]",
    "sqlServerDevelopmentName": "[concat(variables('name'), '-', variables('slotName'))]",
    "sqlServerPassword": "[concat('P', uniqueString(resourceGroup().id, '224F5A8B-51DB-46A3-A7C8-59B0DD584A41'), 'x', '!')]",
    "sqlServerDevelopmentPassword": "[concat('P', uniqueString(resourceGroup().id, 'C1CBF350-010C-46AB-B55A-CC73046DCD9B'), 'x', '!')]",
    "identityDatabaseName": "identity",
    "sxpDatabaseName": "[variables('name')]",
    "hangFireDatabaseName": "hangfire",
    "cosmosContainerName": "products",
    "cosmosThroughPut": "400",
    "cosmosDevelopThroughPut": "400",
    "locations": [
      {
        "locationName": "[parameters('location')]",
        "failoverPriority": 0
      }
    ]
  },
  "resources": [
    {
      "apiVersion": "2019-08-01",
      "type": "Microsoft.Web/serverfarms",
      "kind": "app",
      "name": "[variables('name')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[variables('sku')]"
      }
    },
    {
      "apiVersion": "2018-11-01",
      "type": "Microsoft.Web/sites",
      "name": "[variables('sxpWebAppName')]",
      "kind": "app",
      "location": "[parameters('location')]",
      "properties": {
        "httpsOnly": true,
        "WEBSITE_TIME_ZONE": "GMT Standard Time",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
      },
      "resources": []
    },
    {
      "apiVersion": "2018-11-01",
      "type": "Microsoft.Web/sites",
      "name": "[variables('sxpDevelopWebAppName')]",
      "kind": "app",
      "location": "[parameters('location')]",
      "properties": {
        "httpsOnly": true,
        "WEBSITE_TIME_ZONE": "GMT Standard Time",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
      },
      "resources": []
    },
    {
      "apiVersion": "2018-11-01",
      "type": "Microsoft.Web/sites",
      "name": "[variables('identityWebAppName')]",
      "kind": "app",
      "location": "[parameters('location')]",
      "properties": {
        "httpsOnly": true,
        "WEBSITE_TIME_ZONE": "GMT Standard Time",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
      },
      "resources": [
        {
          "name": "appsettings",
          "type": "config",
          "apiVersion": "2018-11-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('identityWebAppName'))]"
          ],
          "properties": {
            "httpsOnly": true,
            "ASPNETCORE_DETAILEDERRORS": "false",
            "ConnectionStrings:ConnectionString": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('identityDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServerPassword'), ';')]",
            "Options:IdentityServerBaseUrl": "[concat('https://', variables('identityWebAppName'), '.azurewebsites.net/')]",
            "Email:ApiKey": "<EXAMPLE_API_KEY>"
          }
        }
      ]
    },
    {
      "apiVersion": "2018-11-01",
      "type": "Microsoft.Web/sites",
      "name": "[variables('identityDevelopWebAppName')]",
      "kind": "app",
      "location": "[parameters('location')]",
      "properties": {
        "httpsOnly": true,
        "WEBSITE_TIME_ZONE": "GMT Standard Time",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
      },
      "resources": [
        {
          "name": "appsettings",
          "type": "config",
          "apiVersion": "2018-11-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('identityDevelopWebAppName'))]"
          ],
          "properties": {
            "httpsOnly": true,
            "ASPNETCORE_DETAILEDERRORS": "false",
            "ConnectionStrings:ConnectionString": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('identityDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServerDevelopmentPassword'), ';')]",
            "Options:IdentityServerBaseUrl": "[concat('https://', variables('identityDevelopWebAppName'), '.azurewebsites.net/')]",
            "Email:ApiKey": "<EXAMPLE_API_KEY>"
          }
        }
      ]
    },
    {
      "apiVersion": "2018-11-01",
      "type": "Microsoft.Web/sites",
      "name": "[variables('sxpApiWebAppName')]",
      "kind": "app",
      "location": "[parameters('location')]",
      "properties": {
        "WEBSITE_TIME_ZONE": "GMT Standard Time",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
      },
      "resources": [
        {
          "name": "appsettings",
          "type": "config",
          "apiVersion": "2018-11-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('sxpApiWebAppName'))]"
          ],
          "properties": {
            "httpsOnly": true,
            "ASPNETCORE_DETAILEDERRORS": "false",
            "ConnectionStrings:ConnectionString": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('sxpDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServermentPassword'), ';')]",
            "ConnectionStrings:HangFireConnection": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('hangFireDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServermentPassword'), ';')]",
            "ConnectionStrings:StorageConnectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('name'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('name')), '2019-06-01').key1)]",
            "Options:Authority": "[concat('https://', variables('authorityName'), '-', variables('slotName'), '.azurewebsites.net')]",
            "Azure:DocumentDbPrimaryKey": "bVzgKKKRxW1XG3cKwxErdkvQ4kI6c85W9H8WXiN0uGGdIjm0NaNFHGsN4mGOMC0ZNVb36tRKffemDtUtrm1ZEQ=="
          }
        }
      ]
    },
    {
      "apiVersion": "2018-11-01",
      "type": "Microsoft.Web/sites",
      "name": "[variables('sxpApiDevelopWebAppName')]",
      "kind": "app",
      "location": "[parameters('location')]",
      "properties": {
        "WEBSITE_TIME_ZONE": "GMT Standard Time",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
      },
      "resources": [
        {
          "name": "appsettings",
          "type": "config",
          "apiVersion": "2018-11-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('sxpApiDevelopWebAppName'))]"
          ],
          "properties": {
            "httpsOnly": true,
            "ASPNETCORE_DETAILEDERRORS": "false",
            "ConnectionStrings:ConnectionString": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('sxpDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServerDevelopmentPassword'), ';')]",
            "ConnectionStrings:HangFireConnection": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('hangFireDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServerDevelopmentPassword'), ';')]",
            "ConnectionStrings:StorageConnectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('name'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('name')), '2019-06-01').key1)]",
            "Options:Authority": "[concat('https://', variables('authorityName'), '-', variables('slotName'), '.azurewebsites.net')]",
            "Azure:DocumentDbPrimaryKey": "bVzgKKKRxW1XG3cKwxErdkvQ4kI6c85W9H8WXiN0uGGdIjm0NaNFHGsN4mGOMC0ZNVb36tRKffemDtUtrm1ZEQ=="
          }
        }
      ]
    },
    {
      "apiVersion": "2018-11-01",
      "type": "Microsoft.Web/sites",
      "name": "[variables('sxpAdminWebAppName')]",
      "kind": "app",
      "location": "[parameters('location')]",
      "properties": {
        "httpsOnly": true,
        "WEBSITE_TIME_ZONE": "GMT Standard Time",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
      }
    },
    {
      "apiVersion": "2018-11-01",
      "type": "Microsoft.Web/sites",
      "name": "[variables('sxpAdminDevelopWebAppName')]",
      "kind": "app",
      "location": "[parameters('location')]",
      "properties": {
        "httpsOnly": true,
        "WEBSITE_TIME_ZONE": "GMT Standard Time",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
      }
    },
    {
      "apiVersion": "2018-11-01",
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('name')]",
      "location": "[parameters('location')]",
      "tags": {
        "name": "SXP storage"
      },
      "kind": "Storage",
      "sku": {
        "name": "Standard_LRS"
      }
    },
    {
      "name": "[variables('sqlServerName')]",
      "type": "Microsoft.Sql/servers",
      "apiVersion": "2019-06-01-preview",
      "location": "[parameters('location')]",
      "tags": {
        "name": "SXP SQL server"
      },
      "properties": {
        "administratorLogin": "[variables('name')]",
        "administratorLoginPassword": "[variables('sqlServerPassword')]"
      },
      "resources": [
        {
          "apiVersion": "2019-06-01-preview",
          "name": "AllowMachine",
          "type": "firewallrules",
          "location": "[parameters('location')]",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', variables('sqlServerName'))]"
          ],
          "properties": {
            "startIpAddress": "81.103.80.33",
            "endIpAddress": "81.103.80.33"
          }
        },
        {
          "apiVersion": "2019-06-01-preview",
          "name": "AllowSlot",
          "type": "firewallrules",
          "location": "[parameters('location')]",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', variables('sqlServerName'))]"
          ],
          "properties": {
            "startIpAddress": "51.143.191.44",
            "endIpAddress": "51.143.191.44"
          }
        },
        {
          "name": "[variables('identityDatabaseName')]",
          "type": "databases",
          "location": "[parameters('location')]",
          "apiVersion": "2019-06-01-preview",
          "tags": {
            "name": "Identity database"
          },
          "dependsOn": [
            "[concat('Microsoft.Sql/servers', '/', variables('sqlServerName'))]"
          ]
        },
        {
          "name": "[variables('sxpDatabaseName')]",
          "type": "databases",
          "location": "[parameters('location')]",
          "apiVersion": "2019-06-01-preview",
          "tags": {
            "name": "Sxp database"
          },
          "dependsOn": [
            "[concat('Microsoft.Sql/servers', '/', variables('sqlServerName'))]"
          ]
        }
      ]
    },
    {
      "name": "[variables('sqlServerDevelopmentName')]",
      "type": "Microsoft.Sql/servers",
      "apiVersion": "2019-06-01-preview",
      "location": "[parameters('location')]",
      "tags": {
        "name": "SXP Development SQL server"
      },
      "properties": {
        "administratorLogin": "[variables('name')]",
        "administratorLoginPassword": "[variables('sqlServerDevelopmentPassword')]"
      },
      "resources": [
        {
          "apiVersion": "2019-06-01-preview",
          "name": "AllowDevelopmentMachine",
          "type": "firewallrules",
          "location": "[parameters('location')]",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', variables('sqlServerDevelopmentName'))]"
          ],
          "properties": {
            "startIpAddress": "81.103.80.33",
            "endIpAddress": "81.103.80.33"
          }
        },
        {
          "apiVersion": "2019-06-01-preview",
          "name": "AllowDevelopmentSlot",
          "type": "firewallrules",
          "location": "[parameters('location')]",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', variables('sqlServerDevelopmentName'))]"
          ],
          "properties": {
            "startIpAddress": "51.143.191.44",
            "endIpAddress": "51.143.191.44"
          }
        },
        {
          "name": "[variables('identityDatabaseName')]",
          "type": "databases",
          "location": "[parameters('location')]",
          "apiVersion": "2019-06-01-preview",
          "tags": {
            "name": "Development identity database"
          },
          "dependsOn": [
            "[concat('Microsoft.Sql/servers', '/', variables('sqlServerDevelopmentName'))]"
          ]
        },
        {
          "name": "[variables('sxpDatabaseName')]",
          "type": "databases",
          "location": "[parameters('location')]",
          "apiVersion": "2019-06-01-preview",
          "tags": {
            "name": "Development Sxp database"
          },
          "dependsOn": [
            "[concat('Microsoft.Sql/servers', '/', variables('sqlServerDevelopmentName'))]"
          ]
        }
      ]
    },
    {
      "name": "[variables('sqlServerName')]",
      "type": "Microsoft.DocumentDB/databaseAccounts",
      "apiVersion": "2019-12-12",
      "location": "[parameters('location')]",
      "tags": {
        "name": "Cosmos DB Account"
      },
      "properties": {
        "locations": "[variables('locations')]",
        "databaseAccountOfferType": "Standard"
      }
    },
    {
      "name": "[variables('sqlServerDevelopmentName')]",
      "type": "Microsoft.DocumentDB/databaseAccounts",
      "apiVersion": "2019-12-12",
      "location": "[parameters('location')]",
      "tags": {
        "name": "Cosmos Development DB Account"
      },
      "properties": {
        "locations": "[variables('locations')]",
        "databaseAccountOfferType": "Standard"
      }
    },
    {
      "type": "Microsoft.DocumentDB/databaseAccounts/apis/databases",
      "name": "[concat(variables('sqlServerName'), '/sql/', variables('sqlServerName'))]",
      "apiVersion": "2016-03-31",
      "dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('sqlServerName'))]" ],
      "properties": {
        "resource": {
          "name": "[variables('sqlServerName')]"
        },
        "options": {
          "throughput": "[variables('cosmosThroughPut')]"
        }
      }
    },
    {
      "type": "Microsoft.DocumentDB/databaseAccounts/apis/databases",
      "name": "[concat(variables('sqlServerDevelopmentName'), '/sql/', variables('sqlServerName'))]",
      "apiVersion": "2016-03-31",
      "dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('sqlServerDevelopmentName'))]" ],
      "properties": {
        "resource": {
          "name": "[variables('sqlServerName')]"
        },
        "options": {
          "throughput": "[variables('cosmosDevelopThroughPut')]"
        }
      }
    },
    {
      "name": "[concat(variables('sqlServerName'), '/sql/', variables('sqlServerName'), '/', variables('cosmosContainerName'))]",
      "type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers",
      "apiVersion": "2016-03-31",
      "dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('sqlServerName'), 'sql', variables('sqlServerName'))]" ],
      "properties": {
        "resource": {
          "name": "[variables('cosmosContainerName')]",
          "partitionKey": {
            "paths": [
              "/categoryId"
            ],
            "kind": "Hash"
          },
          "indexingPolicy": {
            "indexingMode": "consistent",
            "includedPaths": [
              {
                "path": "/*"
              }
            ]
          }
        }
      }
    },
    {
      "name": "[concat(variables('sqlServerDevelopmentName'), '/sql/', variables('sqlServerName'), '/', variables('cosmosContainerName'))]",
      "type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers",
      "apiVersion": "2016-03-31",
      "dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('sqlServerDevelopmentName'), 'sql', variables('sqlServerName'))]" ],
      "properties": {
        "resource": {
          "name": "[variables('cosmosContainerName')]",
          "partitionKey": {
            "paths": [
              "/categoryId"
            ],
            "kind": "Hash"
          },
          "indexingPolicy": {
            "indexingMode": "consistent",
            "includedPaths": [
              {
                "path": "/*"
              }
            ]
          }
        }
      }
    },
    {
      "name": "[variables('name')]",
      "type": "Sendgrid.Email/accounts",
      "location": "[parameters('location')]",
      "apiVersion": "2015-01-01",
      "plan": {
        "name": "free",
        "publisher": "Sendgrid",
        "product": "sendgrid_azure",
        "promotionCode": ""
      },
      "properties": {
        "password": "[variables('sendGridPassword')]",
        "acceptMarketingEmails": "0"
      }
    }
  ]
}

When I run it, I get an error stating that there is a conflict with sxp.database.windows.net.

If I removed the live sql server, it works:

{
      "name": "[variables('sqlServerName')]",
      "type": "Microsoft.Sql/servers",
      "apiVersion": "2019-06-01-preview",
      "location": "[parameters('location')]",
      "tags": {
        "name": "SXP SQL server"
      },
      "properties": {
        "administratorLogin": "[variables('name')]",
        "administratorLoginPassword": "[variables('sqlServerPassword')]"
      },
      "resources": [
        {
          "apiVersion": "2019-06-01-preview",
          "name": "AllowMachine",
          "type": "firewallrules",
          "location": "[parameters('location')]",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', variables('sqlServerName'))]"
          ],
          "properties": {
            "startIpAddress": "81.103.80.33",
            "endIpAddress": "81.103.80.33"
          }
        },
        {
          "apiVersion": "2019-06-01-preview",
          "name": "AllowSlot",
          "type": "firewallrules",
          "location": "[parameters('location')]",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', variables('sqlServerName'))]"
          ],
          "properties": {
            "startIpAddress": "51.143.191.44",
            "endIpAddress": "51.143.191.44"
          }
        },
        {
          "name": "[variables('identityDatabaseName')]",
          "type": "databases",
          "location": "[parameters('location')]",
          "apiVersion": "2019-06-01-preview",
          "tags": {
            "name": "Identity database"
          },
          "dependsOn": [
            "[concat('Microsoft.Sql/servers', '/', variables('sqlServerName'))]"
          ]
        },
        {
          "name": "[variables('sxpDatabaseName')]",
          "type": "databases",
          "location": "[parameters('location')]",
          "apiVersion": "2019-06-01-preview",
          "tags": {
            "name": "Sxp database"
          },
          "dependsOn": [
            "[concat('Microsoft.Sql/servers', '/', variables('sqlServerName'))]"
          ]
        }
      ]
    },

But the strange thing is that when I run it and look in my resource group, it actually shows conflicts with the cosmos db accounts:

enter image description here

Which is odd, the error messages look like this:

Message: {"code":"BadRequest","message":"Message: {\"partitionCount\":1}\r\nActivityId: 1fd32e81-a8df-4789-920e-5594f8583ce9, Request URI: /apps/a678790d-5f32-4849-9590-eb510b1dc384/services/dec5d369-43fe-49e5-ba42-4bc135299134/partitions/f780127e-794c-4ab7-9448-7aec1d4b6c81/replicas/132271944036741324p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/2.9.2"}, Request URI: /dbs, RequestStats: , SDK: Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2

the sxp appsettings error is this:

Unable to process template language expressions for resource '/subscriptions/87ce59eb-a0b7-428c-8b0a-506da6569d92/resourceGroups/sxp/providers/Microsoft.Web/sites/sxp-api-develop/config/appsettings' at line '1' and column '7003'. 'The language expression property 'key1' doesn't exist, available properties are 'keys'.'

and the last one (for the sql server) states this:

The name 'sxp.database.windows.net' already exists. Choose a different name.

Like I said, when I remove the sql server (and database) it all deploys fine and there are no conflicts. Does anyone know what I am doing wrong?

1
As far as I knew, the same type Azure resource cannot have the same time. When you use the same name to create the new resource, you will get the error. For more details, please refer to docs.microsoft.com/en-us/azure/cloud-adoption-framework/ready/…Jim Xu

1 Answers

0
votes

For the second error sxp appsettings error, you are using the listkeys function wrong in appsettings child resource of [variables('sxpApiWebAppName')] and [variables('sxpApiDevelopWebAppName')] Microsoft.Web/sites resources in the first template.

As per documentation and here, listkeys returns a keys array. To access the actual string of the key, use listkeys(....).keys[0].value.

Basically, replace listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('name')), '2019-06-01').key1) line to listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('name')), '2019-06-01').keys[0].value) and try again.

Also, to get the storage account key, storage account has to exist or should be deployed before using the key. Since storage account itself does not have any dependencies, it should be deployed first. Same for other resources which do not depend on another resource. Add storage account to the dependsOn for both the resources. The second error should go away.