

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# ステートファイルが失われた後、 AWS Account Factory for Terraform (AFT) リソースを安全にクリーンアップする
<a name="clean-up-aft-resources-safely-after-state-file-loss"></a>

*Gokendra Malviya (Amazon Web Services)*

## 概要
<a name="clean-up-aft-resources-safely-after-state-file-loss-summary"></a>

 AWS Account Factory for Terraform (AFT) を使用して AWS Control Tower 環境を管理すると、AFT は Terraform 状態ファイルを生成して、Terraform によって作成されたリソースの状態と設定を追跡します。Terraform ステートファイルが失われると、リソース管理とクリーンアップに大きな課題が生じる可能性があります。このパターンは、 AWS Control Tower 環境の整合性を維持しながら、AFT 関連のリソースを安全に識別および削除する体系的なアプローチを提供します。

このプロセスは、元のステートファイルへの参照がない場合でも、すべての AFT コンポーネントを適切に削除できるように設計されています。このプロセスは、 AWS Control Tower オペレーションの中断を最小限に抑えるために、環境で AFT を正常に再確立および再設定するための明確な道筋を提供します。

AFT の詳細については、[AWS Control Tower のドキュメント](https://docs.aws.amazon.com/controltower/latest/userguide/taf-account-provisioning.html)を参照してください。

## 前提条件と制限
<a name="clean-up-aft-resources-safely-after-state-file-loss-prereqs"></a>

**前提条件**
+ [AFT アーキテクチャ](https://docs.aws.amazon.com/controltower/latest/userguide/aft-architecture.html)についての十分な理解。
+ 次のアカウントへの管理者アクセス:
  + AFT 管理アカウント
  + AWS Control Tower 管理アカウント
  + ログアーカイブアカウント
  + 監査アカウント
+ AFT 関連リソースの削除をブロックする制約や制限がサービスコントロールポリシー (SCP) に含まれていないことを確認します。

**制限事項**
+ このプロセスではリソースを効果的にクリーンアップできますが、失われたステートファイルを復元することはできません。また、一部のリソースは手動で識別しなければならない場合があります。
+ クリーンアッププロセスの所要時間は、環境の複雑さによって異なり、数時間かかる場合もあります。
+ このパターンは AFT バージョン 1.12.2 でテストされており、次のリソースを削除します。別のバージョンの AFT を使用している場合は、追加リソースの削除が必要になる場合があります。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html)

**重要**  
このパターンの各ステップで削除されたリソースは復元できません。これらのステップを実行する前に、リソース名を慎重に確認し、それらが AFT によって作成されていることを確認してください。

## アーキテクチャ
<a name="clean-up-aft-resources-safely-after-state-file-loss-architecture"></a>

次の図は、AFT の各コンポーネントと高レベルのワークフローを示します。AFT は、 AWS Control Towerでアカウントのプロビジョニングとカスタマイズを支援する Terraform パイプラインを設定します。AFT は GitOps モデルに従って、アカウントプロビジョニングのプロセスを自動化します AWS Control Tower。ここで、ユーザーはアカウントリクエストの Terraform ファイルを作成し、リポジトリにコミットします。このファイルは、アカウントプロビジョニングの AFT ワークフローをトリガーするための入力となります。アカウントプロビジョニングが完了すると、AFT は追加のカスタマイズ手順を自動的に実行できます。

![\[AFT コンポーネントと高レベルのワークフロー。\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/images/pattern-img/1342c0a6-4b07-46df-a063-ceab2e2f83c8/images/3e0cae87-20ef-4fcc-aacf-bb450844ac56.png)


このアーキテクチャの詳細は以下のとおりです。
+ **AWS Control Tower 管理アカウント**は AWS アカウント 、 AWS Control Tower サービス専用の です。これは通常、*AWS 支払者アカウント*または *AWS Organizations 管理アカウント*とも呼ばれます。
+ **AFT 管理アカウント**は AWS アカウント 、AFT 管理オペレーション専用の です。これは、組織の管理アカウントとは異なります。
+ **販売済みアカウント**は、選択したすべてのベースラインコンポーネントとコントロール AWS アカウント を含む です。AFT は AWS Control Tower を使用して新しいアカウントを提供します。

このアーキテクチャの詳細については、 AWS Control Tower ワークショップの[「AFT の概要](https://catalog.workshops.aws/control-tower/en-US/customization/aft)」を参照してください。

## ツール
<a name="clean-up-aft-resources-safely-after-state-file-loss-tools"></a>

**AWS のサービス**
+ [AWS Control Tower](https://docs.aws.amazon.com/controltower/latest/userguide/what-is-control-tower.html) は、規範的なベストプラクティスに従って、 AWS マルチアカウント環境のセットアップと管理に役立ちます。
+ [AWS Account Factory for Terraform (AFT)](https://docs.aws.amazon.com/controltower/latest/userguide/taf-account-provisioning.html) は、アカウントとリソースのプロビジョニングとカスタマイズに役立つ Terraform パイプラインを設定します AWS Control Tower。
+ [AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html) は、 AWS リソースの拡大とスケーリングに合わせて環境を一元的に管理および管理するのに役立ちます。Organizations を使用すると、アカウントの作成、リソースの割り当て、ワークロードを整理するためのアカウントのグループ化、ガバナンスポリシーの適用、すべてのアカウントに単一の支払い方法を使用した請求の簡素化が可能になります。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) は、誰を認証し、誰に使用する権限を付与するかを制御することで、 AWS リソースへのアクセスを安全に管理するのに役立ちます。このパターンには、IAM ロールとアクセス許可が必要です。

**その他のツール**
+ [Terraform](https://www.terraform.io/) は、HashiCorp の infrastructure as code (IaC) ツールで、クラウドとオンプレミスのリソースの作成と管理を支援します。

## ベストプラクティス
<a name="clean-up-aft-resources-safely-after-state-file-loss-best-practices"></a>
+ については AWS Control Tower、 AWS Control Tower ドキュメントの[AWS Control Tower 「管理者向けのベストプラクティス](https://docs.aws.amazon.com/controltower/latest/userguide/best-practices.html)」を参照してください。
+ IAM については、IAM ドキュメントの「[IAM でのセキュリティのベストプラクティス](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)」を参照してください。

## エピック
<a name="clean-up-aft-resources-safely-after-state-file-loss-epics"></a>

### AFT 管理アカウントで AFT リソースを削除する
<a name="delete-aft-resources-in-the-aft-management-account"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| AFT タグで識別されるリソースを削除する | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | AWS 管理者、AWS DevOps、DevOps エンジニア | 
| IAM ロールを削除する | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | AWS 管理者、AWS DevOps、DevOps エンジニア | 
|  AWS Backup バックアップボールトを削除します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | AWS 管理者、AWS DevOps、DevOps エンジニア | 
| Amazon CloudWatch リソースの削除 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | AWS 管理者、AWS DevOps、DevOps エンジニア | 
|  AWS KMS リソースを削除します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | AWS 管理者、AWS DevOps、DevOps エンジニア | 

### ログアーカイブアカウントで AFT リソースを削除する
<a name="delete-aft-resources-in-the-log-archive-account"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| S3 バケットを削除する | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | AWS 管理者、AWS DevOps、DevOps エンジニア | 
| IAM ロールを削除する | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | AWS 管理者、AWS DevOps、DevOps エンジニア | 

### 監査アカウントで AFT リソースを削除する
<a name="delete-aft-resources-in-the-audit-account"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| IAM ロールを削除する | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | AWS 管理者、AWS DevOps、DevOps エンジニア | 

### AWS Control Tower 管理アカウントで AFT リソースを削除する
<a name="delete-aft-resources-in-the-ctower-management-account"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| IAM ロールを削除する | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | AWS 管理者、AWS DevOps、DevOps エンジニア | 
| EventBridge ルールを削除する | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | AWS 管理者、AWS DevOps、DevOps エンジニア | 

## トラブルシューティング
<a name="clean-up-aft-resources-safely-after-state-file-loss-troubleshooting"></a>


| 問題 | ソリューション | 
| --- | --- | 
| インターネットゲートウェイのデタッチに失敗した | **AFT** タグで識別されるリソースを削除しようとして、インターネットゲートウェイをデタッチまたは削除するときにこの問題が発生した場合は、まず VPC エンドポイントを削除する必要があります。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | 
| 指定した CloudWatch クエリが見つからない | AFT によって作成された CloudWatch クエリが見つからない場合は、次の手順に従います。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/clean-up-aft-resources-safely-after-state-file-loss.html) | 

## 関連リソース
<a name="clean-up-aft-resources-safely-after-state-file-loss-resources"></a>
+ AFT
  + [GitHub リポジトリ](https://github.com/aws-ia/terraform-aws-control_tower_account_factory)
  + [ワークショップ](https://catalog.workshops.aws/control-tower/en-US/customization/aft)
  + [ドキュメント](https://docs.aws.amazon.com/controltower/latest/userguide/aft-getting-started.html)
+ [AWS Control Tower ドキュメント](https://docs.aws.amazon.com/controltower/latest/userguide/getting-started-with-control-tower.html)

## 追加情報
<a name="clean-up-aft-resources-safely-after-state-file-loss-additional"></a>

CloudWatch のログのインサイトダッシュボードで AFT クエリを表示するには、次のスクリーンショットに示すように、画面右上隅の **[保存済みクエリとサンプルクエリ]** アイコンを選択します。

![\[CloudWatch のログのインサイトダッシュボードでの AFT クエリへのアクセス\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/images/pattern-img/1342c0a6-4b07-46df-a063-ceab2e2f83c8/images/255d4032-738b-4600-9084-9684d2e9a328.png)
