How can I get the Terraform module name programmatically?

Arcones

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}"
}
charli

I think is not possible. There's a self that allows you to reference attributes within your resource, but the identifier is not an attribute. Also, self is only allowed within provisioners.

I guess the only way to accomplish what you want is templating the .tf files, like:

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

but you should render the templates before terraform init. It's straightforward to setup in a CI pipeline, but I find it cumbersome when working locally.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I get package name in android?

How can I get name of the Feign client?

How can I get Gradle module name programmatically

How can I get the name of a Kotlin property?

Given a module name atom, how can I create the struct for that module?

How can I override a resource in a Terraform module?

How can I get the definition of a class in a module?

Get module name programmatically with only PyPI package name

terraform how can I find the ARN for bucket created on module

How can I get the Instance ID of the EMR master instance in Terraform?

How can I use a variable as an attribute name in terraform 3.0?

How in Terraform to get a LB name created in another module (for a DNS records' creation)

How can I get the name of a file in Dart?

How can I get the path of a module dynamically?

How can i get the module name in public/index.php?

How Can I Get The Value Of The Components That I Created Programmatically?

In Ember how can I create a component by name programmatically

How can I programmatically get this layout in tmux?

How can I get the name of comments' author?

How can I get the name of the module where a Table instance was declared?

How can i get current module name [nwidart/laravel-modules]

how can I get requests(module name) data parameter to my dJango server?

How can I use a Terraform's modules output as an input to another Terraform module?

How I can get the AWS RDS writer instance in Terraform

Using Terraform, how can I pass in a list of users from module to module

How can I refactor terraform module that creates vpc?

Can't get Terraform module dependencies to work

How can I enable Cognito 'User name' login using Terraform?

How to output name of a resource from module in terraform