5
1

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

Terraform実行時にCycleエラーが出た際の対処方法

5
Last updated at Posted at 2017-11-29

Cycleエラーが出たときの対処法を残しておきます

$ terraform apply -auto-approve
Error: Error asking for user input: 1 error(s) occurred:

* Cycle: module.create_delivery_func.data.aws_region.dst, module.create_delivery_func.provider.aws.dst

グラフコマンド

Terraformにはgraph commandというTerraformの構成をグラフにおこすコマンドが用意されているのでこれを使って原因の特定を行います。

オプションに-draw-cyclesというグラフの任意のサイクルを色付きのエッジでハイライトしてくれるCycleエラーを診断する用途にぴったりのオプションがあるのでこちらを使います。

コマンド実行

ではコマンドを実行してみましょう!ポチッとな!

$ terraform graph -draw-cycles | dot -Tpng > graph.png

graph.png

...ひえ

グラフの任意のサイクルを色付きのエッジでハイライトしてくれる

とのことなので該当箇所だけ見てみましょう(全部みてられない...

原因

スクリーンショット 2017-11-29 17.53.09.png

図を見た感じproviderdata.aws_regionで双方向の参照が起きているようです

provider "aws" {
  alias  = "dst"
  region = "${data.aws_region.dst.name}"
}

data "aws_region" "dst" {
  provider = "aws.dst"
  current = true
}

コードを見た感じ、、、おかしいですね、、、
とりあえずproviderregionus-east-1にしてみるとエラーが解決しましたー :tada::tada:

まとめ

今回の例はグラフを使わなくても解決できるレベルでしたが、複雑な問題のときにはグラフコマンドは重宝するのでよかったら使ってみましょう

5
1
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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?