helen's blog

ずっとおもしろいことしてたいな。

terratestで遊んだけど明日になったら忘れてるのでメモするよ

github.com

ちょっとGoを書くだけでTerraformのテストができるよっていうツール

かなり初期までのa tour of goしかやってない自分でも
さっくりできてびっくりした

準備

  • 壊れても良い環境しかないようなAWSアカウント用意
  • terraform planまでは通るTerraform書く
  • Goのインストール

いいところ

はまったところ

フォルダ構成がだめ
provider.aws: no suitable version installed

# all logs
go test terraform_test.go
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 retry.go:64: Running terraform [destroy -force -input=false -lock=false]
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:52: Running command terraform with args [destroy -force -input=false -lock=false]
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95: Plugin reinitialization required. Please run "terraform init".
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95: Reason: Could not satisfy plugin requirements.
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95:
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95: Plugins are external binaries that Terraform uses to access and manipulate
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95: resources. The configuration provided requires plugins which can't be located,
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95: don't satisfy the version constraints, or are otherwise incompatible.
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95:
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95: 1 error(s) occurred:
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95:
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95: * provider.aws: no suitable version installed
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95:   version requirements: "(any version)"
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95:   versions installed: none
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95:
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95: Terraform automatically discovers provider requirements from your
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95: configuration, including providers used in child modules. To see the
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95: requirements and constraints from each module, run "terraform providers".
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:95:
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:99:
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:99: Error: error satisfying plugin requirements
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:99:
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 command.go:99:
TestTerraformHttpExample 2018-05-18T20:16:10+02:00 retry.go:72: Returning due to fatal error: FatalError{Underlying: exit status 1}
--- FAIL: TestTerraformHttpExample (0.04s)
	destroy.go:11: FatalError{Underlying: exit status 1}
FAIL
FAIL	command-line-arguments	0.045s

エラーメッセージと全然結びついてないけど
testコードが見に行くTerraformを1つのディレクトリにまとめたらいい感じに動いてくれました

# ng: 平置きがだめ
- testcode_test.go
- terraform_resources
- main.tf
- sample.tfvars

# ok: test.goにTerraformのリソースの入ったディレクトリを参照させる
- testcode_test.go
- terraform_code/
実行上限にひっかかる
*** Test killed with quit: ran too long (10m0s).

S3 + Cloudfrontなstaticホスティング構成立ててhttpリクエストさせてのテストがタイムアウトした・・・
なんかあかんみたいね・・・
明日なおそ・・・・

Rspecみたいに実行状況を何も書かなくても吐いてくれたらいいのになって思ったのと
エラーがまだ人間に優しくないのかも(ドキュメントを読んでなさすぎるのも大いに有りすぎると思う)と思いました。

テストにそれなりに時間がかかるけどちゃんと書けば楽しそう
ちゃんと書けばね!