

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

# Terraform を使用して AWS WAF ソリューションのセキュリティオートメーションをデプロイする
<a name="deploy-the-security-automations-for-aws-waf-solution-by-using-terraform"></a>

*Dr. Rahul Sharad Gaikwad と Tamilselvan P、Amazon Web Services*

## 概要
<a name="deploy-the-security-automations-for-aws-waf-solution-by-using-terraform-summary"></a>

AWS WAF は、ウェブ*アクセスコントロールリスト (ACL) で定義してデプロイするカスタマイズ可能なルールを使用することで、一般的なエクスプロイトからアプリケーションを保護するのに役立つウェブ*ACLs。 AWS WAF ルールの設定は、特に専用のセキュリティチームを持たない組織では難しい場合があります。このプロセスを簡素化するために、Amazon Web Services (AWS) は Security [Automations for AWS WAF](https://aws.amazon.com/solutions/implementations/security-automations-for-aws-waf/) solution を提供しています。これにより、ウェブベースの攻撃をフィルタリングする一連の AWS WAF ルールを含む単一のウェブ ACL が自動的にデプロイされます。Terraform のデプロイ時に、どの保護機能を含めるかを指定できます。このソリューションをデプロイすると、 は既存の Amazon CloudFront ディストリビューションまたは Application Load Balancer へのウェブリクエスト AWS WAF を検査し、ルールに一致しないリクエストをブロックします。

Security Automations for AWS WAF ソリューションは、[「 Security Automations for AWS WAF Implementation Guide](https://docs.aws.amazon.com/solutions/latest/security-automations-for-aws-waf/overview.html)」の指示 AWS CloudFormation に従って を使用してデプロイできます。このパターンは、HashiCorp Terraform を推奨 Infrastructure as Code (IaC) ツールとして使用してクラウドインフラストラクチャをプロビジョニングおよび管理する組織にとって、代替のデプロイオプションとなります。このソリューションをデプロイすると、Terraform は自動的にクラウドに変更を適用し、 AWS WAF 設定と保護機能をデプロイして設定します。

## 前提条件と制限
<a name="deploy-the-security-automations-for-aws-waf-solution-by-using-terraform-prereqs"></a>

**前提条件**
+ アクティブ AWS アカウント。
+ AWS Command Line Interface (AWS CLI) バージョン 2.4.25 以降、必要なアクセス許可でインストールおよび設定されています。詳細については、[「開始方法](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) (AWS CLI ドキュメント）」を参照してください。
+ Terraform バージョン 1.1.9 以降がインストールされ、設定されていること。詳細については、「[Terraform のインストール](https://learn.hashicorp.com/tutorials/terraform/install-cli) (Terraform ドキュメント)」を参照してください。

## アーキテクチャ
<a name="deploy-the-security-automations-for-aws-waf-solution-by-using-terraform-architecture"></a>

**ターゲットアーキテクチャ**

このパターンは、 AWS WAF ソリューションのセキュリティオートメーションをデプロイします。ターゲットアーキテクチャの詳細については、*「 Security Automations for AWS WAF Implementation Guide*」の[「アーキテクチャの概要](https://docs.aws.amazon.com/solutions/latest/security-automations-for-aws-waf/overview.html)」を参照してください。このデプロイの AWS Lambda オートメーション、アプリケーションログパーサー、 AWS WAF ログパーサー、IP リストパーサー、アクセスハンドラーの詳細については、*「 Security Automations for AWS WAF Implementation Guide*」の[「コンポーネントの詳細](https://docs.aws.amazon.com/solutions/latest/security-automations-for-aws-waf/appendix-b.html)」を参照してください。

**Terraform デプロイ**

`terraform apply` を実行すると、Terraform は次のことを行います。

1. Terraform は、**testing.tfvars** ファイルからの入力に基づいて AWS Identity and Access Management (IAM) ロールと Lambda 関数を作成します。

1. Terraform は、**testing.tfvars **ファイルからの入力に基づいて AWS WAF ACL ルールと IP セットを作成します。

1. Terraform は、**testing.tfvars** ファイルからの入力に基づいて、Amazon Simple Storage Service (Amazon S3) バケット、Amazon EventBridge ルール、 AWS Glue データベーステーブル、および Amazon Athena ワークグループを作成します。

1. Terraform は AWS CloudFormation スタックをデプロイしてカスタムリソースをプロビジョニングします。

1. Terraform は、**test.tfvars** ファイルからの指定された入力に基づいて Amazon API Gateway リソースを作成します。

**自動化とスケール**

このパターンを使用して、複数の の AWS WAF ルールを作成し AWS アカウント AWS リージョン 、 AWS WAF ソリューションのセキュリティオートメーションを AWS クラウド 環境全体にデプロイできます。

## ツール
<a name="deploy-the-security-automations-for-aws-waf-solution-by-using-terraform-tools"></a>

**AWS のサービス**
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) は、コマンドラインシェルのコマンド AWS のサービス を使用して を操作するのに役立つオープンソースツールです。
+ [AWS WAF](https://docs.aws.amazon.com/waf/latest/developerguide/what-is-aws-waf.html) は、保護されたウェブアプリケーションリソースに転送される HTTP と HTTPS リクエストをモニタリングできるウェブアプリケーションファイアウォールです。

**その他のサービス**
+ [Git](https://git-scm.com/docs) はオープンソースの分散型バージョン管理システムです。
+ [HashiCorp Terraform](https://www.terraform.io/docs) は、コードを使用してクラウドインフラストラクチャとリソースをプロビジョニングおよび管理するのに役立つコマンドラインインターフェイスアプリケーションです。

**コードリポジトリ**

このパターンのコードは、GitHub 内の「[AWS WAF Automation Using Terraform](https://github.com/aws-samples/aws-waf-automation-terraform-samples)」リポジトリで利用できます。

## ベストプラクティス
<a name="deploy-the-security-automations-for-aws-waf-solution-by-using-terraform-best-practices"></a>
+ 静的ファイルは別の Amazon S3 バケットに配置してください。
+ 変数をハードコーディングすることは避けてください。
+ カスタムスクリプトの使用を制限してください。
+ 命名規則を採用してください。

## エピック
<a name="deploy-the-security-automations-for-aws-waf-solution-by-using-terraform-epics"></a>

### ローカルワークステーションをセットアップする
<a name="set-up-your-local-workstation"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| Git をインストールする。 | 「[Getting started](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)」(Git Web サイト) の指示に従って、ローカルワークステーションに Git をインストールします。 | DevOps エンジニア | 
| リポジトリのクローン作成 | ローカルワークステーションで次のコマンドを入力し、コードリポジトリをクローンします。<pre>git clone https://github.com/aws-samples/aws-waf-automation-terraform-samples.git</pre> | DevOps エンジニア | 
| 変数を更新してください。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-the-security-automations-for-aws-waf-solution-by-using-terraform.html) | DevOps エンジニア | 

### Terraform を使用してターゲットアーキテクチャをプロビジョニングします。
<a name="provision-the-target-architecture-using-terraform"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| Terraform の設定を初期化する | 次のコマンドを入力し、Terraform 設定ファイルを含む作業ディレクトリを初期化します。<pre>terraform init</pre> | DevOps エンジニア | 
| Terraform プランをプレビューしてください。 | 次のコマンドを入力します。Terraform は設定ファイルを評価して、宣言されたリソースのターゲット状態を判断します。次に、ターゲットの状態を現在の状態と比較し、プランを作成します。<pre>terraform plan -var-file="testing.tfvars"</pre> | DevOps エンジニア | 
| プランを検証してください。 | プランを確認し、ターゲットの AWS アカウントアカウントで必要なアーキテクチャが設定されていることを確認します。 | DevOps エンジニア | 
| ソリューションのデプロイ | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-the-security-automations-for-aws-waf-solution-by-using-terraform.html) | DevOps エンジニア | 

### 検証とクリーンアップ
<a name="validate-and-clean-up"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| 変更を確認します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-the-security-automations-for-aws-waf-solution-by-using-terraform.html) | DevOps エンジニア | 
| (オプション) インフラストラクチャをクリーンアップします。 | このソリューションによって行われたすべてのリソースと設定の変更を削除するには、次の操作を行います。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-the-security-automations-for-aws-waf-solution-by-using-terraform.html) | DevOps エンジニア | 

## トラブルシューティング
<a name="deploy-the-security-automations-for-aws-waf-solution-by-using-terraform-troubleshooting"></a>


| 問題 | ソリューション | 
| --- | --- | 
| `WAFV2 IPSet: WAFOptimisticLockException` エラー | `terraform destroy` コマンドの実行時にこのエラーが発生した場合は、IP セットを手動で****削除する必要があります。手順については、[「IP セットの削除](https://docs.aws.amazon.com/waf/latest/developerguide/waf-ip-set-deleting.html) (AWS WAF ドキュメント）」を参照してください。 | 

## 関連リソース
<a name="deploy-the-security-automations-for-aws-waf-solution-by-using-terraform-resources"></a>

**AWS リファレンス**
+ [Security Automations for AWS WAF Implementation ガイド](https://docs.aws.amazon.com/solutions/latest/security-automations-for-aws-waf/welcome.html)
+ [のセキュリティオートメーション AWS WAF](https://aws.amazon.com/solutions/implementations/security-automations-for-aws-waf/) (AWS ソリューションライブラリ)
+ [Security Automations for AWS WAF のよくある質問](https://aws.amazon.com/solutions/implementations/security-automations-for-aws-waf/resources/#FAQ)

**Terraform のリファレンス**
+ [Terraform バックエンドの設定](https://developer.hashicorp.com/terraform/language/backend)
+ [Terraform AWS プロバイダー - ドキュメントと使用状況](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
+ [Terraform AWS プロバイダー](https://github.com/hashicorp/terraform-provider-aws) (GitHub リポジトリ)