Account Factory から新規アカウント作成に失敗したアカウントを Service Catalog から更新かけて修正できるのか試してみた

2022.11.08

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Account Factory から新規アカウント作成に以下のエラーで失敗しました。失敗したアカウントに対して Service Catalog から更新をかけることで復旧できるのか試してみました。

エラーメッセージ

AWS Control Tower cannot complete the operation because activation of accout 123456789012 not complete. Try again in one hour. if this error persists, contact AWS Support.

確認結果

エラーメッセージの指示どおり、数時間あけてから新規アカウント作成をし直した方が良いです。

  • Service Catalog からの更新で作成に失敗したアカウントを Contrlo Tower へ登録はできた
  • 指定 OU 配下に新規アカウント作成時、規定の設定を入れ込む CfCT が実行されなかった
  • 数時間後に改めてアカウント作成すると正常に作成できた

CfCT の設定内容にも依りますが多くの場合は修正したアカウントが正常なのか確認する工数より、新たに新規にアカウントを作成した方が工数を削減できると思われます。

アカウント作成に失敗する

Account Factory からSandboxOU 配下に新規アカウント(Sandbox5)を作成しようとしました。

しばらくしてエラーになりました。

Control Tower の組織画面から確認するとRoot直下に「登録に失敗しました」のステータスでアカウントが作成されています。SanboxOU を指定いたのですが、作成に失敗したアカウントは Root 直下にありました。なにかしら要因で失敗したフェーズによっては指定した OU 内にアカウントが作成されている場合もありそうです。

詳細をクリックすると以下のメッセージが右ペインに表示されました。

失敗したアカウント詳細は以下のキャプチャを参考にしてください。

エラメッセージによると1時間後に再試行してくださいとのことです。新規アカウントを作成し直すのがベターな対応と読み取れます

エラーメッセージ

AWS Control Tower cannot complete the operation because activation of accout 123456789012 not complete. Try again in one hour. if this error persists, contact AWS Support.

新規失敗したアカウントを正常なアカウントに修正することは可能なのか?と気になりましたので試してみます。

修正を試みる

今回の新規アカウント作成の失敗の何かしらの要因で Contorol Tower の登録に失敗したように見受けられました。Contorol Tower へ再登録できないか試してみます。

Service Catalog からプロビジョニングされた製品に Control Tower のアカウントの設定情報があります。

ここから失敗アカウントに対して更新をかければ Control Tower へ再登録できるかやってみます。

AWS Control Tower Account Factoryを選択して製品を変更をかけます。

Account Factory からアカウントを新規発行するのと同じ入力項目が求められます。同じ値を入力して更新をかけます。

10分弱放置すると Control Tower へ登録でき、OU も指定したSandbox OU 配下にアカウントが移動されています。

今回の作業は Contorol Tower 管理アカウントの OU 移動手順と同じ操作をしているため、アカウントが移動されるのは当然と言えば当然なのかもしれません。

Control Tower 組織画面から確認する分には指定した OU 配下に新規アカウントが作成された(修正できた)様に思えます。次は失敗してから修正したアカウント(Sanbox5)へログインして確認してみます。

CfCTの結果を確認してみた

SanboxOU 配下にアカウントが作成されると規定の設定を入れる CfCT を設定していました。結論から述べると新規アカウント作成に失敗して Service Catalog から更新かけて修正したアカウントには CfCT の設定が入っていませんでした。

EventBridge ルールではアカウントを作成をフックしています。

{
  "detail-type": ["AWS Service Event via CloudTrail"],
  "source": ["aws.controltower"],
  "detail": {
    "serviceEventDetails": {
      "createManagedAccountStatus": {
        "state": ["SUCCEEDED"]
      }
    },
    "eventName": ["CreateManagedAccount"]
  }
}

以下は CfCT で使用しているマニュフェストファイルです。対象の OU は Sandbox OU と、Security OU にしています。

