2016年5月19日木曜日

githubのAzure Resource Manager テンプレートをカスタマイズしてみた - 仮想ネットワーク、GatewayサブネットとVPN Gatewayを一度に作る

ここまでカスタマイズしてきたコード


をマージして、仮想ネットワーク、GatewayサブネットとVPN Gatewayを一度に作るJSONコードも書いてみました。

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vnetName": {
      "type": "string",
      "defaultValue": "ArmVNet1",
      "metadata": {
        "description": "VNet name"
      }
    },
    "vnetAddressPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/16",
      "metadata": {
        "description": "Address prefix"
      }
    },
    "subnet1Name": {
      "type": "string",
      "defaultValue": "Subnet1",
      "metadata": {
        "description": "Subnet 1 Name"
      }
    },"subnet1Prefix": {
      "type": "string",
      "defaultValue": "10.0.1.0/24",
      "metadata": {
        "description": "Subnet 1 Prefix"
      }
    },
    "subnet2Name": {
      "type": "string",
      "defaultValue": "Subnet2",
      "metadata": {
        "description": "Subnet 2 Name"
      }
    },
    "subnet2Prefix": {
      "type": "string",
      "defaultValue": "10.0.2.0/24",
      "metadata": {
        "description": "Subnet 2 Prefix"
      }
    },
    "gatewaySubnetName": {
      "type": "string",
      "defaultValue": "GatewaySubnet",
      "metadata": {
        "description": "Gateway subnet namee"
      }
    },
    "gatewaySubnetPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/26",
      "metadata": {
        "description": "CIDR block for gateway subnet, subset of azureVNetAddressPrefix address space"
      }
    },
    "gatewayName": {
      "type": "string",
      "defaultValue": "armAzureGateway01",
      "metadata": {
        "description": "Arbitrary name for the new gateway"
      }
    },
    "gatewaySku": {
      "type": "string",
      "metadata": {
        "description": "The Sku of the Gateway. This must be one of Basic, Standard or HighPerformance."
      },
      "defaultValue": "Basic",
      "allowedValues": [
        "Basic",
        "Standard",
        "HighPerformance"
      ]
    },
    "vpnType": {
      "type": "string",
      "metadata": {
        "description": "Route based as a Dynamic Routing or policy based as a Static Routing"
      },
      "defaultValue": "PolicyBased",
      "allowedValues": [
        "RouteBased",
        "PolicyBased"
      ]
    },
    "sharedKey": {
      "type": "securestring",
      "metadata": {
        "description": "Shared key (PSK) for IPSec tunnel"
      }
    },
    "connectionName": {
      "type": "string",
      "defaultValue": "Azure2Local-01",
      "metadata": {
        "description": "Arbitrary name for the new connection between Azure VNet and other network"
      }
    },
    "localGatewayName": {
      "type": "string",
      "defaultValue": "localGateway01",
      "metadata": {
        "description": "Arbitrary name for gateway resource representing "
      }
    },
    "localGatewayIpAddress": {
      "type": "string",
      "defaultValue": "1.1.1.1",
      "metadata": {
        "description": "Public IP of your local Gateway"
      }
    },
    "localAddressPrefix": {
      "type": "string",
      "defaultValue": "192.168.0.0/16",
      "metadata": {
        "description": "CIDR block representing the address space of the OnPremise VPN network's Subnet"
      }
    }
  },
  "variables": {
    "vnetID": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]",
    "gatewaySubnetRef": "[concat(variables('vnetID'),'/subnets/',parameters('gatewaySubnetName'))]",
    "virtualNetworkGatewayID": "[resourceId('Microsoft.Network/virtualNetworkGateways', parameters('gatewayName'))]",
    "localNetworkGatewayID": "[resourceId('Microsoft.Network/localNetworkGateways', parameters('localGatewayName'))]",
    "gatewayPublicIPName": "[concat(parameters('gatewayName'),'-PublicIP')]",
    "publicIPAddressID": "[resourceId('Microsoft.Network/publicIPAddresses',variables('gatewayPublicIPName'))]",
    "apiversion": "2015-06-15"
  },
  "resources": [   
    {
      "apiVersion": "[variables('apiversion')]",
      "type": "Microsoft.Network/localNetworkGateways",
      "name": "[parameters('localGatewayName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "localNetworkAddressSpace": {
          "addressPrefixes": [
            "[parameters('localAddressPrefix')]"
          ]
        },
        "gatewayIpAddress": "[parameters('localGatewayIpAddress')]"
      }
    },
    {
      "apiVersion": "[variables('apiversion')]",
      "name": "[parameters('connectionName')]",
      "type": "Microsoft.Network/connections",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Network/virtualNetworkGateways/', parameters('gatewayName'))]",
        "[concat('Microsoft.Network/localNetworkGateways/', parameters('localGatewayName'))]"
      ],
      "properties": {
        "virtualNetworkGateway1": {
          "id": "[variables('virtualNetworkGatewayID')]"
        },
        "localNetworkGateway2": {
          "id": "[variables('localNetworkGatewayID')]"
        },
        "connectionType": "IPsec",
        "routingWeight": 10,
        "sharedKey": "[parameters('sharedKey')]"
      }
    },
    {
      "apiVersion": "[variables('apiVersion')]",
      "type": "Microsoft.Network/virtualNetworks",
      "name": "[parameters('vnetName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('vnetAddressPrefix')]"
          ]
        },
        "subnets": [
          {
            "name": "[parameters('gatewaySubnetName')]",
            "properties": {
              "addressPrefix": "[parameters('gatewaySubnetPrefix')]"
            }
          },
          {
            "name": "[parameters('subnet1Name')]",
            "properties": {
              "addressPrefix": "[parameters('subnet1Prefix')]"
            }
          },
          {
            "name": "[parameters('subnet2Name')]",
            "properties": {
              "addressPrefix": "[parameters('subnet2Prefix')]"
            }
          }
        ]
      }
    },
    {
      "apiVersion": "[variables('apiversion')]",
      "type": "Microsoft.Network/publicIPAddresses",
      "name": "[variables('gatewayPublicIPName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "publicIPAllocationMethod": "Dynamic"
      }
    },
    {
      "apiVersion": "[variables('apiversion')]",
      "type": "Microsoft.Network/virtualNetworkGateways",
      "name": "[parameters('gatewayName')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Network/publicIPAddresses/', variables('gatewayPublicIPName'))]",
        "[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]"
      ],
      "properties": {
        "ipConfigurations": [
          {
            "properties": {
              "privateIPAllocationMethod": "Dynamic",
              "subnet": {
                "id": "[variables('gatewaySubnetRef')]"
              },
              "publicIPAddress": {
                "id": "[variables('publicIPAddressID')]"
              }
            },
            "name": "vnetGatewayConfig"
          }
        ],
        "sku": {
          "name": "[parameters('gatewaySku')]",
          "tier": "[parameters('gatewaySku')]"
        },
        "gatewayType": "Vpn",
        "vpnType": "[parameters('vpnType')]",
        "enableBgp": "false"
      }
    }
  ]
}

0 件のコメント:

コメントを投稿