LoginSignup
2
0

More than 5 years have passed since last update.

Terraformではresource名にはdev/prodなどを入れなくてよさそう

Last updated at Posted at 2018-07-18

環境ごとのリソース名の切り替え

  • Terraformで環境ごとのリソース名の切り替えをする際は、Terraform 環境周りTips にあるように workspace サブコマンドを使えばよい
  • でも、その場合同じリソース名をprod/devで指定すると重複してしまうのではないかと危惧していた

構想

以下のようなリソースを作るべきかとちょっと迷った

resource "aws_iam_role" "hoge-role-${terraform.env}" { # <-- ${terraform.env}でリソース名切り替え
  name   = "hoge-role-${terraform.env}"
  path   = "/${terraform.env}/hoge/"
  assume_role_policy = <<EOF
{
...
}
EOF
}

関連するStackOverflowやGitHubのトピック

The names in Terraform are just logical for the purposes of referring to them. You want to parameterize the values inside the resource, and not the name itself, so this is by design.

Multiple environments are supported by using different variable and state files.

しかし、上記の記事にあるようにTerraformでリソース名に文字列補間できないのは仕様で、やる必要がないようだ。

同じリソース名を参照していたとしてもworkspaceが異なれば実際のARNは異なるのだろう(たぶん)

2
0
2

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