terraformでfileを相対パス記載する

terraform version

  • 0.12以上

記載方法

  • module内にてfileを相対パスで指定したい場合、${path.module}が使える
    • 例えば"${path.module}/cert/sample.pem"でファイルのパスを作ってくれる(相対パスを作成してくれる)

具体例

  • certのpemを指定する場合(ファイルを展開したい場合)
    • moduleのcertディレクトリにあるファイルを指定したい
    • /path/to/module/cert/sample.pemを指定する
resource "aws_iot_certificate" "cert" {
  csr    = file("${path.module}/cert/sample.pem")
  active = true
}

memo