9
2

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 3 years have passed since last update.

AWS WAFv2 を Terraform で扱うときの注意点

Last updated at Posted at 2020-07-26

概要

  • マネジメントコンソール(手動)で CloudFront 用に作成した AWS WAFv2 を terraform import したときにハマったこと。
  • 最初から terraform で AWS WAFv2 を作成するときも同様にハマったと思う。

ハマったこと

AWS provider のバージョンが古かった

  • エラー
  • AWS provider 2.48.0 で terraform import すると、次のようなエラーが出る
Error: unknown resource type: aws_wafv2_web_acl

terraform import を実行するリージョンが違っていた

  • エラー
  • 東京リージョンから terraform import すると、次のようなエラーが出る
Error: WAFInvalidParameterException: Error reason: The scope is not valid., field: SCOPE_VALUE, parameter: CLOUDFRONT
{
  RespMetadata: {
    StatusCode: 400,
    RequestID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  },
  Field: "SCOPE_VALUE",
  Message_: "Error reason: The scope is not valid., field: SCOPE_VALUE, parameter: CLOUDFRONT",
  Parameter: "CLOUDFRONT",
  1 resource "aws_wafv2_web_acl" "example" {
  Reason: "The scope is not valid."
}
$ terraform import -provider="aws.virginia" aws_wafv2_web_acl.example xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/example/CLOUDFRONT

terraform 設定例

  • 構成

└── wafv2
   ├── backend.tf
   ├── example.tf
   └── provider.tf
  • provider.tf 抜粋

provider "aws" {
  version                 = "2.67.0"
  shared_credentials_file = "credentials"
  profile                 = "terraform"
  region                  = "ap-northeast-1"
}
provider "aws" {
  version                 = "2.67.0"
  shared_credentials_file = "credentials"
  profile                 = "terraform"
  alias                   = "virginia"
  region                  = "us-east-1"
}
9
2
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
9
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?