0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TerraformでWAFをimportしたらルールが消えた!?

Posted at

先日、手動で作成したAWS WAFをTerraformの管理下に置こうと思い、import してみました。すると…

🤔 なぜかルールを追加するような差分が出る!?

🧐 ステートを確認すると rule が空!?

「単に差分が出ているだけかな?」と思い、Terraformのステートを確認したところ、なんと…

💥 rule の情報が空!

resource "aws_wafv2_web_acl" "this" {
    arn           = "arn:aws:wafv2:us-east-1:????????????:global/webacl/test/aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb"
    capacity      = 2000
    description   = "WAF for test"
    id            = "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb"
    lock_token    = "xxxxxxxxxxxxxxxxxxxxx"
    name          = "test"
    scope         = "CLOUDFRONT"
    tags          = {}
    token_domains = []
    
    default_action {
        block {}
    }
    
    visibility_config {
        cloudwatch_metrics_enabled = true
        metric_name                = "dev-test-waf-ap-northeast-1"
        sampled_requests_enabled   = true
    }
}

「え、そういう仕様なの?🤨 さすがにそんなはずはないよな~」
「capacityはコンソールで確認した値と一緒だな~ :thinking:

🔍 import ログを確認すると rule は認識している!?

import のログを見てみると… rule 自体は認識してるっぽい!

なのに、なぜか rule が Terraform の管理下に入らない…🤔

🛠 TerraformのProviderバージョンを最新にしてみる

「もしかしてバグ?」と思い、一旦 Terraform AWS Provider のバージョンを最新に更新 してみました。

  • 現在のバージョン: 5.85
  • 更新後のバージョン: 5.86.1

plan を再実行 → 差分が消えた!

Provider のバージョンを更新後、再度 terraform plan を実行したところ…

🎉 謎の差分が消えて rule も正しく管理されるようになった!

✨ 結論

💡 Terraform AWS Provider のバグでした!

分かってしまえば簡単ですが、実際にこの状況に遭遇するとかなり戸惑いますね…😅

📌 対策まとめ

Terraformのimportログを確認する

  • ステートではなく、ログの中身もチェック!
    Terraform Provider のバージョンを確認・更新する
  • 古いバージョンを使っている場合は、バグの可能性を疑ってみる。
    ドキュメントやIssueを調査する
  • 似たような事例がないか、公式ドキュメントやGitHubのIssueをチェック!

同じような問題に直面した方の参考になれば嬉しいです!😆

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?