terraform modules is not returning outputs

962 views
Skip to first unread message

deepak.d...@gmail.com

unread,
Nov 8, 2016, 4:58:29 AM11/8/16
to Terraform
my terraform template is producing outputs fine when run without a module but when i run it with module terraform plan and apply works just fine but i dont see outputs getting printed on the console. when i try "terraform output" then get  below error:

The state file has no outputs defined. Define an output

in your configuration with the `output` directive and re-run

`terraform apply` for it to become available


Any idea why it does not work with modules? here is my outputs code https://github.com/ddimri/terraform/blob/master/outputs.tf

David Adams

unread,
Nov 8, 2016, 8:27:23 AM11/8/16
to terrafo...@googlegroups.com
If I understand what you're asking, the answer is that module outputs don't pass through to become outputs of their containing projects. So if you're using github.com/ddimri/terraform as a module in some other Terraform project, you'll have to define outputs in that project as well, eg:

    module "mymod" {
      source = "git://github.com/ddimri/terraform"
      # ... params here
    }

    output "ipa_vpc_id" {
      value = "${module.mymod.ip_vpc_id}"
    }

    # ... and so on

Good luck.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/f1db9047-bf60-4a28-b1d6-555068d704ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

deepak.d...@gmail.com

unread,
Nov 9, 2016, 4:09:15 AM11/9/16
to Terraform
Thanks, David for your response.

In my case if i define module in the outputs as you suggested then i am getting unknown module referenced: error:
I want to have my main.tf containing the input values i want for the modules and just want outputs from it in a file so that i can use it for other processing. 

Is there a way i can have EC2 instances details (such us private DNS, ip etc.) that i am creating using my terraform stored in a text file or some thing?

Thanks again,
Deepak

deepak.d...@gmail.com

unread,
Nov 9, 2016, 6:21:40 AM11/9/16
to Terraform
I got a workaround to manage my requirement for now. I am using

terraform output -state=terraform.tfstate -module=vpc to get the output from the module. 


On Tuesday, November 8, 2016 at 3:28:29 PM UTC+5:30, deepak.d...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages