Azure Classroomnotes 30/Jun/2022

Inbuilt Functions in arm templates

  • Functions in arm templates can be called with the following syntax "[<function>(arg1, arg2....,argn)]"
  • ARM Template functions Refer Here
  • To define parameters in ARM Templates Refer Here
  • For creating iterations in ARM Templates Refer Here
  • Refer Here for the changes done in the template and below for the complete template
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "primaryregion": {
            "type": "string",
            "metadata": {
                "description": "This is the primary region"
            },
            "defaultValue": "southindia"
        },
        "secondaryregion": {
            "type": "string",
            "metadata": {
                "description": "This is the primary region"
            },
            "defaultValue": "centralindia"
        },
        "primary-cidr": {
            "type": "string",
            "metadata": {
                "description": "This is the primary vnet address space"
            },
            "defaultValue": "10.0.0.0/16"
        },
        "secondary-cidr": {
            "type": "string",
            "metadata": {
                "description": "This is the secondary vnet address space"
            },
            "defaultValue": "10.1.0.0/16"
        },
        "subnet-names": {
            "type": "array",
            "metadata": {
                "description": "subnet name"
            },
            "defaultValue": ["web", "app", "db", "mgmt"]
        },
        "primary-subnet-cidr-format": {
            "type": "string",
            "metadata": {
                "description": "subnet cidr format"
            },
            "defaultValue": "10.0.{0}.0/24"
        },
        "secondary-subnet-cidr-format": {
            "type": "string",
            "metadata": {
                "description": "subnet cidr format"
            },
            "defaultValue": "10.1.{0}.0/24"
        }

    },
    "resources": [
        {
            "type": "Microsoft.Network/virtualNetworks",
            "apiVersion": "2020-11-01",
            "name": "primaryvnet",
            "location": "[parameters('primaryregion')]",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [ "[parameters('primary-cidr')]" ]
                }
            }
        },
        {
            "type": "Microsoft.Network/virtualNetworks/subnets",
            "apiVersion": "2020-11-01",
            "name": "[format('primaryvnet/{0}',parameters('subnet-names')[copyIndex()])]",
            "properties": {
                "addressPrefix": "[format(parameters('primary-subnet-cidr-format'),copyIndex())]"
            },
            "copy": {
                "name": "primary-subnet-copy",
                "count": "[length(parameters('subnet-names'))]",
                "mode": "Serial"

            },
            "dependsOn": [
                "[resourceId('Microsoft.Network/virtualNetworks','primaryvnet')]"
            ]

        },
        {
            "type": "Microsoft.Network/virtualNetworks",
            "apiVersion": "2020-11-01",
            "name": "secondaryvnet",
            "location": "[parameters('secondaryregion')]",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [ "[parameters('secondary-cidr')]" ]
                }
            }
        },
        {
            "type": "Microsoft.Network/virtualNetworks/subnets",
            "apiVersion": "2020-11-01",
            "name": "[format('secondaryvnet/{0}',parameters('subnet-names')[copyIndex()])]",
            "properties": {
                "addressPrefix": "[format(parameters('secondary-subnet-cidr-format'),copyIndex())]"
            },
            "copy": {
                "name": "secondary-subnet-copy",
                "count": "[length(parameters('subnet-names'))]",
                "mode": "Serial"

            },
            "dependsOn": [
                "[resourceId('Microsoft.Network/virtualNetworks','secondaryvnet')]"
            ]

        }
    ]
}
  • Try deploying
  • Note: fix in the template try this template and deploy
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%