Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the Terraform module name programmatically?

Tags:

terraform

hcl

I have defined the following Terraform module:

module "lambda" {
  source                = "../lambda"
  region                =  "us-west-1"
  account               = "${var.account}"
}

How can I take advantage from the module name to set the source parameter with an interpolation? I wish something like:

module "lambda" {
  source                = "../${this.name}"
  region                =  "us-west-1"
  account               = "${var.account}"
}
like image 315
Arcones Avatar asked Oct 02 '18 07:10

Arcones


1 Answers

locals {
  module = basename(abspath(path.module))
}

{
...
  some-id = local.module
...
}
like image 62
Sergey Bershadsky Avatar answered Sep 22 '22 06:09

Sergey Bershadsky