Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Terraform, how to pass data from one child module to another

I have the following folder structure

├── main.tf
├── modules
│   ├── web-app
│   │   ├── lambda.tf
│   │   ├── outputs.tf
│   │   ├── s3.tf
│   │   ├── sns.tf
│   │   ├── sqs.tf
│   │   └── variables.tf
│   ├── microservice1
│   │   ├── sns.tf
│   │   ├── sqs.tf
│   │   └── variables.tf
...

Inside the web-app I create a SNS topic. Inside the microservice I want to subscribe the queue I create there to the topic I created inside the web-app.
My problem is that I cannot figure out how to pass the arn of the topic from web-app to the microservice1.

How could I achieve that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can’t do this from microservice1. You have to do it in your main.tf. So first you instantiate a web-app module in the main.tf. The module outputs sns arn. Then you pass the arn to the instant of microservice module, again in main.tf

In main.tf:

module "sns" {
   source = "./modules/web-app"
   # other arguments
}

module "microservice1" {
   source = "./modules/microservice1"
   sns_arn = module.sns.sns_arn
   # other arguments
}

for that to work, you have to have output in your web-app:

output "sns_arn" {
  value = aws_sns_topic.mytopic.id
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading