App Service PlanとApp Serviceをリソースグループ間で移動する場合の制限
Created at:
AzureのApp Service PlanとApp Serviceをリソースグループ間で移動する場合には制限事項があり、その手順に沿って移動しないとうまくいきません。…というのにはまりました。
ドキュメントのApp Serviceの制限事項には以下のように書かれています。
App Service アプリを使用している場合、App Service プランのみを移動することはできません。 App Service アプリを移動するには、次のオプションがあります。
- App Service プランとそのリソース グループ内の他のすべての App Service リソースを、まだ App Service リソースが含まれていない新しいリソース グループに移動する。 この要件により、App Service プランに関連付けられていない App Service リソースも移動する必要があります。
- アプリを別のリソース グループに移動し、元のリソース グループにも App Service プランをすべて保持する。
アプリが正常に動作するために、App Service プランがそのアプリと同じリソース グループ内に存在する必要はありません。
これ(とそれに続く説明)はどういうことなのかというのがピンとこないので順を追って移動する例を見ていきます。
初期構成の想定
まずは初期構成として以下のような構成になっているとします。
- Resource Group: App1Group
- App Service Plan: Basic1
- App Service: App1 (プランはBasic1を利用)
- Application Insights: App1
- Resource Group: App2Group
- App Service: App2 (プランはBasic1を利用)
- Application Insights: App2
最終的な構成
次に移動した結果として希望したい構成です。
- Resource Group: BasicPlan
- App Service Plan: Basic1
- Resource Group: App1Group
- App Service: App1 (プランはBasic1を利用)
- Application Insights: App1
- Resource Group: App2Group
- App Service: App2 (プランはBasic1を利用)
- Application Insights: App2
Step 1: 新しいグループを作ってAppServiceとともに移動する
まずは新しいリソースグループ BasicPlan
を作って、App Service Planを移動します。この際、App Service Planの移動とそれに付随するリソース(App Serviceなど)はすべて新しいリソースグループに移動する必要があります。
- Resource Group: BasicPlan
- App Service Plan: Basic1
- App Service: App1 (プランはBasic1を利用)
- Application Insights: App1
- Resource Group: App2Group
- App Service: App2 (プランはBasic1を利用)
- Application Insights: App2
Step 2: 他のリソースも新しいグループに一度まとめる
次にもう一つのApp Serviceも一度新しいリソースグループ BasicPlan
に移動します。 App Service自体の移動にはApp Service Planは必要ないのでそのまま移動できます。
- Resource Group: BasicPlan
- App Service Plan: Basic1
- App Service: App1 (プランはBasic1を利用)
- Application Insights: App1
- App Service: App2 (プランはBasic1を利用)
- Application Insights: App2
Step 3: App Serviceを移動する
次に新しいリソースグループ App1Group
, App2Group
を作り、そこにApp Serviceのみを移動します。
- Resource Group: BasicPlan
- App Service Plan: Basic1
- Application Insights: App1
- Application Insights: App2
- Resource Group: App1Group
- App Service: App1 (プランはBasic1を利用)
- Resource Group: App2Group
- App Service: App2 (プランはBasic1を利用)
Step 4: App Service以外を移動する
最後にApp Service以外を移動します。
- Resource Group: BasicPlan
- App Service Plan: Basic1
- Resource Group: App1Group
- App Service: App1 (プランはBasic1を利用)
- Application Insights: App1
- Resource Group: App2Group
- App Service: App2 (プランはBasic1を利用)
- Application Insights: App2
注意事項
az resource move
(azure-cli)で移動する
Azure ポータルからではなくazure-cliを利用して移動すると、バリデーションがかからずバラバラに移動できてしまいポータルよりいいと思いきや、想定外の形になることがあるようなので素直にポータルからやっていきましょう。
原則として1つのResource Groupに一つ以上WebApp リソース(App Service Plan)を移動できない
App Service Planの移動先にすでにMicrosoft.Web以下のリソースタイプなどがあると移動できません。ドキュメントのまだ App Service リソースが含まれていない新しいリソース グループに移動する
というのはこの制限事項のことを指しています。
この状態で移動しようとすると以下のようなエラーメッセージが表示されます。
There was an error moving resources. Resource move validation failed. Please see details. Diagnostic information: timestamp '20170805T164541Z', subscription id 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', tracking id 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', request correlation id 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'. (Code: ResourceMoveProviderValidationFailed) Cannot move WebApp resources to a resource group that already contains WebApp resources. Please ensure destination resource group Common does not have any WebApp resources in it before performing the next move operation. Or create a new resource group and move resources there. (Code: BadRequest, Target: Microsoft.Web/serverFarms)
App Service Planの移動と同時にすでにバラバラになっているApp Serviceを一度移動する必要がある
App Service Planを移動するときには関連したApp Serviceも同時に移動する必要があります。つまり一度App Service Planを移動する前にApp Serviceを同じリソースグループに移動する必要があります。
ドキュメントではWeb アプリがその App Service プランとは異なるリソース グループに存在するが、その両方を新しいリソース グループに移動する場合、移動を 2 段階で行う必要があります
として解説されているのがこれです。
この状態で移動しようとすると以下のようなエラーメッセージが表示されます。
There was an error moving resources. Resource move validation failed. Please see details. Diagnostic information: timestamp '20170805T175159Z', subscription id 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', tracking id 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', request correlation id 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'. (Code: ResourceMoveProviderValidationFailed) Cannot move resources because some site(s) are located in other resource group(s) but hosted by resource group 'Default-Web-JapanEast'. The list of site(s) and corresponding resource groups: 'website-01:Default-Web-JapanEast,website-02:Default-Web-JapanEast'. This may be a result of prior move operations. Move the site(s) back to respective hosting resource group(s) and try again. (Code: BadRequest, Target: Microsoft.Web/serverFarms)
Microsoft.Web/certificates リソースタイプは移動不能
証明書はApp Service Planに関連付けられ、そのリソースグループに移動不能な形で残るので最悪削除する羽目になります(新しいリソースグループで証明書を追加できなくなる場合がある)。
まとめ
移動するのは手順はともかくとしても処理に時間がかかるので、App Service Planとリソースグループの構成は最初からちゃんと考えておいたほうがいいでしょう。まあ真面目に使うときには考えて作るとは思いますが…。