---
# Home region for CodePipeline, StepFunctions, Lambda, SSM, StackSets
region: ap-northeast-1  # Control Tower Home Region
version: 2021-03-15

resources:
  # ControlTower Custom SCPs - Additional Preventive Guardrails
  - name: test-preventive-guardrails
    description: Prevent deleting or disabling resources in member accounts
    resource_file: s3://marketplace-sa-resources-ct-ap-northeast-1/ctlabs/preventive-guardrails.json
    deploy_method: scp
    # Apply to the following OU(s)
    deployment_targets:
      organizational_units:
        # New Essential OU names since ControlTower v2.7 April 16.
        # Observe the names of your existing OUs and comment out or uncomment below to match yours.
        - Security # Foremerly Core
        - Sandbox # Formerly Custom
        #- Core
        #- Custom

  # ControlTower Custom CFN Resources - Create Additional IAM Role
  - name: create-iam-role
    resource_file: s3://marketplace-sa-resources-ct-ap-northeast-1/ctlabs/describe-regions-iam-role.template
    deploy_method: stack_set
    deployment_targets:
      organizational_units:
        # New Essential OU names since ControlTower v2.7 April 16.
        # Observe the names of your existing OUs and comment out or uncomment these to match yours.
        - Security # Foremerly Core
        - Sandbox # Formerly Custom
        #- Core
        #- Custom
    regions:
      - ap-northeast-1

  # ControlTower Config Rule - Additional Detective Guardrails
  - name: rotate-access-keys-guardrail
    resource_file: s3://marketplace-sa-resources-ct-ap-northeast-1/ctlabs/access_keys_rotated.template
    parameters:
      - parameter_key: maxAccessKeyAge
        parameter_value: '24'
    deploy_method: stack_set
    deployment_targets:
      organizational_units:
        # New Essential OU names since ControlTower v2.7 April 16.
        # Observe the names of your existing OUs and comment out or uncomment these to match yours.
        - Security # Foremerly Core
        - Sandbox # Formerly Custom
        #- Core
        #- Custom
    regions:
      - ap-northeast-1

新規アカウント作成に失敗したアカウントは最初 Root 直下に作成された影響か、Sandbox OUに設定していた CfCT が実行されなかった様です。CfCT のマニュフェストを更新して CodeCommit にアップし直しで CodePipeline を走らせれば修正完了できそうです。

Sandbox5 の確認結果

IAM ロールが自動作成される期待する状態です。StackSet-Customから始まる IAM ロールが新規アカウントに作成されています。

Sandbox5 アカウントでは IAM ロールが作成されていないです。

Config ルールが自動作成される期待する状態です。

Sanbox5 アカウントでは Config ルールも作成されていませんでした。

数時間あけてから新規アカウント作成を試してみた

エラーメッセージに従い時間をあけてから新規アカウント作成を試してみました。

エラーメッセージ

AWS Control Tower cannot complete the operation because activation of accout 123456789012 not complete. Try again in one hour. if this error persists, contact AWS Support.

この間に他にも検証していた OU 構成に変更が見られますが、新規アカウント(Sanbox6)は問題なく指定したSanbox OU 配下に作成できました。

SandboxOU 配下のため、CfCT は実行され、Sanbox5 アカウントの CfCT の実行結果確認で期待する状態になっていました。

まとめ

新規アカウント作成失敗したアカウントを Service Catalog から更新かけると、Control Tower のダッシュボードから確認する分には正常に見えるが、 CfCT などの後続作業が期待した動作をしていない可能性があります(ありました)。そのため、エラーメッセージの指示どおり時間あけてから新規アカウントを作成した方が無難な対応でした。

修正したアカウントに問題がないか確認する工数を鑑みると、失敗したアカウントは諦め新規アカウントなので作り直しがいいですね。どうせ新規アカウントですしね。

おわりに

トラブルシューティングガイドに現時点では載っていないメッセージであったため記録に残しました。

Troubleshooting - AWS Control Tower