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

Synchronize passed value with each resource in module : Terraform

I have main.tf file where I have "eip" module, and i am passing some instance id’s to eip module.

I have 3 eip resources declared in module, each of them expecting instance id from main.tf.

Problem is how each passed value(instance id) from main.tf will go to right resource in module, as I cant change "eip resources" name in module as these "eip" are already created, I just collected all 3 "eip" from 3 different files and placed in one file just for optimization purpose.

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

so do I need some understanding here, or its not possible the way I am assuming it.

Please have a look at screenshot for better understanding issue.
enter image description here

>Solution :

In your EIP module, you should have only one resource.

eip/eip.tf

resource "aws_eip" "eip" {
  instance = var.instance
  vpc      = true
}

output "public_ip" {
  value = aws_eip.eip.public_ip
}

Then in the parent module you can access the id using module indices

main.tf

locals {
  public_ip_first_eip = module.module-generic-eip[0].public_ip

Since you are iterating in the parent module, the module will be instantiated three times, and you will get three EIPs – one EIP for each instance.

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