How to call value from one module in terraform to another module

DevOps

YOUR COSMETIC CARE STARTS HERE

Find the Best Cosmetic Hospitals

Trusted • Curated • Easy

Looking for the right place for a cosmetic procedure? Explore top cosmetic hospitals in one place and choose with confidence.

“Small steps lead to big changes — today is a perfect day to begin.”

Explore Cosmetic Hospitals Compare hospitals, services & options quickly.

✓ Shortlist providers • ✓ Review options • ✓ Take the next step with confidence

Step 1-

Define Outputs in the Source Module: First, you need to define outputs in the module from which you want to export data.

modules/module1/outputs.tf:

output "output_name" {
  description = "Description of the output value"
  value       = local.some_value_or_variable
}Code language: JavaScript (javascript)

Step 2 –

Call the Module in the Main Configuration:

main.tf:

module "module1" {
  source = "./modules/module1"
  // ... other input variables
}Code language: JavaScript (javascript)

Step 3

Access the Output from Another Module: If you want to use the output from module1 in another module (module2 for example), you'd reference it in the main configuration where you call module2:

main.tf:

module "module2" {
  source  = "./modules/module2"
  input_variable = module.module1.output_name
}Code language: PHP (php)

Step 4

Define the Input Variable in the Destination Module: In the module where you want to use the passed value, define a corresponding input variable.

modules/module2/variables.tf:


variable "input_variable" {
  description = "Description of the input variable"
  type        = type_of_the_variable // e.g., string, number, map, etc.
}Code language: JavaScript (javascript)

Step 5

Use the Input Variable: Now, within module2, you can use var.input_variable to access the value passed from module1.Code language: JavaScript (javascript)
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x