4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【初心者】Azure Resource Manager テンプレートを使ってみる

Posted at

目的

  • AWS CloudFormation に相当するAzureの機能を確認したい。
  • MS公式サイトのサービス比較「AWS サービスと Azure サービスの比較」によると、CloudFormationに相当するのは「Azure Resource Manager」とのことで、それを使ってみる。

Azure Resource Manager テンプレートとは(自分の理解)

  • Azure Resource Manager は、Azureのリソース(仮想マシン、仮想ネットワーク等)を管理する仕組みのこと。その中にある「Azure Resource Manager テンプレート」が、JSONで定義した内容をデプロイできる機能であり、CloudFormationに近いイメージ。

やったこと

  • 以下を定義する Azure Resource Manager テンプレート(JSONファイル)を作成し、デプロイを行う。
    • vNetを作成する。(vNetはAWSのVPCに概ね相当)
    • Subnetを作成する。

構成図

rm09.png

作業手順

JSONファイルの作成

  • MS公式サイト「仮想ネットワーク用の Azure Resource Manager テンプレート サンプル 」の中から、「2 つのサブネットから成る仮想ネットワークの作成」を行う既存のテンプレートを選択し、JSONファイルをダウンロードする。
  • JSONファイルの不要な部分を削除し、vNetを1個、subnetを1個作るだけの内容に修正する。
  • フォーマットとしては、parametersとして変数を、resourcesとして作成するリソースを定義する等、CloudFormation用のJSONファイルと内容は似ている。
sampletemplate.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vnetName": {
      "type": "string",
      "defaultValue": "VNet1",
      "metadata": {
        "description": "VNet name"
      }
    },
    "vnetAddressPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/16",
      "metadata": {
        "description": "Address prefix"
      }
    },
    "subnet1Prefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/24",
      "metadata": {
        "description": "Subnet 1 Prefix"
      }
    },
    "subnet1Name": {
      "type": "string",
      "defaultValue": "Subnet1",
      "metadata": {
        "description": "Subnet 1 Name"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "variables": {},
  "resources": [
    {
      "apiVersion": "2018-10-01",
      "type": "Microsoft.Network/virtualNetworks",
      "name": "[parameters('vnetName')]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('vnetAddressPrefix')]"
          ]
        }
      },
      "resources": [
        {
          "apiVersion": "2018-10-01",
          "type": "subnets",
          "location": "[parameters('location')]",
          "name": "[parameters('subnet1Name')]",
          "dependsOn": [
            "[parameters('vnetName')]"
          ],
          "properties": {
            "addressPrefix": "[parameters('subnet1Prefix')]"
          }
        }
      ]
    }
  ]
}

リソースのデプロイ

  • MS公式サイトによると、ポータル、CLI、PowerShell、REST APIでのデプロイが可能とのこと。今回は初心者なのでポータルからのデプロイを行う。

  • 「テンプレートのデプロイ」画面へ
    rm02a.png

  • 「エディターで独自のテンプレートを作成」を選択

rm03a.png

  • Parametersで規定した値(vNetの名前/アドレスレンジ、subnetの名前/アドレスレンジ、リージョン、リソースグループ)を記入、選択して、「購入」する。(ボタンは「購入」だが、何かを購入するわけではない)
    rm05a.png

結果確認

  • vNet及びsubnetが作成されることを確認する。

rm07a.png

rm08a.png

所感

  • このテンプレートで作ったリソースは、stackとしての管理ができるのか?等、よく分からない点もあるため、引き続き勉強していきたい。

参考

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?